import { useState } from "react"; import { useSession } from "@/components/session-provider"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { InputOTP, InputOTPGroup, InputOTPSlot } from "@/components/ui/input-otp"; import { useResendVerification, useVerifyEmail } from "@/lib/query/hooks"; interface VerificationModalProps { open: boolean; onOpenChange: (open: boolean) => void; } export function VerificationModal({ open, onOpenChange }: VerificationModalProps) { const { refreshUser, setEmailVerified } = useSession(); const [code, setCode] = useState(""); const [error, setError] = useState(null); const [resendSuccess, setResendSuccess] = useState(false); const verifyMutation = useVerifyEmail(); const resendMutation = useResendVerification(); const handleVerify = async (e: React.FormEvent) => { e.preventDefault(); setError(null); setResendSuccess(false); try { await verifyMutation.mutateAsync({ code: code.trim() }); setEmailVerified(true); onOpenChange(false); await refreshUser(); } catch (err) { setError(err instanceof Error ? err.message : "Verification failed"); } }; const handleResend = async () => { setError(null); setResendSuccess(false); try { await resendMutation.mutateAsync(); setResendSuccess(true); } catch (err) { setError(err instanceof Error ? err.message : "Failed to resend code"); } }; return ( {}}> Verify your email We've sent a 6-digit verification code to your email. Enter it below to complete your registration.
{error &&

{error}

} {resendSuccess &&

Verification code sent!

}
); }