feat: request on api
CI / 🔍 Lint & Type Check (push) Successful in 1m5s
CI / 🐳 Build & Push Image (push) Successful in 17s

This commit is contained in:
2026-07-10 23:07:43 +02:00
parent 1e85e66bc2
commit 0a289b6c23
3 changed files with 11 additions and 11 deletions
+1
View File
@@ -1 +1,2 @@
DISCORD_WHITELIST_WEBHOOK_URL="" DISCORD_WHITELIST_WEBHOOK_URL=""
NEXT_PUBLIC_API_URL="https://api.leonmorival.xyz"
+9 -11
View File
@@ -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
+1
View File
@@ -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 = {