Skip to content

Commit

Permalink
missing concentration message appears conditionally and abstracted co…
Browse files Browse the repository at this point in the history
…nvertToOptionObjects method
  • Loading branch information
23langloisj committed Feb 2, 2025
1 parent e9f3394 commit febd2cd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/major/major.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class MajorService {

const isValidConcentrationName =
concentrations.includes(concentrationName) ||
concentrationName.toLowerCase() === "undecided";
concentrationName === "Undecided";

if (!isValidConcentrationName) {
this.logger.debug(
Expand Down
40 changes: 18 additions & 22 deletions packages/common/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { OptionObject } from "./types";

const UNDECIDED_OPTION: OptionObject = {
label: "Undecided",
value: "Undecided",
};

/** Does the given password satisfy our minimum criteria for strength? */
export const isStrongPassword = (password: string): boolean => {
const containsLettersAndNumbersRegex = /^(?=.*[a-zA-Z])(?=.*[0-9])/;
Expand Down Expand Up @@ -33,32 +38,23 @@ export const majorOptionObjectComparator = (
return majorNameComparator(a.value.toString(), b.value.toString());
};

/**
* Converts a list of strings or numbers into a list of option objects for the
* Select component, including an "Undecided" option.
*/
export const convertToOptionObjectsIncludingUndecided = (
options: (string | number)[]
): OptionObject[] => {
const optionObjects = convertToOptionObjects(options);
optionObjects.unshift({
label: "Undecided",
value: "Undecided",
});
return optionObjects;
};

/**
* Converts a list of strings or numbers into a list of option objects for the
* Select component.
*
* IncludeUndecided: optional parameter specifying whether to include\
* "Undecided" as an option
*/
export const convertToOptionObjects = (
options: (string | number)[]
options: (string | number)[],
includeUndecided = false
): OptionObject[] => {
return options.map((option) => {
return {
label: option,
value: option,
};
});
const optionObjects = options.map((option) => ({
label: option,
value: option,
}));
if (includeUndecided) {
optionObjects.unshift(UNDECIDED_OPTION);
}
return optionObjects;
};
6 changes: 3 additions & 3 deletions packages/frontend/components/Plan/AddPlanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
CreatePlanDtoWithoutSchedule,
PlanModel,
convertToOptionObjects,
convertToOptionObjectsIncludingUndecided,
} from "@graduate/common";
import { useRouter } from "next/router";
import { Dispatch, SetStateAction, useContext, useState } from "react";
Expand Down Expand Up @@ -319,8 +318,9 @@ export const AddPlanModal: React.FC<AddPlanModalProps> = ({
label="Concentrations"
name="concentration"
placeholder="Select a Concentration"
options={convertToOptionObjectsIncludingUndecided(
majorConcentrations.concentrations
options={convertToOptionObjects(
majorConcentrations.concentrations,
true
)}
control={control}
rules={{
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/components/Plan/EditPlanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
PlanModel,
UpdatePlanDto,
convertToOptionObjects,
convertToOptionObjectsIncludingUndecided,
} from "@graduate/common";
import { useRouter } from "next/router";
import { useCallback, useContext, useEffect, useState } from "react";
Expand Down Expand Up @@ -311,8 +310,9 @@ export const EditPlanModal: React.FC<EditPlanModalProps> = ({ plan }) => {
label="Concentrations"
name="concentration"
placeholder="Select a Concentration"
options={convertToOptionObjectsIncludingUndecided(
majorConcentrations.concentrations
options={convertToOptionObjects(
majorConcentrations.concentrations,
true
)}
control={control}
rules={{
Expand Down
4 changes: 3 additions & 1 deletion packages/frontend/components/Sidebar/SidebarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ const SidebarContainer: React.FC<PropsWithChildren<SidebarContainerProps>> = ({
</Text>
)}
</Box>
<ConcentrationDropdownWarning />
{subtitle === "Concentration Undecided" && (
<ConcentrationDropdownWarning />
)}
{renderDropdownWarning && <DropdownWarning />}
{creditsTaken !== undefined && (
<Flex mb="sm" alignItems="baseline" columnGap="xs">
Expand Down

0 comments on commit febd2cd

Please sign in to comment.