import { Form } from "@remix-run/react"; import { useState, useEffect } from "react"; import { Input } from "~/components/ui/Input"; import { Button } from "~/components/ui/Button"; import { Flex } from "~/components/layout/Flex"; import type { Customer } from "~/types/database"; interface CustomerFormProps { customer?: Customer; onCancel: () => void; errors?: Record; isLoading: boolean; } export function CustomerForm({ customer, onCancel, errors = {}, isLoading, }: CustomerFormProps) { const [formData, setFormData] = useState({ name: customer?.name || "", phone: customer?.phone || "", email: customer?.email || "", address: customer?.address || "", }); // Reset form data when customer changes useEffect(() => { if (customer) { setFormData({ name: customer.name || "", phone: customer.phone || "", email: customer.email || "", address: customer.address || "", }); } else { setFormData({ name: "", phone: "", email: "", address: "", }); } }, [customer]); const handleInputChange = (field: string, value: string) => { setFormData(prev => ({ ...prev, [field]: value, })); }; const isEditing = !!customer; return (
{isEditing && ( )} {/* Customer Name */}
handleInputChange("name", e.target.value)} placeholder="أدخل اسم العميل" error={errors.name} required disabled={isLoading} /> {errors.name && (

{errors.name}

)}
{/* Phone Number */}
handleInputChange("phone", e.target.value)} placeholder="أدخل رقم الهاتف" error={errors.phone} disabled={isLoading} dir="ltr" /> {errors.phone && (

{errors.phone}

)}
{/* Email */}
handleInputChange("email", e.target.value)} placeholder="أدخل البريد الإلكتروني" error={errors.email} disabled={isLoading} dir="ltr" /> {errors.email && (

{errors.email}

)}
{/* Address */}