diff --git a/app/forms/subnet-create.tsx b/app/forms/subnet-create.tsx index b492202bc..d1953aeee 100644 --- a/app/forms/subnet-create.tsx +++ b/app/forms/subnet-create.tsx @@ -6,7 +6,6 @@ * Copyright Oxide Computer Company */ import { useNavigate } from 'react-router-dom' -import type { SetRequired } from 'type-fest' import { useApiMutation, useApiQueryClient, type VpcSubnetCreate } from '@oxide/api' @@ -24,13 +23,14 @@ import { useForm, useVpcSelector } from '~/hooks' import { FormDivider } from '~/ui/lib/Divider' import { pb } from '~/util/path-builder' -const defaultValues: SetRequired = { +const defaultValues: Required = { name: '', + description: '', + ipv4Block: '', + ipv6Block: '', // populate the form field with the value corresponding to an undefined custom // router on a subnet response customRouter: customRouterDataToForm(undefined), - description: '', - ipv4Block: '', } export function CreateSubnetForm() { @@ -56,12 +56,15 @@ export function CreateSubnetForm() { formType="create" resourceName="subnet" onDismiss={onDismiss} - onSubmit={(body) => + onSubmit={({ name, description, ipv4Block, ipv6Block, customRouter }) => createSubnet.mutate({ query: vpcSelector, body: { - ...body, - customRouter: customRouterFormToData(body.customRouter), + name, + description, + ipv4Block, + ipv6Block: ipv6Block.trim() || undefined, + customRouter: customRouterFormToData(customRouter), }, }) } diff --git a/app/forms/subnet-edit.tsx b/app/forms/subnet-edit.tsx index 5c87e9c8b..a8b5863c9 100644 --- a/app/forms/subnet-edit.tsx +++ b/app/forms/subnet-edit.tsx @@ -6,7 +6,6 @@ * Copyright Oxide Computer Company */ import { useNavigate, type LoaderFunctionArgs } from 'react-router-dom' -import type { SetRequired } from 'type-fest' import { apiQueryClient, @@ -57,7 +56,7 @@ export function EditSubnetForm() { }, }) - const defaultValues: SetRequired = { + const defaultValues: Required = { name: subnet.name, description: subnet.description, customRouter: customRouterDataToForm(subnet.customRouterId), diff --git a/test/e2e/vpcs.e2e.ts b/test/e2e/vpcs.e2e.ts index 6f9f7f20d..f9ee5a207 100644 --- a/test/e2e/vpcs.e2e.ts +++ b/test/e2e/vpcs.e2e.ts @@ -63,6 +63,11 @@ test('can create and delete subnet', async ({ page }) => { await dialog.getByRole('textbox', { name: 'Name' }).fill('mock-subnet-2') await dialog.getByRole('textbox', { name: 'IPv4 block' }).fill('10.1.1.2/24') + + // little hack to catch a bug where we weren't handling empty input here properly + await dialog.getByRole('textbox', { name: 'IPv6 block' }).fill('abc') + await dialog.getByRole('textbox', { name: 'IPv6 block' }).clear() + await dialog.getByRole('button', { name: 'Create subnet' }).click() await expect(dialog).toBeHidden()