import { Button } from '@/components/ui/button'; import { Calendar } from '@/components/ui/calendar'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { useForm } from '@inertiajs/react'; import AppLayout from '@/layouts/app-layout'; import { Head } from '@inertiajs/react'; import { type BreadcrumbItem } from '@/types'; import InputError from '@/components/input-error'; import { format } from 'date-fns'; import { CalendarIcon } from 'lucide-react'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { cn } from '@/lib/utils'; import { Textarea } from '@/components/ui/textarea'; interface PatientFormProps { mode: 'create' | 'edit'; patient?: { id?: string; medical_record_number: string; name: string; gender: string; nik?: string; birth_date: string; birth_place?: string; address?: string; phone_number?: string; email?: string; blood_type?: string; religion?: string; marital_status?: string; emergency_contact_name?: string; emergency_contact_phone?: string; emergency_contact_relation?: string; is_active: boolean; }; } const breadcrumbs: BreadcrumbItem[] = [ { title: 'Dashboard', href: '/dashboard' }, { title: 'Patients', href: '/patients' }, { title: 'Form', href: '#' }, ]; const toLocalISOString = (date: Date) => { const offset = date.getTimezoneOffset(); const localDate = new Date(date.getTime() - (offset * 60 * 1000)); return localDate.toISOString().split('T')[0]; }; export default function PatientForm({ mode, patient }: PatientFormProps) { const { data, setData, post, put, processing, errors, reset } = useForm({ // Patient fields medical_record_number: patient?.medical_record_number || '', name: patient?.name || '', gender: patient?.gender || 'laki-laki', nik: patient?.nik || '', birth_date: patient?.birth_date || '', birth_place: patient?.birth_place || '', address: patient?.address || '', phone_number: patient?.phone_number || '', email: patient?.email || '', blood_type: patient?.blood_type || 'unknown', religion: patient?.religion || '', marital_status: patient?.marital_status || '', emergency_contact_name: patient?.emergency_contact_name || '', emergency_contact_phone: patient?.emergency_contact_phone || '', emergency_contact_relation: patient?.emergency_contact_relation || '', is_active: patient?.is_active ?? true, }); const onSubmit = (e: React.FormEvent) => { e.preventDefault(); if (mode === 'create') { post(route('patients.store'), { onSuccess: () => reset(), }); } else { put(route('patients.update', patient?.id), { preserveScroll: true, }); } }; return (

{mode === 'create' ? 'Tambah Pasien Baru' : 'Edit Data Pasien'}

{mode === 'edit' && ( No. Pasien {data.medical_record_number} )}
{/* Informasi Utama */}
setData('name', e.target.value)} placeholder="Nama pasien" />
setData('gender', value)} className="flex gap-4 mt-4" >
setData('nik', e.target.value)} placeholder="16-digit NIK" maxLength={16} />
date && setData('birth_date', toLocalISOString(date))} initialFocus />
setData('birth_place', e.target.value)} placeholder="Kota kelahiran" />
{/* Kontak & Informasi Tambahan */}
setData('phone_number', e.target.value)} placeholder="08123456789" />
setData('email', e.target.value)} placeholder="joko_susanto@example.com" />