"use client"; import { post } from "@/api/request"; import { useSearchParams, useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { CheckCircle, XCircle, Loader2 } from "lucide-react"; export default function Activate() { const searchParams = useSearchParams(); const t = searchParams.get("t") || ""; const type = searchParams.get("type"); if (type === "confirm_email") { return ; } return <>; } /** * Email verification confirmation component * @param {string} t - Verification token */ function ConfirmEmail({ t }: { t: string }) { const router = useRouter(); const [status, setStatus] = useState<"loading" | "success" | "error">( "loading" ); const [message, setMessage] = useState(""); const [countdown, setCountdown] = useState(3); useEffect(() => { if (!t) { setStatus("error"); setMessage("Invalid verification token"); return; } post(`/auth/activate`, { t: t, }).then((res:any) => { setStatus("success"); setMessage( "Your registration has been verified. Redirecting to login page..." ); }).catch((err:any) => { setStatus("error"); setMessage("Verification failed. Please try again."); }); }, [t]); /** * Handle countdown and redirect to login page */ useEffect(() => { if (status === "success") { const timer = setInterval(() => { setCountdown((prev: number) => { if (prev <= 1) { clearInterval(timer); router.push("/login"); return 0; } return prev - 1; }); }, 1000); return () => clearInterval(timer); } }, [status, router]); const renderContent = () => { switch (status) { case "loading": return (

Verifying email...

); case "success": return (

Verification Successful

{message}

Redirecting to login page in {countdown} seconds...

); case "error": return (

Verification Failed

{message}

{/* */}
); } }; return (
{status === "loading" && (

Email Verification

Please wait while we verify your email

)} {renderContent()}
); }