Skip to content

Commit

Permalink
coop in last year, not just year 4
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcarvajal committed Feb 6, 2025
1 parent 499a68d commit f56972f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 41 deletions.
76 changes: 41 additions & 35 deletions packages/frontend/components/Plan/Plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ScheduleYear2,
SeasonEnum,
} from "@graduate/common";
import { useState } from "react";
import { useState, createContext } from "react";
import { addClassesToTerm, removeYearFromPlan } from "../../utils";
import { removeCourseFromTerm } from "../../utils";
import { ScheduleYear } from "./ScheduleYear";
Expand All @@ -27,6 +27,7 @@ interface PlanProps {
mutateStudentWithUpdatedPlan: (updatedPlan: PlanModel<string>) => void;
}

export const TotalYearsContext = createContext<number | null>(null);
export const Plan: React.FC<PlanProps> = ({
plan,
mutateStudentWithUpdatedPlan,
Expand All @@ -35,6 +36,7 @@ export const Plan: React.FC<PlanProps> = ({
setIsRemove,
}) => {
const [expandedYears, setExpandedYears] = useState<Set<number>>(new Set());
const totalYears = plan.schedule.years.length;

const toggleExpanded = (year: ScheduleYear2<unknown>) => {
if (expandedYears.has(year.year)) {
Expand Down Expand Up @@ -109,41 +111,45 @@ export const Plan: React.FC<PlanProps> = ({
};

return (
<Flex direction="column" rowGap="sm">
<Flex flexDirection="column" rowGap="4xs" ref={setNodeRef}>
{plan.schedule.years.map((scheduleYear) => {
const isExpanded = expandedYears.has(scheduleYear.year);
<TotalYearsContext.Provider value={totalYears}>
<Flex direction="column" rowGap="sm">
<Flex flexDirection="column" rowGap="4xs" ref={setNodeRef}>
{plan.schedule.years.map((scheduleYear) => {
const isExpanded = expandedYears.has(scheduleYear.year);

return (
<Flex key={scheduleYear.year} flexDirection="column">
<ScheduleYear
catalogYear={plan.catalogYear}
yearCoReqError={coReqErr?.years.find(
(year) => year.year == scheduleYear.year
)}
yearPreReqError={preReqErr?.years.find(
(year) => year.year == scheduleYear.year
)}
scheduleYear={scheduleYear}
isExpanded={isExpanded}
toggleExpanded={() => toggleExpanded(scheduleYear)}
addClassesToTermInCurrPlan={addClassesToTermInCurrPlan}
removeCourseFromTermInCurrPlan={removeCourseFromTermInCurrPlan}
removeYearFromCurrPlan={() =>
removeYearFromCurrPlan(scheduleYear.year)
}
setIsRemove={setIsRemove}
/>
</Flex>
);
})}
return (
<Flex key={scheduleYear.year} flexDirection="column">
<ScheduleYear
catalogYear={plan.catalogYear}
yearCoReqError={coReqErr?.years.find(
(year) => year.year == scheduleYear.year
)}
yearPreReqError={preReqErr?.years.find(
(year) => year.year == scheduleYear.year
)}
scheduleYear={scheduleYear}
isExpanded={isExpanded}
toggleExpanded={() => toggleExpanded(scheduleYear)}
addClassesToTermInCurrPlan={addClassesToTermInCurrPlan}
removeCourseFromTermInCurrPlan={
removeCourseFromTermInCurrPlan
}
removeYearFromCurrPlan={() =>
removeYearFromCurrPlan(scheduleYear.year)
}
setIsRemove={setIsRemove}
/>
</Flex>
);
})}
</Flex>
<Flex>
<AddYearButton
plan={plan}
mutateStudentWithUpdatedPlan={mutateStudentWithUpdatedPlan}
/>
</Flex>
</Flex>
<Flex>
<AddYearButton
plan={plan}
mutateStudentWithUpdatedPlan={mutateStudentWithUpdatedPlan}
/>
</Flex>
</Flex>
</TotalYearsContext.Provider>
);
};
11 changes: 7 additions & 4 deletions packages/frontend/components/Plan/ReqErrorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
INEUReqError,
ScheduleCourse2,
ScheduleTerm2,
SeasonEnum,
} from "@graduate/common";
import { HelperToolTip } from "../Help";
import {
Expand All @@ -31,8 +32,8 @@ import {
} from "../../utils";
import { useFetchCourse } from "../../hooks";
import { GraduateToolTip } from "../GraduateTooltip";
import { SetStateAction } from "react";
import { ErrorModalError } from "./";
import { SetStateAction, useContext } from "react";
import { ErrorModalError, TotalYearsContext } from "./";

interface ReqErrorModalProps {
setHovered: (isHovered: SetStateAction<boolean>) => void;
Expand All @@ -51,14 +52,16 @@ export const ReqErrorModal: React.FC<ReqErrorModalProps> = ({
}) => {
const { isOpen, onOpen, onClose } = useDisclosure();

const totalYears = useContext(TotalYearsContext);
const isFinalYear = term && parseInt(term.id[0]) === totalYears;
const coopErr =
course.name === COOP_TITLE &&
term !== undefined &&
(term.id === FALL_1 || term.id === SPRING_4);
(term.id === FALL_1 || (isFinalYear && term.season == SeasonEnum.SP));
let msg = GENERIC_ERROR_MSG;
if (coopErr && term.id === FALL_1) {
msg = FALL_1_COOP_ERROR_MSG;
} else if (coopErr && term.id === SPRING_4) {
} else if (coopErr) {
msg = SPRING_4_COOP_ERROR_MSG;
}
return (
Expand Down
16 changes: 14 additions & 2 deletions packages/frontend/components/ScheduleCourse/ScheduleCourse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import {
ScheduleTerm2,
SeasonEnum,
} from "@graduate/common";
import { forwardRef, PropsWithChildren, useEffect, useState } from "react";
import {
forwardRef,
PropsWithChildren,
useEffect,
useState,
useContext,
} from "react";
import {
COOP_TITLE,
DELETE_COURSE_AREA_DND_ID,
Expand All @@ -24,6 +30,7 @@ import { COOP_BLOCK } from "../Sidebar";
import { CourseDragIcon } from "./CourseDragIcon";
import { CourseTrashButton } from "./CourseTrashButton";
import { GraduateToolTip } from "../GraduateTooltip";
import { TotalYearsContext } from "../Plan/Plan";

interface DraggableScheduleCourseProps {
scheduleCourse: ScheduleCourse2<string>;
Expand Down Expand Up @@ -210,12 +217,17 @@ const ScheduleCourse = forwardRef<HTMLElement | null, ScheduleCourseProps>(
) => {
const [hovered, setHovered] = useState(false);
const isValidRemove = isRemove && !isFromSidebar;
const totalYears = useContext(TotalYearsContext);
const isFinalYear =
scheduleTerm && parseInt(scheduleTerm.id[0]) === totalYears;

const isCourseError =
coReqErr !== undefined ||
preReqErr !== undefined ||
(scheduleCourse.name === COOP_TITLE &&
scheduleTerm !== undefined &&
(scheduleTerm.id === FALL_1 || scheduleTerm.id === SPRING_4));
(scheduleTerm.id === FALL_1 ||
(isFinalYear && scheduleTerm.season === SeasonEnum.SP)));

/*
This component uses some plain HTML elements instead of Chakra
Expand Down

0 comments on commit f56972f

Please sign in to comment.