Added a confirmation dialog for when the user leaves questions unanswered

This commit is contained in:
Tiago Ribeiro
2023-06-29 15:28:50 +01:00
parent 3fac92b54d
commit 3c4dba69db
3 changed files with 90 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ import ProgressBar from "@/components/Low/ProgressBar";
import ModuleTitle from "@/components/Medium/ModuleTitle";
import {Divider} from "primereact/divider";
import Button from "@/components/Low/Button";
import BlankQuestionsModal from "@/components/BlankQuestionsModal";
interface Props {
exam: ReadingExam;
@@ -83,6 +84,16 @@ export default function Reading({exam, showSolutions = false, onFinish}: Props)
const [exerciseIndex, setExerciseIndex] = useState(-1);
const [showTextModal, setShowTextModal] = useState(false);
const [userSolutions, setUserSolutions] = useState<UserSolution[]>([]);
const [showBlankModal, setShowBlankModal] = useState(false);
const confirmFinishModule = (keepGoing?: boolean) => {
if (!keepGoing) {
setShowBlankModal(false);
return;
}
onFinish(userSolutions.map((x) => ({...x, module: "reading", exam: exam.id})));
};
const nextExercise = (solution?: UserSolution) => {
if (solution) {
@@ -94,6 +105,11 @@ export default function Reading({exam, showSolutions = false, onFinish}: Props)
return;
}
if (!userSolutions.map((x) => x.score.missing).every((x) => x === 0)) {
setShowBlankModal(true);
return;
}
if (solution) {
onFinish(
[...userSolutions.filter((x) => x.exercise !== solution.exercise), solution].map((x) => ({...x, module: "reading", exam: exam.id})),
@@ -142,6 +158,7 @@ export default function Reading({exam, showSolutions = false, onFinish}: Props)
return (
<>
<div className="flex flex-col h-full w-full gap-8">
<BlankQuestionsModal isOpen={showBlankModal} onClose={confirmFinishModule} />
<TextModal {...exam.text} isOpen={showTextModal} onClose={() => setShowTextModal(false)} />
<ModuleTitle
minTimer={exam.minTimer}