@@ -10,17 +10,27 @@ import { useNavigate } from 'react-router-dom'
1010import { useApiMutation , useApiQueryClient , type VpcSubnetCreate } from '@oxide/api'
1111
1212import { DescriptionField } from '~/components/form/fields/DescriptionField'
13+ import { ListboxField } from '~/components/form/fields/ListboxField'
1314import { NameField } from '~/components/form/fields/NameField'
1415import { TextField } from '~/components/form/fields/TextField'
16+ import {
17+ customRouterDataToForm ,
18+ customRouterFormToData ,
19+ useCustomRouterItems ,
20+ } from '~/components/form/fields/useItemsList'
1521import { SideModalForm } from '~/components/form/SideModalForm'
1622import { useForm , useVpcSelector } from '~/hooks'
1723import { FormDivider } from '~/ui/lib/Divider'
1824import { pb } from '~/util/path-builder'
1925
20- const defaultValues : VpcSubnetCreate = {
26+ const defaultValues : Required < VpcSubnetCreate > = {
2127 name : '' ,
2228 description : '' ,
2329 ipv4Block : '' ,
30+ ipv6Block : '' ,
31+ // populate the form field with the value corresponding to an undefined custom
32+ // router on a subnet response
33+ customRouter : customRouterDataToForm ( undefined ) ,
2434}
2535
2636export function CreateSubnetForm ( ) {
@@ -38,14 +48,26 @@ export function CreateSubnetForm() {
3848 } )
3949
4050 const form = useForm ( { defaultValues } )
51+ const { isLoading, items } = useCustomRouterItems ( )
4152
4253 return (
4354 < SideModalForm
4455 form = { form }
4556 formType = "create"
4657 resourceName = "subnet"
4758 onDismiss = { onDismiss }
48- onSubmit = { ( body ) => createSubnet . mutate ( { query : vpcSelector , body } ) }
59+ onSubmit = { ( { name, description, ipv4Block, ipv6Block, customRouter } ) =>
60+ createSubnet . mutate ( {
61+ query : vpcSelector ,
62+ body : {
63+ name,
64+ description,
65+ ipv4Block,
66+ ipv6Block : ipv6Block . trim ( ) || undefined ,
67+ customRouter : customRouterFormToData ( customRouter ) ,
68+ } ,
69+ } )
70+ }
4971 loading = { createSubnet . isPending }
5072 submitError = { createSubnet . error }
5173 >
@@ -54,6 +76,16 @@ export function CreateSubnetForm() {
5476 < FormDivider />
5577 < TextField name = "ipv4Block" label = "IPv4 block" required control = { form . control } />
5678 < TextField name = "ipv6Block" label = "IPv6 block" control = { form . control } />
79+ < FormDivider />
80+ < ListboxField
81+ label = "Custom router"
82+ name = "customRouter"
83+ placeholder = "Select a custom router"
84+ isLoading = { isLoading }
85+ items = { items }
86+ control = { form . control }
87+ required
88+ />
5789 </ SideModalForm >
5890 )
5991}
0 commit comments