"use client" import type React from "react" import { useState } from "react" import { useRouter } from "next/navigation" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Alert, AlertDescription } from "@/components/ui/alert" import Link from "next/link" export default function LoginForm() { const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [error, setError] = useState("") const [loading, setLoading] = useState(false) const router = useRouter() const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError("") try { const response = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password }), }) const data = await response.json() if (response.ok) { // توجيه المستخدم حسب دوره switch (data.user.role) { case "admin": router.push("/admin") break case "plumber": router.push("/plumber") break default: router.push("/dashboard") } } else { setError(data.error || "حدث خطأ في تسجيل الدخول") } } catch (err) { setError("حدث خطأ في الاتصال") } finally { setLoading(false) } } return ( تسجيل الدخول أدخل بياناتك للوصول إلى حسابك
{error && ( {error} )}
setEmail(e.target.value)} required className="text-right" placeholder="example@email.com" />
setPassword(e.target.value)} required className="text-right" placeholder="••••••••" />

ليس لديك حساب؟{" "} إنشاء حساب جديد

كلمة المرور التجريبية: 123456

) }