"use client"; import React, { useState } from "react"; import { Button } from "@/components/ui/button"; import { useTranslations } from "next-intl"; import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, } from "@/components/ui/input-otp"; import { OTPFormProps } from "@/types/auth"; import { useOTPVerification } from "@/hooks/use-auth"; export const OTPForm: React.FC = ({ loginCredentials, onSuccess, onError, onResend, className, }) => { const t = useTranslations("LandingPage"); const { verifyOTP, loading } = useOTPVerification(); const [otpValue, setOtpValue] = useState(""); const handleTypeOTP = (event: React.KeyboardEvent) => { const { key } = event; const target = event.currentTarget; if (key === "Enter") { event.preventDefault(); const inputs = Array.from(target.form?.querySelectorAll("input") || []); const currentIndex = inputs.indexOf(target); const nextInput = inputs[currentIndex + 1] as HTMLElement | undefined; if (nextInput) { nextInput.focus(); } } }; const handleOTPChange = (value: string) => { setOtpValue(value); }; const handleSubmit = async () => { if (otpValue.length !== 6) { onError?.("Please enter a complete 6-digit OTP"); return; } if (!loginCredentials?.username) { onError?.("Username not found. Please try logging in again."); return; } try { const isValid = await verifyOTP(loginCredentials.username, otpValue); if (isValid) { onSuccess?.(); } else { onError?.("Invalid OTP code"); } } catch (error: any) { onError?.(error.message || "OTP verification failed"); } }; // const handleResend = () => { // onResend?.(); // }; return (
{/* Header */}

{t("pleaseEnterOtp", { defaultValue: "Please Enter OTP" })}

Enter the 6-digit code sent to your email address.

{/* OTP Input */}
{/* Resend OTP */}
{/* Submit Button */}
); };