import React, { useState } from 'react'; import Spinner from './Spinner'; interface OtpModalProps { isOpen: boolean; onClose: () => void; onSubmit: (otpCode: string) => Promise; isLoading?: boolean; errorMessage?: string | null; } const OtpModal: React.FC = ({ isOpen, onClose, onSubmit, isLoading = false, errorMessage }) => { const [otpCode, setOtpCode] = useState(''); const [localError, setLocalError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!otpCode.trim()) { setLocalError('Vui lòng nhập mã OTP'); return; } setLocalError(null); try { await onSubmit(otpCode); // If successful, clear the OTP and close modal setOtpCode(''); } catch (error) { // Error will be handled by parent component } }; const handleClose = () => { setOtpCode(''); setLocalError(null); onClose(); }; if (!isOpen) return null; return (

Xác thực OTP

Phiên đăng nhập đã hết hạn. Vui lòng nhập mã OTP để tiếp tục.

setOtpCode(e.target.value)} className="bg-slate-900/50 border border-slate-700 text-slate-100 text-sm rounded-lg focus:ring-indigo-500 focus:border-indigo-500 block w-full p-3 transition-colors duration-200" placeholder="Nhập mã OTP 6 chữ số" disabled={isLoading} maxLength={6} autoFocus />
{(localError || errorMessage) && (

{localError || errorMessage}

)}
); }; export default OtpModal;