add error handling

prevent the user to go into next step if schema cannot be retrieved
This commit is contained in:
Johannes Kirschbauer
2023-11-04 15:10:37 +01:00
parent 46cd25cc0d
commit 37533aa00d
2 changed files with 17 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ import MenuItem from "@mui/material/MenuItem";
import OutlinedInput from "@mui/material/OutlinedInput"; import OutlinedInput from "@mui/material/OutlinedInput";
import Select, { SelectChangeEvent } from "@mui/material/Select"; import Select, { SelectChangeEvent } from "@mui/material/Select";
import { useEffect } from "react"; import { useEffect } from "react";
import { toast } from "react-hot-toast";
import { CreateMachineForm, FormStepContentProps } from "./interfaces"; import { CreateMachineForm, FormStepContentProps } from "./interfaces";
const ITEM_HEIGHT = 48; const ITEM_HEIGHT = 48;
@@ -52,12 +53,18 @@ export default function ClanModules(props: ClanModulesProps) {
const newValue = typeof value === "string" ? value.split(",") : value; const newValue = typeof value === "string" ? value.split(",") : value;
formHooks.setValue("modules", newValue); formHooks.setValue("modules", newValue);
setMachineSchema(clanName, "example_machine", { setMachineSchema(clanName, "example_machine", {
imports: selectedModules, imports: newValue,
}).then((response) => { })
if (response.statusText == "OK") { .then((response) => {
formHooks.setValue("schema", response.data.schema); if (response.statusText == "OK") {
} formHooks.setValue("schema", response.data.schema);
}); }
})
.catch((error) => {
formHooks.setValue("schema", {});
console.error({ error });
toast.error(`${error.message}`);
});
}; };
return ( return (
<div className="my-4 flex w-full flex-col justify-center px-2"> <div className="my-4 flex w-full flex-col justify-center px-2">

View File

@@ -100,7 +100,10 @@ export function CreateMachineForm() {
<> <>
{activeStep !== steps.length - 1 && ( {activeStep !== steps.length - 1 && (
<Button <Button
disabled={!formHooks.formState.isValid} disabled={
!formHooks.formState.isValid ||
(activeStep == 1 && !formHooks.watch("schema")?.type)
}
onClick={handleNext} onClick={handleNext}
color="secondary" color="secondary"
> >