@@ -13,9 +13,10 @@ import { ListboxField } from '~/components/form/fields/ListboxField'
13
13
import { HL } from '~/components/HL'
14
14
import { addToast } from '~/stores/toast'
15
15
import { Message } from '~/ui/lib/Message'
16
- import { Modal } from '~/ui/lib/Modal'
17
16
import { Slash } from '~/ui/lib/Slash'
18
17
18
+ import { ModalForm } from './form/ModalForm'
19
+
19
20
function FloatingIpLabel ( { fip } : { fip : FloatingIp } ) {
20
21
return (
21
22
< div className = "text-secondary selected:text-accent-secondary" >
@@ -60,40 +61,39 @@ export const AttachFloatingIpModal = ({
60
61
const floatingIp = form . watch ( 'floatingIp' )
61
62
62
63
return (
63
- < Modal isOpen title = "Attach floating IP" onDismiss = { onDismiss } >
64
- < Modal . Body >
65
- < Modal . Section >
66
- < Message
67
- variant = "info"
68
- content = { `Instance ‘${ instance . name } ’ will be reachable at the selected IP address` }
69
- />
70
- < form >
71
- < ListboxField
72
- control = { form . control }
73
- name = "floatingIp"
74
- label = "Floating IP"
75
- placeholder = "Select a floating IP"
76
- items = { floatingIps . map ( ( ip ) => ( {
77
- value : ip . id ,
78
- label : < FloatingIpLabel fip = { ip } /> ,
79
- selectedLabel : ip . name ,
80
- } ) ) }
81
- required
82
- />
83
- </ form >
84
- </ Modal . Section >
85
- </ Modal . Body >
86
- < Modal . Footer
87
- actionText = "Attach"
88
- disabled = { ! floatingIp }
89
- onAction = { ( ) =>
90
- floatingIpAttach . mutate ( {
91
- path : { floatingIp } , // note that this is an ID!
92
- body : { kind : 'instance' , parent : instance . id } ,
93
- } )
94
- }
95
- onDismiss = { onDismiss }
96
- > </ Modal . Footer >
97
- </ Modal >
64
+ < ModalForm
65
+ form = { form }
66
+ onDismiss = { onDismiss }
67
+ submitLabel = "Attach floating IP"
68
+ submitError = { floatingIpAttach . error }
69
+ loading = { floatingIpAttach . isPending }
70
+ title = "Attach floating IP"
71
+ onSubmit = { ( ) =>
72
+ floatingIpAttach . mutate ( {
73
+ path : { floatingIp } , // note that this is an ID!
74
+ body : { kind : 'instance' , parent : instance . id } ,
75
+ } )
76
+ }
77
+ submitDisabled = { ! floatingIp }
78
+ >
79
+ < Message
80
+ variant = "info"
81
+ content = { `Instance ‘${ instance . name } ’ will be reachable at the selected IP address` }
82
+ />
83
+ < form >
84
+ < ListboxField
85
+ control = { form . control }
86
+ name = "floatingIp"
87
+ label = "Floating IP"
88
+ placeholder = "Select a floating IP"
89
+ items = { floatingIps . map ( ( ip ) => ( {
90
+ value : ip . id ,
91
+ label : < FloatingIpLabel fip = { ip } /> ,
92
+ selectedLabel : ip . name ,
93
+ } ) ) }
94
+ required
95
+ />
96
+ </ form >
97
+ </ ModalForm >
98
98
)
99
99
}
0 commit comments