Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exchange not allowing submission when Schedule has a conflict #339

Open
wants to merge 2 commits into
base: feature/exchange
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/exchange/requests/view/cards/RequestCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -15,6 +16,8 @@ export const RequestCard = ({ }) => {
} = useContext(ExchangeRequestCommonContext);
const [hovered, setHovered] = useState<boolean>(false);

const { conflictsSeverity } = useContext(ConflictsContext);

useEffect(() => {
if (chosenRequest?.id !== request.id) {
setOpen(false);
Expand Down Expand Up @@ -102,7 +105,12 @@ export const RequestCard = ({ }) => {
<label htmlFor="select-all">Selecionar todas</label>
</div>
<form className="flex flex-row gap-2">
<Button type="submit" onClick={submitExchange} className="success-button hover:bg-white">
<Button
type="submit"
onClick={!conflictsSeverity ? submitExchange : () => { }}
className={conflictsSeverity ? "disabled:bg-red-400" : "success-button hover:bg-white"}
disabled={conflictsSeverity}
>
Propôr troca
</Button>
</form>
Expand Down
8 changes: 7 additions & 1 deletion src/components/planner/schedules/LessonBox.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 { setConflictsSeverity } = useContext(ConflictsContext);

// Needs to change the entry with the id of this lesson to contain the correct ConflictInfo when the classes change
useEffect(() => {
Expand Down Expand Up @@ -72,6 +74,10 @@ const LessonBox = ({
setConflict(newConflictInfo);
}, [classInfo, classes]);

useEffect(() => {
setConflictsSeverity(conflict?.severe);
}, [hasConflict]);

const showConflicts = () => {
setConflictsShown(true)
}
Expand Down
7 changes: 6 additions & 1 deletion src/contexts/CombinedProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +29,8 @@ const CombinedProvider = ({ children }: Props) => {
const [selectedOption, setSelectedOptionState] = useState<number>(StorageAPI.getSelectedOptionStorage());
const { signedIn } = useSession();

const [conflictsSeverity, setConflictsSeverity] = useState<number>(0);

const setMultipleOptions = (newMultipleOptions: MultipleOptions | ((prevMultipleOptions: MultipleOptions) => MultipleOptions)) => {
if (newMultipleOptions instanceof Function)
newMultipleOptions = newMultipleOptions(multipleOptions);
Expand Down Expand Up @@ -58,7 +61,9 @@ const CombinedProvider = ({ children }: Props) => {
}
}>
<MultipleOptionsContext.Provider value={{ multipleOptions, setMultipleOptions, selectedOption, setSelectedOption }}>
{children}
<ConflictsContext.Provider value={{ conflictsSeverity, setConflictsSeverity }}>
{children}
</ConflictsContext.Provider>
</MultipleOptionsContext.Provider>
</CourseContext.Provider>
</MajorContext.Provider>
Expand Down
13 changes: 13 additions & 0 deletions src/contexts/ConflictsContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Context, Dispatch, createContext, SetStateAction } from "react";

interface ConflictsContextType {
conflictsSeverity: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although in the CombinedProvider you are passing a number as the severity, here on the context you are still saying that this will be a boolean.

You need to change the type of the variable in the interface and in the createContext call

setConflictsSeverity: Dispatch<SetStateAction<boolean>>;
}

const ConflictsContext: Context<ConflictsContextType> = createContext({
conflictsSeverity: false,
setConflictsSeverity: () => { },
})

export default ConflictsContext