dstpabuaran.com/resources/js/components/form-dialog.tsx
Yoga Pangestu d91ec8869e refactor: replace tooltip buttons with row actions component in supplier and role columns
feat: implement delete confirmation dialog component for better UX

refactor: update supplier and role index pages to utilize new form dialog and delete confirm dialog components

feat: add reusable form dialog component for creating and editing entities

feat: introduce filter popover component for enhanced filtering options in data tables

feat: create image preview button component for displaying images with modal preview

feat: add page header component for consistent page layout

feat: implement row actions component for handling actions on table rows

feat: add status badge component for displaying entity statuses

feat: create toggle status component for easily toggling entity states

feat: implement draft save hook for auto-saving form data

feat: add server table hook for managing server-side pagination and filtering

feat: create utility functions for formatting dates and numbers

feat: add constants for month names and measurement units
2026-08-02 23:40:12 +07:00

82 lines
2.6 KiB
TypeScript

import { Form } from '@inertiajs/react';
import type { ReactNode } from 'react';
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<typeof Form>['action'];
resetOnSuccess?: boolean;
onSuccess?: () => void;
submitDisabled?: boolean;
submitLabel?: ReactNode;
submittingLabel?: ReactNode;
children:
| ReactNode
| ((ctx: {
errors: Record<string, string>;
processing: boolean;
}) => ReactNode);
};
export function FormDialog({
open,
onOpenChange,
title,
action,
resetOnSuccess,
onSuccess,
submitDisabled = false,
submitLabel = 'Simpan',
submittingLabel = 'Menyimpan...',
children,
}: FormDialogProps) {
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<Form
action={action}
resetOnSuccess={resetOnSuccess}
onSuccess={onSuccess}
>
{({ errors, processing }) => (
<>
<DialogHeader>
<DialogTitle>{title}</DialogTitle>
</DialogHeader>
<div className="grid gap-4 py-4">
{typeof children === 'function'
? children({ errors, processing })
: children}
</div>
<DialogFooter>
<Button
type="button"
variant="outline"
onClick={() => onOpenChange(false)}
>
Batal
</Button>
<Button
type="submit"
disabled={processing || submitDisabled}
>
{processing ? submittingLabel : submitLabel}
</Button>
</DialogFooter>
</>
)}
</Form>
</DialogContent>
</Dialog>
);
}