Skip to content

Commit

Permalink
Migrate the createInstance useApiMutation code
Browse files Browse the repository at this point in the history
  • Loading branch information
charliepark committed Sep 9, 2024
1 parent af42e70 commit e6b7834
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions app/forms/instance-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ export function CreateInstanceForm() {
const { project } = useProjectSelector()
const navigate = useNavigate()

const createInstance = useApiMutation('instanceCreate', {
const {
mutateAsync: createInstance,
isPending,
error,
} = useApiMutation('instanceCreate', {
onSuccess(instance) {
// refetch list of instances
queryClient.invalidateQueries('instanceList')
Expand Down Expand Up @@ -244,10 +248,10 @@ export function CreateInstanceForm() {
const imageSizeGiB = image?.size ? Math.ceil(image.size / GiB) : undefined

useEffect(() => {
if (createInstance.error) {
if (error) {
setIsSubmitting(false)
}
}, [createInstance.error])
}, [error])

// additional form elements for projectImage and siloImage tabs
const bootDiskSizeAndName = (
Expand Down Expand Up @@ -308,7 +312,7 @@ export function CreateInstanceForm() {
? await readBlobAsBase64(values.userData)
: undefined

await createInstance.mutateAsync({
await createInstance({
query: { project },
body: {
name: values.name,
Expand All @@ -325,8 +329,8 @@ export function CreateInstanceForm() {
},
})
}}
loading={createInstance.isPending}
submitError={createInstance.error}
loading={isPending}
submitError={error}
>
<NameField name="name" control={control} disabled={isSubmitting} />
<DescriptionField name="description" control={control} disabled={isSubmitting} />
Expand Down Expand Up @@ -573,7 +577,7 @@ export function CreateInstanceForm() {
siloPools={siloPools.items}
/>
<Form.Actions>
<Form.Submit loading={createInstance.isPending}>Create instance</Form.Submit>
<Form.Submit loading={isPending}>Create instance</Form.Submit>
<Form.Cancel onClick={() => navigate(pb.instances({ project }))} />
</Form.Actions>
</FullPageForm>
Expand Down

0 comments on commit e6b7834

Please sign in to comment.