import { Form } from '@inertiajs/react'; import type { ReactNode } from 'react'; import { toast } from 'sonner'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; type FormDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; title: string; action: React.ComponentProps['action']; resetOnSuccess?: boolean; onSuccess?: () => void; submitDisabled?: boolean; submitLabel?: ReactNode; submittingLabel?: ReactNode; children: | ReactNode | ((ctx: { errors: Record; processing: boolean; }) => ReactNode); }; export function FormDialog({ open, onOpenChange, title, action, resetOnSuccess, onSuccess, submitDisabled = false, submitLabel = 'Simpan', submittingLabel = 'Menyimpan...', children, }: FormDialogProps) { return (
{ toast.error('Ada data yang belum sesuai, silakan periksa kembali input Anda.'); }} > {({ errors, processing }) => ( <> {title}
{typeof children === 'function' ? children({ errors, processing }) : children}
)}
); }