88import * as Accordion from '@radix-ui/react-accordion'
99import { useState } from 'react'
1010import { useNavigate } from 'react-router-dom'
11- import type { SetRequired } from 'type-fest'
1211
1312import {
1413 useApiMutation ,
@@ -22,14 +21,12 @@ import { AccordionItem } from '~/components/AccordionItem'
2221import { DescriptionField } from '~/components/form/fields/DescriptionField'
2322import { ListboxField } from '~/components/form/fields/ListboxField'
2423import { NameField } from '~/components/form/fields/NameField'
25- import { TextField } from '~/components/form/fields/TextField'
2624import { SideModalForm } from '~/components/form/SideModalForm'
2725import { useForm , useProjectSelector } from '~/hooks'
2826import { addToast } from '~/stores/toast'
2927import { Badge } from '~/ui/lib/Badge'
3028import { Message } from '~/ui/lib/Message'
3129import { pb } from '~/util/path-builder'
32- import { validateIp } from '~/util/str'
3330
3431const toListboxItem = ( p : SiloIpPool ) => {
3532 if ( ! p . isDefault ) {
@@ -50,11 +47,10 @@ const toListboxItem = (p: SiloIpPool) => {
5047 }
5148}
5249
53- const defaultValues : SetRequired < FloatingIpCreate , 'ip' > = {
50+ const defaultValues : Omit < FloatingIpCreate , 'ip' > = {
5451 name : '' ,
5552 description : '' ,
5653 pool : undefined ,
57- ip : '' ,
5854}
5955
6056export function CreateFloatingIpSideModalForm ( ) {
@@ -78,7 +74,6 @@ export function CreateFloatingIpSideModalForm() {
7874 } )
7975
8076 const form = useForm ( { defaultValues } )
81- const isPoolSelected = ! ! form . watch ( 'pool' )
8277
8378 const [ openItems , setOpenItems ] = useState < string [ ] > ( [ ] )
8479
@@ -88,13 +83,7 @@ export function CreateFloatingIpSideModalForm() {
8883 formType = "create"
8984 resourceName = "floating IP"
9085 onDismiss = { ( ) => navigate ( pb . floatingIps ( projectSelector ) ) }
91- onSubmit = { ( { ip, ...rest } ) => {
92- createFloatingIp . mutate ( {
93- query : projectSelector ,
94- // if address is '', evaluate as false and send as undefined
95- body : { ip : ip || undefined , ...rest } ,
96- } )
97- } }
86+ onSubmit = { ( body ) => createFloatingIp . mutate ( { query : projectSelector , body } ) }
9887 loading = { createFloatingIp . isPending }
9988 submitError = { createFloatingIp . error }
10089 >
@@ -124,16 +113,6 @@ export function CreateFloatingIpSideModalForm() {
124113 control = { form . control }
125114 placeholder = "Select pool"
126115 />
127- < TextField
128- name = "ip"
129- label = "IP address"
130- control = { form . control }
131- disabled = { ! isPoolSelected }
132- transform = { ( v ) => v . replace ( / \s / g, '' ) }
133- validate = { ( ip ) =>
134- ip && ! validateIp ( ip ) . valid ? 'Not a valid IP address' : true
135- }
136- />
137116 </ AccordionItem >
138117 </ Accordion . Root >
139118 </ SideModalForm >
0 commit comments