import { KeyRound, Loader2, Shield } from "lucide-react"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { motion } from "framer-motion"; import toast, { Toaster } from "react-hot-toast"; import { sendEmailOTP, verifyEmail } from "@/app/utils/api"; import AuthService from "@/app/services/AuthService"; import { useRouter } from "next/navigation"; export default function OtpDialog({ formData, setShowOtpModal, type }) { const { t } = useTranslation(); const router = useRouter(); const [isLoading, setIsLoading] = useState(false); const [otpCode, setOtpCode] = useState(""); const handleVerifyOTP = async () => { if (!otpCode || otpCode.length < 4) { toast.error(t("register.otpRequired")); return; } setIsLoading(true); try { const res = await verifyEmail(otpCode); if (res.status === 200) { AuthService.deleteToken(); toast.success(res.message || t("register.emailVerified")); setShowOtpModal(false); setTimeout(() => router.push("/login"), 1500); } else { toast.error(res.message || res.data?.message || t("accountVerification.otpInvalid")); } } catch (err) { toast.error(err.message || t("register.verificationError")); } finally { setIsLoading(false); } }; const handleResendOTP = async () => { setIsLoading(true); try { await sendEmailOTP(); toast.success(t("register.newOtpSent")); } catch (err) { toast.error(t("register.resendOtpFailed")); } finally { setIsLoading(false); } }; return ( <>

{t("register.otpTitle")}

{t("register.otpSentTo")}

{formData.email}

setOtpCode(e.target.value)} className="w-full pr-12 pl-4 py-3 bg-white/5 border border-gray-700 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500 text-white text-center tracking-[0.5em] text-xl" placeholder="------" />
); }