From 3c4dba69dbbc7e148b876a0589877b2f363aa3da Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Thu, 29 Jun 2023 15:28:50 +0100 Subject: [PATCH] Added a confirmation dialog for when the user leaves questions unanswered --- src/components/BlankQuestionsModal.tsx | 56 ++++++++++++++++++++++++++ src/exams/Listening.tsx | 17 ++++++++ src/exams/Reading.tsx | 17 ++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/components/BlankQuestionsModal.tsx diff --git a/src/components/BlankQuestionsModal.tsx b/src/components/BlankQuestionsModal.tsx new file mode 100644 index 00000000..cd1d9650 --- /dev/null +++ b/src/components/BlankQuestionsModal.tsx @@ -0,0 +1,56 @@ +import {Dialog, Transition} from "@headlessui/react"; +import {Fragment} from "react"; +import Button from "./Low/Button"; + +interface Props { + isOpen: boolean; + onClose: (next?: boolean) => void; +} + +export default function BlankQuestionsModal({isOpen, onClose}: Props) { + return ( + + onClose(false)} className="relative z-50"> + +
+ + + +
+ + Questions Unanswered + + Please note that you are finishing the current module and once you proceed to the next module, you will no longer be + able to change the answers in the current one, including your unanswered questions.
+
+ Are you sure you want to continue without completing those questions? +
+
+ + +
+
+
+
+
+
+ ); +} diff --git a/src/exams/Listening.tsx b/src/exams/Listening.tsx index 36847401..11bf5e76 100644 --- a/src/exams/Listening.tsx +++ b/src/exams/Listening.tsx @@ -9,6 +9,7 @@ import {renderSolution} from "@/components/Solutions"; import ModuleTitle from "@/components/Medium/ModuleTitle"; import AudioPlayer from "@/components/Low/AudioPlayer"; import Button from "@/components/Low/Button"; +import BlankQuestionsModal from "@/components/BlankQuestionsModal"; interface Props { exam: ListeningExam; @@ -20,6 +21,16 @@ export default function Listening({exam, showSolutions = false, onFinish}: Props const [exerciseIndex, setExerciseIndex] = useState(-1); const [timesListened, setTimesListened] = useState(0); const [userSolutions, setUserSolutions] = useState([]); + 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) { @@ -31,6 +42,11 @@ export default function Listening({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: "listening", exam: exam.id})), @@ -79,6 +95,7 @@ export default function Listening({exam, showSolutions = false, onFinish}: Props return ( <> +
([]); + 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 ( <>
+ setShowTextModal(false)} />