diff --git a/packages/common/src/api-dtos.ts b/packages/common/src/api-dtos.ts index 6aebaed7..b1966e65 100644 --- a/packages/common/src/api-dtos.ts +++ b/packages/common/src/api-dtos.ts @@ -25,6 +25,10 @@ export class CreatePlanDtoWithoutSchedule { @IsOptional() major?: string; + @IsString() + @IsOptional() + minor?: string; + @IsString() @IsOptional() concentration?: string; @@ -58,6 +62,10 @@ export class UpdatePlanDto { @IsString() major?: string; + @IsOptional() + @IsString() + minor?: string; + @IsOptional() @IsString() concentration?: string; @@ -122,6 +130,10 @@ export class UpdateStudentDto { @IsString() major?: string; + @IsOptional() + @IsString() + minor?: string; + @IsOptional() @IsString() coopCycle?: string; @@ -173,6 +185,9 @@ export class OnboardStudentDto { @IsString() major: string; + @IsString() + minor: string; + @IsString() coopCycle: string; diff --git a/packages/common/src/api-response-types.ts b/packages/common/src/api-response-types.ts index 3e29703a..549178b7 100644 --- a/packages/common/src/api-response-types.ts +++ b/packages/common/src/api-response-types.ts @@ -20,7 +20,7 @@ export class PlanModel { catalogYear: number; createdAt: Date; updatedAt: Date; - minor?: string | undefined; + minor?: string; } export class GetPlanResponse extends PlanModel {} diff --git a/packages/frontend/components/Plan/AddPlanModal.tsx b/packages/frontend/components/Plan/AddPlanModal.tsx index fbda5d99..852153f8 100644 --- a/packages/frontend/components/Plan/AddPlanModal.tsx +++ b/packages/frontend/components/Plan/AddPlanModal.tsx @@ -32,11 +32,13 @@ import { //useSupportedMinors, USE_STUDENT_WITH_PLANS_SWR_KEY, useStudentWithPlans, + useSupportedMinors, } from "../../hooks"; import { cleanDndIdsFromStudent, createEmptySchedule, extractSupportedMajorOptions, + extractSupportedMinorOptions, extractSupportedMajorYears, handleApiClientError, noLeadOrTrailWhitespacePattern, @@ -62,6 +64,8 @@ export const AddPlanModal: React.FC = ({ const { onOpen, onClose: onCloseDisplay, isOpen } = useDisclosure(); const { supportedMajorsData, error: supportedMajorsError } = useSupportedMajors(); + const { supportedMinorsData, error: supportedMinorsError } = + useSupportedMinors(); //const { supportedMinorsData, error: supportedMinorsError } = //useSupportedMinors(); const { @@ -77,6 +81,7 @@ export const AddPlanModal: React.FC = ({ shouldFocusError: true, }); const [isNoMajorSelected, setIsNoMajorSelected] = useState(false); + const [isNoMinorSelected, setIsNoMinorSelected] = useState(false); const { isGuest } = useContext(IsGuestContext); const { student } = useStudentWithPlans(); @@ -87,6 +92,9 @@ export const AddPlanModal: React.FC = ({ if (supportedMajorsError) { handleApiClientError(supportedMajorsError, router); } + if (supportedMinorsError) { + handleApiClientError(supportedMinorsError, router); + } //if (supportedMinorsError) { //handleApiClientError(supportedMinorsError, router); //} @@ -97,6 +105,7 @@ export const AddPlanModal: React.FC = ({ name: payload.name, catalogYear: isNoMajorSelected ? undefined : payload.catalogYear, major: isNoMajorSelected ? undefined : payload.major, + minor: isNoMinorSelected ? undefined : payload.minor, concentration: isNoMajorSelected ? undefined : payload.concentration, schedule, }; @@ -148,6 +157,7 @@ export const AddPlanModal: React.FC = ({ const title = watch("name"); const catalogYear = watch("catalogYear"); const majorName = watch("major"); + const minorName = watch("minor"); const concentration = watch("concentration"); const agreeToBetaMajor = watch("agreeToBetaMajor"); @@ -314,6 +324,20 @@ export const AddPlanModal: React.FC = ({ isSearchable useFuzzySearch /> + Can't find your major / minor? diff --git a/packages/frontend/components/Sidebar/Sidebar.tsx b/packages/frontend/components/Sidebar/Sidebar.tsx index 4d0a66de..5a78b659 100644 --- a/packages/frontend/components/Sidebar/Sidebar.tsx +++ b/packages/frontend/components/Sidebar/Sidebar.tsx @@ -82,9 +82,13 @@ const Sidebar: React.FC = memo( const concentration = major?.concentrations?.concentrationOptions.find( (concentration) => concentration.title === selectedPlan.concentration ); - const minorResponse = useMinor(2022, "Data Science, Minor"); - console.log("minor response"); - console.log(minorResponse.minor); + + const minorResponse = useMinor( + selectedPlan.catalogYear, + selectedPlan.minor + ); + //console.log("minor response"); + //console.log(minorResponse.minor); const workerRef = useRef(); @@ -281,7 +285,7 @@ const Sidebar: React.FC = memo( /> )} - {minorCourses && ( + {minorResponse.minor && ( <> We have a minor {minorResponse.minor?.requirementSections.map( diff --git a/packages/frontend/utils/plan/supportedMajors.ts b/packages/frontend/utils/plan/supportedMajors.ts index 86f497e3..bb8f2e3a 100644 --- a/packages/frontend/utils/plan/supportedMajors.ts +++ b/packages/frontend/utils/plan/supportedMajors.ts @@ -1,5 +1,6 @@ import { GetSupportedMajorsResponse, + GetSupportedMinorsResponse, OptionObject, majorNameComparator, majorOptionObjectComparator, @@ -30,6 +31,35 @@ export const extractSupportedMajorNames = ( return Object.keys(majorMap ?? {}).sort(majorNameComparator); }; +/** + * Returns a list of option objects for supported majors (label, value) for the + * given catalog year. + * + * @param catalogYear Catalog year to search for + * @param supportedMajorsData Supported major data to extract from + * @returns A list of the supported major option objects for + * the given catalog year + */ +export const extractSupportedMinorOptions = ( + catalogYear?: number, + supportedMinorsData?: GetSupportedMinorsResponse +): OptionObject[] => { + if (!catalogYear) { + return []; + } + const minorMap = supportedMinorsData?.supportedMinors[catalogYear]; + const minorList = Object.keys(minorMap ?? {}) + .map((minorName) => { + return { + label: minorName, + value: minorName, + }; + }) + .sort(majorOptionObjectComparator); + minorList.unshift({ label: "None", value: "" }); + return minorList; +}; + /** * Returns a list of option objects for supported majors (label, value) for the * given catalog year.