"use client"; import { Suspense, useState, useEffect } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Alert } from "@/components/ui/alert"; import { AlertCircle, CheckCircle2, Loader2 } from "lucide-react"; function AcceptInvitePageInner() { const router = useRouter(); const searchParams = useSearchParams(); const token = searchParams.get("token"); const [name, setName] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); useEffect(() => { if (!token) { setError("Invalid or missing invitation token."); } }, [token]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (password !== confirmPassword) { setError("Passwords do not match"); return; } if (password.length < 8) { setError("Password must be at least 8 characters"); return; } setLoading(true); setError(null); try { const res = await fetch("/api/accept-invite", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token, name, password }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error); setSuccess(true); setTimeout(() => router.push("/login"), 2000); } catch (err) { setError(err instanceof Error ? err.message : "Something went wrong"); } finally { setLoading(false); } }; return (
{/* Logo */}
CubeAdmin
Accept Invitation Create your account to access the Minecraft server panel. {success ? (

Account created!

Redirecting you to the login page...

) : (
{error && ( {error} )}
setName(e.target.value)} placeholder="John Doe" required disabled={!token || loading} className="bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500 focus:border-emerald-500/50" />
setPassword(e.target.value)} placeholder="At least 8 characters" required disabled={!token || loading} className="bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500 focus:border-emerald-500/50" />
setConfirmPassword(e.target.value)} placeholder="Repeat your password" required disabled={!token || loading} className="bg-zinc-800 border-zinc-700 text-white placeholder:text-zinc-500 focus:border-emerald-500/50" />
)}
); } export default function AcceptInvitePage() { return ( ); }