import { AlertCircleIcon, LoaderIcon } from "lucide-react"; import { useState } from "react"; import { Alert, AlertDescription } from "./ui/alert"; import { InputOTP, InputOTPGroup, InputOTPSlot } from "./ui/input-otp"; import { verifyOtp } from "~/lib/api"; import { useNavigate } from "react-router"; export default function OtpInput({ email, setOtpError, otpError, }: { email: string; setOtpError: (error: string | null) => void; otpError: string | null; }) { const navigate = useNavigate(); const [isVerifying, setIsVerifying] = useState(false); // Handle OTP verification const handleVerifyOtp = (otpCode: string) => { setIsVerifying(true); setOtpError(null); verifyOtp({ otpCode, email }) .then(() => { setIsVerifying(false); // TODO: Check if new user ?? navigate("/success?email=" + encodeURIComponent(email), { replace: true, }); }) .catch((error) => setOtpError( error instanceof Error ? error.message : "Code de vérification invalide" ) ); }; return (
handleVerifyOtp(value)} disabled={isVerifying} >
{isVerifying && (
Vérification en cours...
)} {otpError && ( {otpError} )}
); }