"use client"; import React, { useState, useEffect } from "react"; import { Button } from "@/components/ui/button"; import { useTranslations } from "next-intl"; import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, } from "@/components/ui/input-otp"; import { RegistrationOTPFormProps, UserCategory } from "@/types/registration"; import { useOTP } from "@/hooks/use-registration"; export const RegistrationOTPForm: React.FC = ({ email, category, memberIdentity, onSuccess, onError, onResend, className, }) => { const t = useTranslations("LandingPage"); const { verifyOTP, resendOTP, loading, error, formattedTime, canResend } = useOTP(); const [otpValue, setOtpValue] = useState(""); const handleOTPChange = (value: string) => { setOtpValue(value); }; const handleVerifyOTP = async () => { if (otpValue.length !== 6) { onError?.("Please enter a complete 6-digit OTP"); return; } try { const userData = await verifyOTP( email, otpValue, category, memberIdentity ); if (userData?.error) return false; onSuccess(email); } catch (error: any) { onError?.(error.message || "OTP verification failed"); } }; const handleResendOTP = async () => { if (!canResend) { onError?.("Please wait before requesting a new OTP"); return; } try { const success = await resendOTP(email, category, memberIdentity); if (success) { onResend?.(); } } catch (error: any) { onError?.(error.message || "Failed to resend OTP"); } }; const handleTypeOTP = (event: React.KeyboardEvent) => { const { key } = event; const target = event.currentTarget; if (key === "Enter") { event.preventDefault(); handleVerifyOTP(); } }; return (
{/* OTP Instructions */} {/*

{t("enterOTP", { defaultValue: "Masukkan kode OTP" })}

{t("checkInbox", { defaultValue: "Silahkan cek inbox atau kotak spam pada email Anda." })}

OTP sent to: {email}

*/} {/* OTP Input */}
{/* Error Message */} {error && (

{error}

)} {/* Action Buttons */}
{/* Help Text */}

{t("otpHelp", { defaultValue: "Didn't receive the code? Check your spam folder or", })}{" "}

); };