From 0a289b6c235a4c800a09db8bc496d105ae764f5e Mon Sep 17 00:00:00 2001 From: Leon Morival Date: Fri, 10 Jul 2026 23:07:43 +0200 Subject: [PATCH] feat: request on api --- .env.example | 1 + app/components/MinecraftWhitelistForm.tsx | 20 +++++++++----------- app/lib/server-config.ts | 1 + 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index 56cba6c..4cbf929 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ DISCORD_WHITELIST_WEBHOOK_URL="" +NEXT_PUBLIC_API_URL="https://api.leonmorival.xyz" diff --git a/app/components/MinecraftWhitelistForm.tsx b/app/components/MinecraftWhitelistForm.tsx index ddf501d..3c447ec 100644 --- a/app/components/MinecraftWhitelistForm.tsx +++ b/app/components/MinecraftWhitelistForm.tsx @@ -1,6 +1,7 @@ "use client"; import { FormEvent, useState } from "react"; +import { siteConfig } from "../lib/server-config"; type FormStatus = { tone: "success" | "error"; @@ -19,29 +20,27 @@ export default function MinecraftWhitelistForm() { const formData = new FormData(form); const payload = { - username: String(formData.get("username") ?? ""), - reason: String(formData.get("reason") ?? ""), + game_username: String(formData.get("username") ?? ""), + message: String(formData.get("reason") ?? ""), + server_slug: "minecraft", }; try { - const response = await fetch("/api/minecraft/whitelist/request", { + const response = await fetch(`${siteConfig.apiUrl}/api/access-requests`, { method: "POST", headers: { "Content-Type": "application/json" }, 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."); } form.reset(); setStatus({ tone: "success", - message: result.message ?? "Demande envoyée.", + message: "Demande envoyée.", }); } catch (error) { setStatus({ @@ -78,8 +77,7 @@ export default function MinecraftWhitelistForm() {