@@ -23,6 +23,7 @@ import { IpGlobal16Icon, IpGlobal24Icon } from '@oxide/design-system/icons/react
23
23
24
24
import { DocsPopover } from '~/components/DocsPopover'
25
25
import { ListboxField } from '~/components/form/fields/ListboxField'
26
+ import { ModalForm } from '~/components/form/ModalForm'
26
27
import { HL } from '~/components/HL'
27
28
import { makeCrumb } from '~/hooks/use-crumbs'
28
29
import { getProjectSelector , useProjectSelector } from '~/hooks/use-params'
@@ -38,7 +39,6 @@ import { CopyableIp } from '~/ui/lib/CopyableIp'
38
39
import { CreateLink } from '~/ui/lib/CreateButton'
39
40
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
40
41
import { Message } from '~/ui/lib/Message'
41
- import { Modal } from '~/ui/lib/Modal'
42
42
import { PageHeader , PageTitle } from '~/ui/lib/PageHeader'
43
43
import { TableActions } from '~/ui/lib/Table'
44
44
import { ALL_ISH } from '~/util/consts'
@@ -258,45 +258,41 @@ const AttachFloatingIpModal = ({
258
258
addToast ( { title : 'Error' , content : err . message , variant : 'error' } )
259
259
} ,
260
260
} )
261
+
261
262
const form = useForm ( { defaultValues : { instanceId : '' } } )
262
- const instanceId = form . watch ( 'instanceId' )
263
263
264
264
return (
265
- < Modal isOpen title = "Attach floating IP" onDismiss = { onDismiss } >
266
- < Modal . Body >
267
- < Modal . Section >
268
- < Message
269
- variant = "info"
270
- content = {
271
- < >
272
- The selected instance will be reachable at < HL > { address } </ HL >
273
- </ >
274
- }
275
- />
276
- < form >
277
- < ListboxField
278
- control = { form . control }
279
- name = "instanceId"
280
- items = { instances . map ( ( i ) => ( { value : i . id , label : i . name } ) ) }
281
- label = "Instance"
282
- required
283
- placeholder = "Select an instance"
284
- />
285
- </ form >
286
- </ Modal . Section >
287
- </ Modal . Body >
288
- < Modal . Footer
289
- actionText = "Attach"
290
- disabled = { ! instanceId }
291
- onAction = { ( ) =>
292
- floatingIpAttach . mutate ( {
293
- path : { floatingIp } ,
294
- query : { project } ,
295
- body : { kind : 'instance' , parent : instanceId } ,
296
- } )
265
+ < ModalForm
266
+ title = "Attach floating IP"
267
+ form = { form }
268
+ onSubmit = { ( { instanceId } ) => {
269
+ floatingIpAttach . mutate ( {
270
+ path : { floatingIp } ,
271
+ query : { project } ,
272
+ body : { kind : 'instance' , parent : instanceId } ,
273
+ } )
274
+ } }
275
+ submitLabel = "Attach"
276
+ submitError = { floatingIpAttach . error }
277
+ loading = { floatingIpAttach . isPending }
278
+ onDismiss = { onDismiss }
279
+ >
280
+ < Message
281
+ variant = "info"
282
+ content = {
283
+ < >
284
+ The selected instance will be reachable at < HL > { address } </ HL >
285
+ </ >
297
286
}
298
- onDismiss = { onDismiss }
299
- > </ Modal . Footer >
300
- </ Modal >
287
+ />
288
+ < ListboxField
289
+ control = { form . control }
290
+ name = "instanceId"
291
+ items = { instances . map ( ( i ) => ( { value : i . id , label : i . name } ) ) }
292
+ label = "Instance"
293
+ required
294
+ placeholder = "Select an instance"
295
+ />
296
+ </ ModalForm >
301
297
)
302
298
}
0 commit comments