Added title to the exam generate

This commit is contained in:
Joao Ramos
2024-08-06 19:24:43 +01:00
parent cf64a91651
commit 95c3f89911
7 changed files with 94 additions and 19 deletions

View File

@@ -258,7 +258,11 @@ const PartTab = ({
);
};
const ReadingGeneration = () => {
interface Props {
id: string;
}
const ReadingGeneration = ({ id } : Props) => {
const [part1, setPart1] = useState<ReadingPart>();
const [part2, setPart2] = useState<ReadingPart>();
const [part3, setPart3] = useState<ReadingPart>();
@@ -300,13 +304,18 @@ const ReadingGeneration = () => {
return;
}
if(!id) {
toast.error("Please insert a title before submitting");
return;
}
setIsLoading(true);
const exam: ReadingExam = {
parts,
isDiagnostic: false,
minTimer,
module: "reading",
id: generate({minLength: 4, maxLength: 8, min: 3, max: 5, join: " ", formatter: capitalize}),
id,
type: "academic",
variant: parts.length === 3 ? "full" : "partial",
difficulty,
@@ -328,7 +337,7 @@ const ReadingGeneration = () => {
})
.catch((error) => {
console.log(error);
toast.error("Something went wrong while generating, please try again later.");
toast.error(error.response.data.error || "Something went wrong while generating, please try again later.");
})
.finally(() => setIsLoading(false));
};