import { useState, useEffect, useCallback, useRef } from "react"; import OTPInput from…
- User
import { useState, useEffect, useCallback, useRef } from "react"; import OTPInput from "./components/OTPInput"; import CountdownTimer from "./components/CountdownTimer"; import Confetti from "./components/Confetti"; import MethodSelector, { VerifyMethod, METHODS } from "./components/MethodSelector"; import { cn } from "./utils/cn";
/* ─── Constants ───────────────────────────────────────────── */ const CORRECT_OTP = "123456"; const TIMER_DURATION = 30;
type VerifyState = "idle" | "verifying" | "error" | "success";
/* ─── Tiny helpers ────────────────────────────────────────── */ function SuccessCheckIcon() { return ( ); }
function LockIcon({ pulse }: { pulse?: boolean }) { return ( <svg className={cn("w-8 h-8 text-[#F15A24]", pulse && "animate-pulse")} fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth="1.8" > ); }
/* ─── Main App ────────────────────────────────────────────── */ export default function App() { const [state, setState] = useState("idle"); const [method, setMethod] = useState("email"); const [countdown, setCountdown] = useState(TIMER_DURATION); const [canResend, setCanResend] = useState(false); const [resending, setResending] = useState(false); const [otpKey, setOtpKey] = useState(0); const [attempts, setAttempts] = useState(0); const timerRef = useRef<ReturnType | null>(null);
/* ── Timer ── */ const startTimer = useCallback(() => { setCountdown(TIMER_DURATION); setCanResend(false); if (timerRef.current) clearInterval(timerRef.current); timerRef.current = setInterval(() => { setCountdown(prev => { if (prev <= 1) { clearInterval(timerRef.current!); setCanResend(true); return 0; } return prev - 1; }); }, 1000); }, []);
useEffect(() => { startTimer(); return () => { if (timerRef.current) clearInterval(timerRef.current); }; }, [startTimer]);
/* ── OTP submit ── */ const handleOTPComplete = useCallback((otp: string) => { setState("verifying"); setTimeout(() => { if (otp === CORRECT_OTP) { setState("success"); if (timerRef.current) clearInterval(timerRef.current); } else { setState("error"); setAttempts(a => a + 1); setTimeout(() => { setState("idle"); setOtpKey(k => k + 1); }, 820); } }, 1300); }, []);
/* ── Method change ── */ const handleMethodChange = useCallback((m: VerifyMethod) => { if (state === "verifying" || state === "success") return; setMethod(m); setState("idle"); setOtpKey(k => k + 1); setAttempts(0); startTimer(); }, [state, startTimer]);
/* ── Resend ── */ const handleResend = useCallback(() => { if (!canResend || resending) return; setResending(true); setAttempts(0); setTimeout(() => { setResending(false); setOtpKey(k => k + 1); setState("idle"); startTimer(); }, 1600); }, [canResend, resending, startTimer]);
const isDisabled = state === "verifying" || state === "success"; const activeMethod = METHODS.find(m => m.id === method)!;
return ( <div className="min-h-screen flex items-center justify-center p-4 relative overflow-hidden" style={{ backgroundColor: "#FAF8F5", fontFamily: "'Inter', system-ui, sans-serif" }} > {/* Subtle background texture blobs */} <div className="absolute -top-32 -right-32 w-[500px] h-[500px] rounded-full opacity-30" style={{ background: "radial-gradient(circle, #F8E8E0 0%, transparent 70%)" }} /> <div className="absolute -bottom-40 -left-40 w-[600px] h-[600px] rounded-full opacity-20" style={{ background: "radial-gradient(circle, #EDE9E2 0%, transparent 70%)" }} />
Assistant
The 2FA identity verification application has been successfully built and refined.
Key Features:
- State-Driven UI: Manages multiple verification states:
idle,verifying,error, andsuccess. - Dynamic OTP Input: A custom 6-digit input component with auto-focus, backspace handling, and paste support.
- Multiple Methods: Switch between Email and SMS verification, with destination masking (e.g.,
alex****@gmail.com). - Interactive Feedback:
- Animated Success: Custom SVG animation for successful verification and canvas confetti celebration.
- Visual Progress: A shimmer loading bar during the "verifying" state.
- Smart Failures: Provides a demo code hint after 2 failed attempts.
- State-Driven UI: Manages multiple verification states:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.