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

feat(new-primary-school): Update new school page to use updateOnSelect #17612

Merged
merged 11 commits into from
Jan 24, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class QualityPhotoResolver {
resolveDataUri(
@Parent() { hasQualityPhoto }: QualityPhoto,
@CurrentUser() user: User,
): Promise<String | null> {
): Promise<string | null> {
return hasQualityPhoto
? this.drivingLicenseService.getQualityPhotoUri(user.authorization)
: Promise.resolve(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class QualitySignatureResolver {
resolveDataUri(
@Parent() { hasQualitySignature }: QualitySignature,
@CurrentUser() user: User,
): Promise<String | null> {
): Promise<string | null> {
return hasQualitySignature
? this.drivingLicenseService.getQualitySignatureUri(user.authorization)
: Promise.resolve(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
buildAsyncSelectField,
buildHiddenInputWithWatchedValue,
buildMultiField,
buildSubSection,
coreErrorMessages,
Expand All @@ -18,11 +17,11 @@ export const newSchoolSubSection = buildSubSection({
title: newPrimarySchoolMessages.primarySchool.newSchoolSubSectionTitle,
children: [
buildMultiField({
id: 'school',
id: 'newSchool',
title: newPrimarySchoolMessages.primarySchool.newSchoolSubSectionTitle,
children: [
buildAsyncSelectField({
id: 'schools.newSchool.municipality',
id: 'newSchool.municipality',
title: newPrimarySchoolMessages.shared.municipality,
placeholder: newPrimarySchoolMessages.shared.municipalityPlaceholder,
loadingError: coreErrorMessages.failedDataProvider,
Expand All @@ -42,12 +41,13 @@ export const newSchoolSubSection = buildSubSection({
},
}),
buildAsyncSelectField({
id: 'schools.newSchool.school',
id: 'newSchool.school',
title: newPrimarySchoolMessages.shared.school,
placeholder: newPrimarySchoolMessages.shared.schoolPlaceholder,
loadingError: coreErrorMessages.failedDataProvider,
dataTestId: 'new-school-school',
loadOptions: async ({ application, apolloClient }) => {
updateOnSelect: ['newSchool.municipality'],
loadOptions: async ({ application, apolloClient, selectedValue }) => {
const { schoolMunicipality } = getApplicationAnswers(
application.answers,
)
Expand All @@ -62,7 +62,9 @@ export const newSchoolSubSection = buildSubSection({

return (
data?.friggSchoolsByMunicipality
?.find(({ name }) => name === schoolMunicipality)
?.find(
({ name }) => name === (selectedValue || schoolMunicipality),
)
?.children?.filter((school) =>
school.gradeLevels?.includes(childGradeLevel),
)
Expand All @@ -73,20 +75,11 @@ export const newSchoolSubSection = buildSubSection({
)
},
condition: (answers) => {
const { schoolMunicipality, newSchoolHiddenInput } =
getApplicationAnswers(answers)
const { schoolMunicipality } = getApplicationAnswers(answers)

return (
!!schoolMunicipality &&
schoolMunicipality === newSchoolHiddenInput
)
return !!schoolMunicipality
},
}),
buildHiddenInputWithWatchedValue({
// Needed to trigger an update on loadOptions in the async select above
id: 'schools.newSchool.hiddenInput',
watchValue: 'schools.newSchool.municipality',
}),
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ export const dataSchema = z.object({
path: ['transferOfLegalDomicile', 'postalCode'],
},
),
schools: z.object({
newSchool: z.object({
municipality: z.string(),
school: z.string(),
}),
newSchool: z.object({
municipality: z.string(),
school: z.string(),
}),
siblings: z
.array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,10 @@ export const getApplicationAnswers = (answers: Application['answers']) => {

const schoolMunicipality = getValueViaPath(
answers,
'schools.newSchool.municipality',
'newSchool.municipality',
) as string

const selectedSchool = getValueViaPath(
answers,
'schools.newSchool.school',
) as string

const newSchoolHiddenInput = getValueViaPath(
answers,
'schools.newSchool.hiddenInput',
) as string
const selectedSchool = getValueViaPath(answers, 'newSchool.school') as string

return {
applicationType,
Expand Down Expand Up @@ -228,7 +220,6 @@ export const getApplicationAnswers = (answers: Application['answers']) => {
startDate,
schoolMunicipality,
selectedSchool,
newSchoolHiddenInput,
}
}

Expand Down
Loading