@@ -24,6 +24,7 @@ import { DocsPopover } from '~/components/DocsPopover'
2424import { ComboboxField } from '~/components/form/fields/ComboboxField'
2525import { toImageComboboxItem } from '~/components/form/fields/ImageSelectField'
2626import { ListboxField } from '~/components/form/fields/ListboxField'
27+ import { ModalForm } from '~/components/form/ModalForm'
2728import { HL } from '~/components/HL'
2829import { confirmDelete } from '~/stores/confirm-delete'
2930import { addToast } from '~/stores/toast'
@@ -129,7 +130,7 @@ type Values = { project: string | null; image: string | null }
129130const defaultValues : Values = { project : null , image : null }
130131
131132const PromoteImageModal = ( { onDismiss } : { onDismiss : ( ) => void } ) => {
132- const { control , handleSubmit , watch , resetField } = useForm ( { defaultValues } )
133+ const form = useForm ( { defaultValues } )
133134
134135 const queryClient = useApiQueryClient ( )
135136
@@ -146,7 +147,7 @@ const PromoteImageModal = ({ onDismiss }: { onDismiss: () => void }) => {
146147
147148 const projects = useApiQuery ( 'projectList' , { } )
148149 const projectItems = useMemo ( ( ) => toComboboxItems ( projects . data ?. items ) , [ projects . data ] )
149- const selectedProject = watch ( 'project' )
150+ const selectedProject = form . watch ( 'project' )
150151
151152 // can only fetch images if a project is selected
152153 const images = useApiQuery (
@@ -165,44 +166,42 @@ const PromoteImageModal = ({ onDismiss }: { onDismiss: () => void }) => {
165166 }
166167
167168 return (
168- < Modal isOpen onDismiss = { onDismiss } title = "Promote image" >
169- < Modal . Body >
170- < Modal . Section >
171- < form autoComplete = "off" onSubmit = { handleSubmit ( onSubmit ) } className = "space-y-4" >
172- < ComboboxField
173- placeholder = "Select a project"
174- name = "project"
175- label = "Project"
176- items = { projectItems }
177- onChange = { ( ) => {
178- resetField ( 'image' ) // reset image field when the project changes
179- } }
180- isLoading = { projects . isPending }
181- required
182- control = { control }
183- />
184- < ListboxField
185- control = { control }
186- name = "image"
187- placeholder = "Select an image"
188- items = { imageItems }
189- isLoading = { images . isPending }
190- required
191- disabled = { ! selectedProject }
192- />
193- </ form >
194- < Message
195- variant = "info"
196- content = "Once an image has been promoted it is visible to all projects in a silo"
197- />
198- </ Modal . Section >
199- </ Modal . Body >
200- < Modal . Footer
201- onDismiss = { onDismiss }
202- onAction = { handleSubmit ( onSubmit ) }
203- actionText = "Promote"
169+ < ModalForm
170+ title = "Promote image"
171+ form = { form }
172+ resourceName = "Image"
173+ loading = { promoteImage . isPending }
174+ submitError = { promoteImage . error }
175+ onSubmit = { onSubmit }
176+ onDismiss = { onDismiss }
177+ submitLabel = "Promote"
178+ >
179+ < ComboboxField
180+ placeholder = "Select a project"
181+ name = "project"
182+ label = "Project"
183+ items = { projectItems }
184+ onChange = { ( ) => {
185+ form . resetField ( 'image' ) // reset image field when the project changes
186+ } }
187+ isLoading = { projects . isPending }
188+ required
189+ control = { form . control }
204190 />
205- </ Modal >
191+ < ListboxField
192+ control = { form . control }
193+ name = "image"
194+ placeholder = "Select an image"
195+ items = { imageItems }
196+ isLoading = { images . isPending }
197+ required
198+ disabled = { ! selectedProject }
199+ />
200+ < Message
201+ variant = "info"
202+ content = "Once an image has been promoted it is visible to all projects in a silo"
203+ />
204+ </ ModalForm >
206205 )
207206}
208207
0 commit comments