From d3c01fa758ef1211bbe3bccebb167a774a64c180 Mon Sep 17 00:00:00 2001 From: R0drig0-P Date: Sun, 10 Nov 2024 15:39:51 +0000 Subject: [PATCH 1/2] Made the submitting exchange button disabled when any type of conflicts exist --- .../exchange/requests/view/cards/RequestCard.tsx | 10 +++++++++- src/components/planner/schedules/LessonBox.tsx | 8 +++++++- src/contexts/CombinedProvider.tsx | 7 ++++++- src/contexts/ConflictsContext.tsx | 13 +++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/contexts/ConflictsContext.tsx diff --git a/src/components/exchange/requests/view/cards/RequestCard.tsx b/src/components/exchange/requests/view/cards/RequestCard.tsx index b3cb56be..00efd47d 100644 --- a/src/components/exchange/requests/view/cards/RequestCard.tsx +++ b/src/components/exchange/requests/view/cards/RequestCard.tsx @@ -7,6 +7,7 @@ import exchangeRequestService from "../../../../../api/services/exchangeRequestS import { ListRequestChanges } from "./ListRequestChanges"; import ExchangeRequestCommonContext from "../../../../../contexts/ExchangeRequestCommonContext"; import { CommonCardHeader } from "./CommonCardHeader"; +import ConflictsContext from "../../../../../contexts/ConflictsContext"; export const RequestCard = ({ }) => { const { @@ -15,6 +16,8 @@ export const RequestCard = ({ }) => { } = useContext(ExchangeRequestCommonContext); const [hovered, setHovered] = useState(false); + const { conflictsExist } = useContext(ConflictsContext); + useEffect(() => { if (chosenRequest?.id !== request.id) { setOpen(false); @@ -102,7 +105,12 @@ export const RequestCard = ({ }) => {
-
diff --git a/src/components/planner/schedules/LessonBox.tsx b/src/components/planner/schedules/LessonBox.tsx index b447b9af..f8ce8b91 100644 --- a/src/components/planner/schedules/LessonBox.tsx +++ b/src/components/planner/schedules/LessonBox.tsx @@ -1,6 +1,7 @@ import classNames from 'classnames' -import { useState, useEffect } from 'react' +import { useContext, useState, useEffect } from 'react' +import ConflictsContext from '../../../contexts/ConflictsContext' import LessonPopover from './LessonPopover' import ConflictsPopover from './ConflictsPopover' import { CourseInfo, ClassInfo, SlotInfo, ClassDescriptor, ConflictInfo } from '../../../@types' @@ -40,6 +41,7 @@ const LessonBox = ({ const [isHovered, setIsHovered] = useState(false) const [conflict, setConflict] = useState(conflicts[slotInfo.id]); const hasConflict = conflict?.conflictingClasses?.length > 1; + const { setConflictsExist } = useContext(ConflictsContext); // Needs to change the entry with the id of this lesson to contain the correct ConflictInfo when the classes change useEffect(() => { @@ -72,6 +74,10 @@ const LessonBox = ({ setConflict(newConflictInfo); }, [classInfo, classes]); + useEffect(() => { + setConflictsExist(hasConflict); + },[hasConflict]); + const showConflicts = () => { setConflictsShown(true) } diff --git a/src/contexts/CombinedProvider.tsx b/src/contexts/CombinedProvider.tsx index e6a75fe2..ed2dfc56 100644 --- a/src/contexts/CombinedProvider.tsx +++ b/src/contexts/CombinedProvider.tsx @@ -8,6 +8,7 @@ import useSession from "../hooks/useSession"; import SessionContext from "./SessionContext"; import MajorContext from "./MajorContext"; import CourseContext from "./CourseContext"; +import ConflictsContext from "./ConflictsContext"; type Props = { children: React.JSX.Element @@ -28,6 +29,8 @@ const CombinedProvider = ({ children }: Props) => { const [selectedOption, setSelectedOptionState] = useState(StorageAPI.getSelectedOptionStorage()); const { signedIn } = useSession(); + const [conflictsExist, setConflictsExist] = useState(false); + const setMultipleOptions = (newMultipleOptions: MultipleOptions | ((prevMultipleOptions: MultipleOptions) => MultipleOptions)) => { if (newMultipleOptions instanceof Function) newMultipleOptions = newMultipleOptions(multipleOptions); @@ -58,7 +61,9 @@ const CombinedProvider = ({ children }: Props) => { } }> - {children} + + {children} + diff --git a/src/contexts/ConflictsContext.tsx b/src/contexts/ConflictsContext.tsx new file mode 100644 index 00000000..bc04dda4 --- /dev/null +++ b/src/contexts/ConflictsContext.tsx @@ -0,0 +1,13 @@ +import { Context, Dispatch, createContext, SetStateAction } from "react"; + +interface ConflictsContextType { + conflictsExist: boolean; + setConflictsExist: Dispatch>; +} + + const ConflictsContext: Context = createContext({ + conflictsExist: false, + setConflictsExist: () => {}, + }) + + export default ConflictsContext \ No newline at end of file From 659619e810f5d5cb136164b3d79ac818abdba549 Mon Sep 17 00:00:00 2001 From: R0drig0-P Date: Wed, 13 Nov 2024 23:09:11 +0000 Subject: [PATCH 2/2] only disable button when conflict is severe --- .../exchange/requests/view/cards/RequestCard.tsx | 8 ++++---- src/components/planner/schedules/LessonBox.tsx | 6 +++--- src/contexts/CombinedProvider.tsx | 4 ++-- src/contexts/ConflictsContext.tsx | 14 +++++++------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/components/exchange/requests/view/cards/RequestCard.tsx b/src/components/exchange/requests/view/cards/RequestCard.tsx index 00efd47d..b54a6458 100644 --- a/src/components/exchange/requests/view/cards/RequestCard.tsx +++ b/src/components/exchange/requests/view/cards/RequestCard.tsx @@ -16,7 +16,7 @@ export const RequestCard = ({ }) => { } = useContext(ExchangeRequestCommonContext); const [hovered, setHovered] = useState(false); - const { conflictsExist } = useContext(ConflictsContext); + const { conflictsSeverity } = useContext(ConflictsContext); useEffect(() => { if (chosenRequest?.id !== request.id) { @@ -107,9 +107,9 @@ export const RequestCard = ({ }) => {
diff --git a/src/components/planner/schedules/LessonBox.tsx b/src/components/planner/schedules/LessonBox.tsx index f8ce8b91..3bf2aec4 100644 --- a/src/components/planner/schedules/LessonBox.tsx +++ b/src/components/planner/schedules/LessonBox.tsx @@ -41,7 +41,7 @@ const LessonBox = ({ const [isHovered, setIsHovered] = useState(false) const [conflict, setConflict] = useState(conflicts[slotInfo.id]); const hasConflict = conflict?.conflictingClasses?.length > 1; - const { setConflictsExist } = useContext(ConflictsContext); + const { setConflictsSeverity } = useContext(ConflictsContext); // Needs to change the entry with the id of this lesson to contain the correct ConflictInfo when the classes change useEffect(() => { @@ -75,8 +75,8 @@ const LessonBox = ({ }, [classInfo, classes]); useEffect(() => { - setConflictsExist(hasConflict); - },[hasConflict]); + setConflictsSeverity(conflict?.severe); + }, [hasConflict]); const showConflicts = () => { setConflictsShown(true) diff --git a/src/contexts/CombinedProvider.tsx b/src/contexts/CombinedProvider.tsx index ed2dfc56..f7321ae7 100644 --- a/src/contexts/CombinedProvider.tsx +++ b/src/contexts/CombinedProvider.tsx @@ -29,7 +29,7 @@ const CombinedProvider = ({ children }: Props) => { const [selectedOption, setSelectedOptionState] = useState(StorageAPI.getSelectedOptionStorage()); const { signedIn } = useSession(); - const [conflictsExist, setConflictsExist] = useState(false); + const [conflictsSeverity, setConflictsSeverity] = useState(0); const setMultipleOptions = (newMultipleOptions: MultipleOptions | ((prevMultipleOptions: MultipleOptions) => MultipleOptions)) => { if (newMultipleOptions instanceof Function) @@ -61,7 +61,7 @@ const CombinedProvider = ({ children }: Props) => { } }> - + {children} diff --git a/src/contexts/ConflictsContext.tsx b/src/contexts/ConflictsContext.tsx index bc04dda4..60fc5bca 100644 --- a/src/contexts/ConflictsContext.tsx +++ b/src/contexts/ConflictsContext.tsx @@ -1,13 +1,13 @@ import { Context, Dispatch, createContext, SetStateAction } from "react"; interface ConflictsContextType { - conflictsExist: boolean; - setConflictsExist: Dispatch>; + conflictsSeverity: boolean; + setConflictsSeverity: Dispatch>; } - const ConflictsContext: Context = createContext({ - conflictsExist: false, - setConflictsExist: () => {}, - }) +const ConflictsContext: Context = createContext({ + conflictsSeverity: false, + setConflictsSeverity: () => { }, +}) - export default ConflictsContext \ No newline at end of file +export default ConflictsContext \ No newline at end of file