feat: request on api
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
DISCORD_WHITELIST_WEBHOOK_URL=""
|
DISCORD_WHITELIST_WEBHOOK_URL=""
|
||||||
|
NEXT_PUBLIC_API_URL="https://api.leonmorival.xyz"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { FormEvent, useState } from "react";
|
import { FormEvent, useState } from "react";
|
||||||
|
import { siteConfig } from "../lib/server-config";
|
||||||
|
|
||||||
type FormStatus = {
|
type FormStatus = {
|
||||||
tone: "success" | "error";
|
tone: "success" | "error";
|
||||||
@@ -19,29 +20,27 @@ export default function MinecraftWhitelistForm() {
|
|||||||
|
|
||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
const payload = {
|
const payload = {
|
||||||
username: String(formData.get("username") ?? ""),
|
game_username: String(formData.get("username") ?? ""),
|
||||||
reason: String(formData.get("reason") ?? ""),
|
message: String(formData.get("reason") ?? ""),
|
||||||
|
server_slug: "minecraft",
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/minecraft/whitelist/request", {
|
const response = await fetch(`${siteConfig.apiUrl}/api/access-requests`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
const result = (await response.json()) as {
|
|
||||||
ok?: boolean;
|
|
||||||
message?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!response.ok || !result.ok) {
|
if (!response.ok) {
|
||||||
|
const result = await response.json().catch(() => ({})) as { message?: string };
|
||||||
throw new Error(result.message ?? "Demande refusée.");
|
throw new Error(result.message ?? "Demande refusée.");
|
||||||
}
|
}
|
||||||
|
|
||||||
form.reset();
|
form.reset();
|
||||||
setStatus({
|
setStatus({
|
||||||
tone: "success",
|
tone: "success",
|
||||||
message: result.message ?? "Demande envoyée.",
|
message: "Demande envoyée.",
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setStatus({
|
setStatus({
|
||||||
@@ -78,8 +77,7 @@ export default function MinecraftWhitelistForm() {
|
|||||||
<textarea
|
<textarea
|
||||||
id="minecraft-reason"
|
id="minecraft-reason"
|
||||||
name="reason"
|
name="reason"
|
||||||
minLength={10}
|
maxLength={255}
|
||||||
maxLength={800}
|
|
||||||
rows={5}
|
rows={5}
|
||||||
placeholder="Je voudrais rejoindre le serveur..."
|
placeholder="Je voudrais rejoindre le serveur..."
|
||||||
required
|
required
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export const siteConfig = {
|
|||||||
jellyfinUrl: "https://momostreaming.com",
|
jellyfinUrl: "https://momostreaming.com",
|
||||||
minecraftPath: "/minecraft",
|
minecraftPath: "/minecraft",
|
||||||
astroneerPath: "/astroneer",
|
astroneerPath: "/astroneer",
|
||||||
|
apiUrl: process.env.NEXT_PUBLIC_API_URL ?? "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const minecraftServer = {
|
export const minecraftServer = {
|
||||||
|
|||||||
Reference in New Issue
Block a user