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 Select, { SelectChangeEvent } from "@mui/material/Select";
import { useEffect } from "react";
import { toast } from "react-hot-toast";
import { CreateMachineForm, FormStepContentProps } from "./interfaces";
const ITEM_HEIGHT = 48;
@@ -52,11 +53,17 @@ export default function ClanModules(props: ClanModulesProps) {
const newValue = typeof value === "string" ? value.split(",") : value;
formHooks.setValue("modules", newValue);
setMachineSchema(clanName, "example_machine", {
imports: selectedModules,
}).then((response) => {
imports: newValue,
})
.then((response) => {
if (response.statusText == "OK") {
formHooks.setValue("schema", response.data.schema);
}
})
.catch((error) => {
formHooks.setValue("schema", {});
console.error({ error });
toast.error(`${error.message}`);
});
};
return (

View File

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