"use client"; import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import { ShieldCheck } from "lucide-react"; import { Button } from "@/components/ui/Button"; import { TextField } from "@/components/ui/TextField"; import { ErrorBanner } from "@/components/ui/ErrorBanner"; import { Card } from "@/components/ui/Card"; import { requestOtp } from "@/lib/api"; import { formatApiError } from "@/lib/hooks"; import { useAuth } from "@/lib/auth-context"; const PHONE_REGEX = /^09\d{9}$/; export default function LoginPage() { const router = useRouter(); const { status } = useAuth(); const [phone, setPhone] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (status === "authenticated") router.replace("/"); }, [status, router]); const isValid = PHONE_REGEX.test(phone); async function handleSubmit() { if (!isValid) return; setLoading(true); setError(null); try { await requestOtp(phone); router.push(`/verify?phone=${phone}`); } catch (err) { setError(formatApiError(err)); } finally { setLoading(false); } } return (

پنل ادمین دلدل

فقط برای مدیران سیستم

setPhone(e.target.value.replace(/\D/g, "").slice(0, 11))} onKeyDown={(e) => e.key === "Enter" && handleSubmit()} />
); }