"use client"; import { useState, useTransition } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; export function LoginForm() { const router = useRouter(); const searchParams = useSearchParams(); const [isPending, startTransition] = useTransition(); const [error, setError] = useState(null); const [formState, setFormState] = useState({ email: "", password: "", }); function handleSubmit(event: React.FormEvent) { event.preventDefault(); setError(null); startTransition(async () => { const response = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(formState), }); const payload = (await response.json().catch(() => null)) as | { message?: string } | null; if (!response.ok) { setError(payload?.message || "تعذر تسجيل الدخول."); return; } const nextPath = searchParams.get("next") || "/dashboard/customers"; router.replace(nextPath); router.refresh(); }); } return (

تسجيل الدخول

ادخل على حسابك وكمل متابعة عملاءك وملفاتهم.

setFormState((current) => ({ ...current, email: event.target.value })) } required />
setFormState((current) => ({ ...current, password: event.target.value, })) } required />
{error ? (

{error}

) : null}
); }