Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(secondary school): More fixes + stop user if no programs are open for admission + handle if only 1 school or program available #17522

Merged
merged 9 commits into from
Jan 20, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,25 @@ export class SecondarySchoolService extends BaseTemplateApiService {
async getSchools({
auth,
}: TemplateApiModuleActionProps): Promise<SecondarySchool[]> {
return this.secondarySchoolClient.getSchools(auth)
const studentInfo = await this.secondarySchoolClient.getStudentInfo(auth)
const schools = await this.secondarySchoolClient.getSchools(auth)

const schoolIsOpenForAdmission = schools.find((x) =>
studentInfo?.isFreshman
? x.isOpenForAdmissionFreshman
: x.isOpenForAdmissionFreshman || x.isOpenForAdmissionGeneral,
)
if (!schoolIsOpenForAdmission) {
throw new TemplateApiError(
{
title: error.errorNoSchoolOpenForAdmissionTitle,
summary: error.errorNoSchoolOpenForAdmissionDescription,
},
400,
)
}

return schools
}

async validateCanCreate({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const getCleanSchoolSelection = (
): ApplicationSelectionSchool[] => {
const result: ApplicationSelectionSchool[] = []

let schoolPriority = 0
let schoolPriority = 1
johannaagma marked this conversation as resolved.
Show resolved Hide resolved

const selectionKeys = ['first', 'second', 'third']
selectionKeys.forEach((selectionKey) => {
Expand All @@ -134,11 +134,11 @@ export const getCleanSchoolSelection = (
schoolId: selectionItem.school.id,
programs: [
{
priority: 0,
priority: 1,
programId: selectionItem.firstProgram.id,
},
{
priority: 1,
priority: 2,
programId: selectionItem.secondProgram?.include
? selectionItem.secondProgram.id || ''
: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ApplicationType,
getTranslatedProgram,
Language,
LANGUAGE_CODE_DANISH,
Program,
SecondarySchool,
} from '../../utils'
Expand All @@ -34,6 +35,7 @@ export const SelectionItem: FC<FieldBaseProps & SelectionItemProps> = (
const { application, setFieldLoadingState } = props
const { setValue, watch } = useFormContext()
const [isLoadingPrograms, setIsLoadingPrograms] = useState<boolean>(false)
const [showSecondProgram, setShowSecondProgram] = useState<boolean>(true)

const isFreshman =
getValueViaPath<ApplicationType>(
Expand Down Expand Up @@ -256,8 +258,10 @@ export const SelectionItem: FC<FieldBaseProps & SelectionItemProps> = (

// default set include=true for second program if freshman
useEffect(() => {
setValue(`${props.field.id}.secondProgram.include`, isFreshman)
}, [isFreshman, props.field.id, setValue])
const showSecondProgram = isFreshman && programOptions.length !== 1
setValue(`${props.field.id}.secondProgram.include`, showSecondProgram)
setShowSecondProgram(showSecondProgram)
}, [isFreshman, programOptions.length, props.field.id, setValue])

useEffect(() => {
setFieldLoadingState?.(isLoadingPrograms)
Expand All @@ -276,7 +280,13 @@ export const SelectionItem: FC<FieldBaseProps & SelectionItemProps> = (
backgroundColor="blue"
required
options={(schoolOptions || [])
.filter((x) => !otherSchoolIds.includes(x.id))
.filter(
(x) =>
(isFreshman
? x.isOpenForAdmissionFreshman
: x.isOpenForAdmissionGeneral) &&
!otherSchoolIds.includes(x.id),
)
.map((school) => {
return {
label: school.name,
Expand Down Expand Up @@ -319,7 +329,7 @@ export const SelectionItem: FC<FieldBaseProps & SelectionItemProps> = (
/>
</Box>

{isFreshman && (
{showSecondProgram && (
<Box marginTop={2}>
<Controller
name={`${props.field.id}.secondProgram.id`}
Expand Down Expand Up @@ -397,7 +407,7 @@ export const SelectionItem: FC<FieldBaseProps & SelectionItemProps> = (
isDisabled={isLoadingPrograms}
value={selectedNordicLanguage}
options={nordicLanguageOptions
.filter((x) => x.code !== 'da')
.filter((x) => x.code !== LANGUAGE_CODE_DANISH)
.map((language) => {
return {
label: language.name,
Expand Down
Loading
Loading