@@ -16,66 +16,41 @@ import { Modal, type ModalProps } from '~/ui/lib/Modal'
1616
1717type ModalFormProps < TFieldValues extends FieldValues > = {
1818 form : UseFormReturn < TFieldValues >
19- /**
20- * A function that returns the fields.
21- *
22- * Implemented as a function so we can pass `control` to the fields in the
23- * calling code. We could do that internally with `cloneElement` instead, but
24- * then in the calling code, the field would not infer `TFieldValues` and
25- * constrain the `name` prop to paths in the values object.
26- */
2719 children : ReactNode
28- resourceName : string
2920 /** Must be provided with a reason describing why it's disabled */
3021 submitDisabled ?: string
31-
22+ onSubmit : ( values : TFieldValues ) => void
23+ submitLabel : string
3224 // require loading and error so we can't forget to hook them up. there are a
3325 // few forms that don't need them, so we'll use dummy values
3426
3527 /** Error from the API call */
3628 submitError : ApiError | null
3729 loading : boolean
38-
39- /** Only needed if you need to override the default title (Create/Edit ${resourceName}) */
40- subtitle ?: ReactNode
41- onSubmit : ( values : TFieldValues ) => void
42-
43- submitLabel ?: string
4430} & Omit < ModalProps , 'isOpen' >
4531
4632export function ModalForm < TFieldValues extends FieldValues > ( {
4733 form,
4834 children,
4935 onDismiss,
50- resourceName,
5136 submitDisabled,
5237 submitError,
5338 title,
5439 onSubmit,
5540 submitLabel = 'Save' ,
5641 loading,
57- subtitle,
5842 width = 'medium' ,
5943 overlay = true ,
6044} : ModalFormProps < TFieldValues > ) {
6145 const id = useId ( )
6246
6347 const { isSubmitting } = form . formState
6448
65- const modalTitle = title || `Create ${ resourceName } `
66-
6749 return (
6850 < >
69- < Modal
70- isOpen
71- onDismiss = { onDismiss }
72- title = { modalTitle }
73- width = { width }
74- overlay = { overlay }
75- >
51+ < Modal isOpen onDismiss = { onDismiss } title = { title } width = { width } overlay = { overlay } >
7652 < Modal . Body >
7753 < Modal . Section >
78- { subtitle && < div className = "mb-4" > { subtitle } </ div > }
7954 { submitError && (
8055 < Message variant = "error" title = "Error" content = { submitError . message } />
8156 ) }
0 commit comments