From 4f9d814abee394f7bc802cb9ee106e8cd7d45608 Mon Sep 17 00:00:00 2001 From: Sol Dubock <94075844+sjd210@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:11:04 +0100 Subject: [PATCH 1/3] Apply front-end warning to reassigning tests --- .../components/elements/modals/QuizSettingModal.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app/components/elements/modals/QuizSettingModal.tsx b/src/app/components/elements/modals/QuizSettingModal.tsx index e6c87d7f6e..42bebe1ff2 100644 --- a/src/app/components/elements/modals/QuizSettingModal.tsx +++ b/src/app/components/elements/modals/QuizSettingModal.tsx @@ -7,7 +7,8 @@ import { useAppDispatch, useAppSelector, useAssignQuizMutation, - useGetGroupsQuery + useGetGroupsQuery, + useGetQuizAssignmentsSetByMeQuery, } from "../../../state"; import {assignMultipleQuiz, isDefined, Item, selectOnChange, TODAY} from "../../../services"; import range from "lodash/range"; @@ -59,6 +60,8 @@ export function QuizSettingModal({quiz, dueDate: initialDueDate, scheduledStartD const [scheduledStartDate, setScheduledStartDate] = useState(initialScheduledStartDate ?? null); const [feedbackMode, setFeedbackMode] = useState(initialFeedbackMode ?? null); + const allQuizAssignments = useGetQuizAssignmentsSetByMeQuery().data; + const yearRange = range(currentYear, currentYear + 5); function addValidated(what: ControlName) { @@ -86,7 +89,7 @@ export function QuizSettingModal({quiz, dueDate: initialDueDate, scheduledStartD }); } - const groupInvalid = validated.has('group') && selectedGroups.length === 0; + const groupInvalid = validated.has('group') && selectedGroups.length === 0 || selectedGroups.some(group => allQuizAssignments?.some(assignment => assignment.quizId === quiz.id && assignment.groupId === group.value)); const dueDateInvalid = isDefined(dueDate) && ((scheduledStartDate ? scheduledStartDate.valueOf() > dueDate.valueOf() : false) || dueDate.valueOf() < Date.now()); const scheduledStartDateInvalid = isDefined(scheduledStartDate) && scheduledStartDate.valueOf() < TODAY().valueOf(); const feedbackModeInvalid = validated.has('feedbackMode') && feedbackMode === null; @@ -117,7 +120,7 @@ export function QuizSettingModal({quiz, dueDate: initialDueDate, scheduledStartD />; }} /> - {groupInvalid && You must select a group} + {groupInvalid && (selectedGroups.length === 0 ? You must select a group : You cannot reassign a test to this group(s) until the due date has passed.)}