diff --git a/packages/frontend/components/Form/Select.tsx b/packages/frontend/components/Form/Select.tsx index 223f5e22b..1e1166935 100644 --- a/packages/frontend/components/Form/Select.tsx +++ b/packages/frontend/components/Form/Select.tsx @@ -25,6 +25,7 @@ type PlanSelectProps = { /** Are the field values numbers. */ isNumeric?: boolean; isSearchable?: boolean; + isDisabled?: boolean; /** The default text shown in the input box. */ placeholder?: string; /** Fuzzy options to use */ @@ -41,6 +42,7 @@ export const PlanSelect: React.FC = ({ rules, isNumeric, isSearchable, + isDisabled, placeholder, useFuzzySearch, }) => { @@ -107,6 +109,7 @@ export const PlanSelect: React.FC = ({ onChange={onChange} value={selectedOption} isSearchable={isSearchable} + isDisabled={isDisabled} placeholder={placeholder} filterOption={filterOptions} {...fieldRest} diff --git a/packages/frontend/components/Plan/AddPlanModal.tsx b/packages/frontend/components/Plan/AddPlanModal.tsx index 7f6163847..57131aa29 100644 --- a/packages/frontend/components/Plan/AddPlanModal.tsx +++ b/packages/frontend/components/Plan/AddPlanModal.tsx @@ -41,7 +41,6 @@ import { import { BlueButton } from "../Button"; import { PlanInput, PlanSelect } from "../Form"; import { HelperToolTip } from "../Help"; -import { PlanConcentrationsSelect } from "./PlanConcentrationsSelect"; import { IsGuestContext } from "../../pages/_app"; interface AddPlanModalProps { @@ -133,10 +132,30 @@ export const AddPlanModal: React.FC = ({ onCloseDisplay(); }; + const title = watch("name"); const catalogYear = watch("catalogYear"); const majorName = watch("major"); const concentration = watch("concentration"); + const yearSupportedMajors = + supportedMajorsData?.supportedMajors[catalogYear ?? 0]; + + const noConcentrations = { concentrations: [], minRequiredConcentrations: 0 }; + + const majorConcentrations = + yearSupportedMajors?.[majorName ?? ""] ?? noConcentrations; + + const isConcentrationRequired = + majorConcentrations.minRequiredConcentrations > 0; + + const majorHasConcentrations = majorConcentrations.concentrations.length > 0; + + const isValidForm = + title && + catalogYear && + majorName && + (!isConcentrationRequired || concentration); + const noMajorHelperLabel = ( @@ -243,16 +262,24 @@ export const AddPlanModal: React.FC = ({ setValue("concentration", ""); }} rules={{ required: "Major is required." }} - helperText='First select your catalog year. If you still cannot find your major, select "No Major" above.' + isDisabled={!catalogYear} isSearchable useFuzzySearch /> - + {majorHasConcentrations && ( + + )} )} @@ -270,6 +297,7 @@ export const AddPlanModal: React.FC = ({