Skip to content

Commit dd7cd95

Browse files
authored
fix: can submit create instance without image if /images response empty (#1028)
1 parent c2f91e0 commit dd7cd95

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

app/forms/instance-create.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as Yup from 'yup'
2+
import { useNavigate } from 'react-router-dom'
13
import invariant from 'tiny-invariant'
24

35
import type {
@@ -80,6 +82,7 @@ export default function CreateInstanceForm({
8082
onError,
8183
...props
8284
}: CreateFullPageFormProps<InstanceCreateInput, Instance>) {
85+
const navigate = useNavigate()
8386
const queryClient = useApiQueryClient()
8487
const addToast = useToast()
8588
const pageParams = useParams('orgName', 'projectName')
@@ -116,6 +119,12 @@ export default function CreateInstanceForm({
116119
initialValues={initialValues}
117120
title={title}
118121
icon={<Instances24Icon />}
122+
validationSchema={Yup.object({
123+
// needed to cover case where there are no images, in which case there
124+
// are no individual radio fields marked required, which unfortunately
125+
// is how required radio fields work
126+
globalImage: Yup.string().required(),
127+
})}
119128
onSubmit={
120129
onSubmit ||
121130
(async (values) => {
@@ -218,6 +227,7 @@ export default function CreateInstanceForm({
218227
<Tabs id="boot-disk-tabs" aria-describedby="boot-disk" fullWidth>
219228
<Tab>Distros</Tab>
220229
<Tab.Panel className="space-y-4">
230+
{images.length === 0 && <span>No images found</span>}
221231
<ImageSelectField
222232
id="boot-disk-image"
223233
name="globalImage"
@@ -235,9 +245,13 @@ export default function CreateInstanceForm({
235245
<DiskSizeField id="disk-size" label="Disk size" name="bootDiskSize" />
236246
</Tab.Panel>
237247
<Tab>Images</Tab>
238-
<Tab.Panel></Tab.Panel>
248+
<Tab.Panel>
249+
<span>No images found</span>
250+
</Tab.Panel>
239251
<Tab>Snapshots</Tab>
240-
<Tab.Panel></Tab.Panel>
252+
<Tab.Panel>
253+
<span>No snapshots found</span>
254+
</Tab.Panel>
241255
</Tabs>
242256
<Divider />
243257
<Form.Heading id="additional-disks">Additional disks</Form.Heading>
@@ -255,7 +269,8 @@ export default function CreateInstanceForm({
255269
<Form.Submit loading={createDisk.isLoading || createInstance.isLoading}>
256270
{title}
257271
</Form.Submit>
258-
<Form.Cancel />
272+
{/* TODO: this nav may not always be correct. Could get rid of the button instead. */}
273+
<Form.Cancel onClick={() => navigate('..')} />
259274
</Form.Actions>
260275
</FullPageForm>
261276
)

0 commit comments

Comments
 (0)