Skip to content

Commit

Permalink
create plan with minor works
Browse files Browse the repository at this point in the history
  • Loading branch information
denniwang committed Dec 3, 2024
1 parent b18ad0c commit 6393f2c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
15 changes: 15 additions & 0 deletions packages/common/src/api-dtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export class CreatePlanDtoWithoutSchedule {
@IsOptional()
major?: string;

@IsString()
@IsOptional()
minor?: string;

@IsString()
@IsOptional()
concentration?: string;
Expand Down Expand Up @@ -58,6 +62,10 @@ export class UpdatePlanDto {
@IsString()
major?: string;

@IsOptional()
@IsString()
minor?: string;

@IsOptional()
@IsString()
concentration?: string;
Expand Down Expand Up @@ -122,6 +130,10 @@ export class UpdateStudentDto {
@IsString()
major?: string;

@IsOptional()
@IsString()
minor?: string;

@IsOptional()
@IsString()
coopCycle?: string;
Expand Down Expand Up @@ -173,6 +185,9 @@ export class OnboardStudentDto {
@IsString()
major: string;

@IsString()
minor: string;

@IsString()
coopCycle: string;

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/api-response-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class PlanModel<T> {
catalogYear: number;
createdAt: Date;
updatedAt: Date;
minor?: string | undefined;
minor?: string;
}

export class GetPlanResponse extends PlanModel<null> {}
Expand Down
24 changes: 24 additions & 0 deletions packages/frontend/components/Plan/AddPlanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ import {
//useSupportedMinors,
USE_STUDENT_WITH_PLANS_SWR_KEY,
useStudentWithPlans,
useSupportedMinors,
} from "../../hooks";
import {
cleanDndIdsFromStudent,
createEmptySchedule,
extractSupportedMajorOptions,
extractSupportedMinorOptions,
extractSupportedMajorYears,
handleApiClientError,
noLeadOrTrailWhitespacePattern,
Expand All @@ -62,6 +64,8 @@ export const AddPlanModal: React.FC<AddPlanModalProps> = ({
const { onOpen, onClose: onCloseDisplay, isOpen } = useDisclosure();
const { supportedMajorsData, error: supportedMajorsError } =
useSupportedMajors();
const { supportedMinorsData, error: supportedMinorsError } =
useSupportedMinors();
//const { supportedMinorsData, error: supportedMinorsError } =
//useSupportedMinors();
const {
Expand All @@ -77,6 +81,7 @@ export const AddPlanModal: React.FC<AddPlanModalProps> = ({
shouldFocusError: true,
});
const [isNoMajorSelected, setIsNoMajorSelected] = useState(false);
const [isNoMinorSelected, setIsNoMinorSelected] = useState(false);

Check failure on line 84 in packages/frontend/components/Plan/AddPlanModal.tsx

View workflow job for this annotation

GitHub Actions / Run linting for all packages

'setIsNoMinorSelected' is assigned a value but never used. Allowed unused vars must match /^_/u
const { isGuest } = useContext(IsGuestContext);
const { student } = useStudentWithPlans();

Expand All @@ -87,6 +92,9 @@ export const AddPlanModal: React.FC<AddPlanModalProps> = ({
if (supportedMajorsError) {
handleApiClientError(supportedMajorsError, router);
}
if (supportedMinorsError) {
handleApiClientError(supportedMinorsError, router);
}
//if (supportedMinorsError) {
//handleApiClientError(supportedMinorsError, router);
//}
Expand All @@ -97,6 +105,7 @@ export const AddPlanModal: React.FC<AddPlanModalProps> = ({
name: payload.name,
catalogYear: isNoMajorSelected ? undefined : payload.catalogYear,
major: isNoMajorSelected ? undefined : payload.major,
minor: isNoMinorSelected ? undefined : payload.minor,
concentration: isNoMajorSelected ? undefined : payload.concentration,
schedule,
};
Expand Down Expand Up @@ -148,6 +157,7 @@ export const AddPlanModal: React.FC<AddPlanModalProps> = ({
const title = watch("name");
const catalogYear = watch("catalogYear");
const majorName = watch("major");
const minorName = watch("minor");

Check failure on line 160 in packages/frontend/components/Plan/AddPlanModal.tsx

View workflow job for this annotation

GitHub Actions / Run linting for all packages

'minorName' is assigned a value but never used. Allowed unused vars must match /^_/u
const concentration = watch("concentration");
const agreeToBetaMajor = watch("agreeToBetaMajor");

Expand Down Expand Up @@ -314,6 +324,20 @@ export const AddPlanModal: React.FC<AddPlanModalProps> = ({
isSearchable
useFuzzySearch
/>
<PlanSelect
label="Minor"
placeholder="Select a Minor"
name="minor"
control={control}
options={extractSupportedMinorOptions(
catalogYear,
supportedMinorsData
)}
//rules={{ required: "Minor is required." }}
isDisabled={!catalogYear}
isSearchable
useFuzzySearch
/>
<Flex align="center">
<Text size="xs" mr="xs">
Can&apos;t find your major / minor?
Expand Down
12 changes: 8 additions & 4 deletions packages/frontend/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ const Sidebar: React.FC<SidebarProps> = 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<Worker>();

Expand Down Expand Up @@ -281,7 +285,7 @@ const Sidebar: React.FC<SidebarProps> = memo(
/>
)}

{minorCourses && (
{minorResponse.minor && (
<>
<Text>We have a minor </Text>
{minorResponse.minor?.requirementSections.map(
Expand Down
30 changes: 30 additions & 0 deletions packages/frontend/utils/plan/supportedMajors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
GetSupportedMajorsResponse,
GetSupportedMinorsResponse,
OptionObject,
majorNameComparator,
majorOptionObjectComparator,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6393f2c

Please sign in to comment.