Skip to content

Commit 2cbd293

Browse files
committed
clean up props a bit
1 parent 13ac403 commit 2cbd293

File tree

3 files changed

+7
-43
lines changed

3 files changed

+7
-43
lines changed

app/components/form/ModalForm.tsx

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,41 @@ import { Modal, type ModalProps } from '~/ui/lib/Modal'
1616

1717
type 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

4632
export 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
)}

app/components/form/SideModalForm.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ type EditFormProps = {
3030

3131
type SideModalFormProps<TFieldValues extends FieldValues> = {
3232
form: UseFormReturn<TFieldValues>
33-
/**
34-
* A function that returns the fields.
35-
*
36-
* Implemented as a function so we can pass `control` to the fields in the
37-
* calling code. We could do that internally with `cloneElement` instead, but
38-
* then in the calling code, the field would not infer `TFieldValues` and
39-
* constrain the `name` prop to paths in the values object.
40-
*/
4133
children: ReactNode
4234
onDismiss: () => void
4335
resourceName: string

app/pages/SiloImagesPage.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,16 @@ const PromoteImageModal = ({ onDismiss }: { onDismiss: () => void }) => {
160160
[images.data]
161161
)
162162

163-
const onSubmit = ({ image, project }: Values) => {
164-
if (!image || !project) return
165-
promoteImage.mutate({ path: { image } })
166-
}
167-
168163
return (
169164
<ModalForm
170165
title="Promote image"
171166
form={form}
172-
resourceName="Image"
173167
loading={promoteImage.isPending}
174168
submitError={promoteImage.error}
175-
onSubmit={onSubmit}
169+
onSubmit={({ image, project }) => {
170+
if (!image || !project) return // shouldn't happen because of validation
171+
promoteImage.mutate({ path: { image } })
172+
}}
176173
onDismiss={onDismiss}
177174
submitLabel="Promote"
178175
>

0 commit comments

Comments
 (0)