Skip to content

Commit aa7ecdb

Browse files
committed
convert floating IP attach
1 parent 1b568f9 commit aa7ecdb

File tree

1 file changed

+33
-37
lines changed

1 file changed

+33
-37
lines changed

app/pages/project/floating-ips/FloatingIpsPage.tsx

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { IpGlobal16Icon, IpGlobal24Icon } from '@oxide/design-system/icons/react
2323

2424
import { DocsPopover } from '~/components/DocsPopover'
2525
import { ListboxField } from '~/components/form/fields/ListboxField'
26+
import { ModalForm } from '~/components/form/ModalForm'
2627
import { HL } from '~/components/HL'
2728
import { makeCrumb } from '~/hooks/use-crumbs'
2829
import { getProjectSelector, useProjectSelector } from '~/hooks/use-params'
@@ -38,7 +39,6 @@ import { CopyableIp } from '~/ui/lib/CopyableIp'
3839
import { CreateLink } from '~/ui/lib/CreateButton'
3940
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
4041
import { Message } from '~/ui/lib/Message'
41-
import { Modal } from '~/ui/lib/Modal'
4242
import { PageHeader, PageTitle } from '~/ui/lib/PageHeader'
4343
import { TableActions } from '~/ui/lib/Table'
4444
import { ALL_ISH } from '~/util/consts'
@@ -258,45 +258,41 @@ const AttachFloatingIpModal = ({
258258
addToast({ title: 'Error', content: err.message, variant: 'error' })
259259
},
260260
})
261+
261262
const form = useForm({ defaultValues: { instanceId: '' } })
262-
const instanceId = form.watch('instanceId')
263263

264264
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+
</>
297286
}
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>
301297
)
302298
}

0 commit comments

Comments
 (0)