From 683f97ccb479aa3b63e04d40fab7346d212f40a7 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Fri, 21 Jun 2024 13:26:12 +0000 Subject: [PATCH 01/22] Added latest version of clientConfig and latest endpoints from Juni --- .../new-primary-school.service.ts | 10 +- .../src/dataProviders/index.ts | 18 ++ .../src/forms/Prerequisites.ts | 27 +++ .../src/lib/NewPrimarySchoolTemplate.ts | 12 ++ libs/clients/mms/frigg/src/clientConfig.json | 189 +++++++++++++++++- libs/clients/mms/frigg/src/lib/apiProvider.ts | 37 ++-- .../mms/frigg/src/lib/friggClient.service.ts | 35 +++- 7 files changed, 304 insertions(+), 24 deletions(-) diff --git a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts index efec706e766d..0661eb017eb7 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts @@ -19,10 +19,18 @@ export class NewPrimarySchoolService extends BaseTemplateApiService { } async getAllKeyOptions({ auth }: TemplateApiModuleActionProps) { - return await this.friggClientService.getAllKeyOptions(auth, '') + return await this.friggClientService.getAllKeyOptions(auth, undefined) } async getHealth({ auth }: TemplateApiModuleActionProps) { return await this.friggClientService.getHealth(auth) } + + async getUserById({ auth }: TemplateApiModuleActionProps) { + return await this.friggClientService.getUserById(auth) + } + + async getAllSchoolsByMunicipality({ auth }: TemplateApiModuleActionProps) { + return await this.friggClientService.getAllSchoolsByMunicipality(auth) + } } diff --git a/libs/application/templates/new-primary-school/src/dataProviders/index.ts b/libs/application/templates/new-primary-school/src/dataProviders/index.ts index 634d71350a1b..a34a6f036b9a 100644 --- a/libs/application/templates/new-primary-school/src/dataProviders/index.ts +++ b/libs/application/templates/new-primary-school/src/dataProviders/index.ts @@ -14,3 +14,21 @@ export const GetHealthApi = defineTemplateApi({ externalDataId: 'health', namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, }) + +export const GetUserApi = defineTemplateApi({ + action: 'getUserById', + externalDataId: 'userInfo', + namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, +}) + +export const GetSchoolsApi = defineTemplateApi({ + action: 'getAllSchoolsByMunicipality', + externalDataId: 'schools', + namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, +}) + +export const OptionsApi = defineTemplateApi({ + action: 'getAllKeyOptions', + externalDataId: 'KeyOptions', + namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, +}) diff --git a/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts b/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts index ede49c5d1d6f..87e7d653ee58 100644 --- a/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts +++ b/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts @@ -14,6 +14,13 @@ import { UserProfileApi, } from '@island.is/application/types' import { newPrimarySchoolMessages } from '../lib/messages' +import { + GetHealthApi, + GetSchoolsApi, + GetTypesApi, + GetUserApi, + OptionsApi, +} from '../dataProviders' export const Prerequisites: Form = buildForm({ id: 'newPrimarySchoolPrerequisites', @@ -63,6 +70,26 @@ export const Prerequisites: Form = buildForm({ subTitle: newPrimarySchoolMessages.pre.userProfileInformationSubTitle, }), + /* buildDataProviderItem({ + provider: GetTypesApi, + title: 'Type', + }), + buildDataProviderItem({ + provider: GetHealthApi, + title: 'health', + }), + buildDataProviderItem({ + provider: OptionsApi, + title: 'OPtions', + }), */ + /* buildDataProviderItem({ + provider: GetUserApi, + title: 'usr', + }),*/ + /* buildDataProviderItem({ + provider: GetSchoolsApi, + title: 'schools', + }),*/ ], }), ], diff --git a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts index ead983048ca9..e59e4fa0c685 100644 --- a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts +++ b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts @@ -24,6 +24,13 @@ import { Events, ReasonForApplicationOptions, Roles, States } from './constants' import { dataSchema } from './dataSchema' import { newPrimarySchoolMessages, statesMessages } from './messages' import { getApplicationAnswers } from './newPrimarySchoolUtils' +import { + GetHealthApi, + GetSchoolsApi, + GetTypesApi, + GetUserApi, + OptionsApi, +} from '../dataProviders' const NewPrimarySchoolTemplate: ApplicationTemplate< ApplicationContext, @@ -71,6 +78,11 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< ChildrenCustodyInformationApi, NationalRegistryUserApi, UserProfileApi, + /* GetTypesApi, + GetHealthApi, + OptionsApi,*/ + // GetSchoolsApi, + //GetUserApi, ], }, ], diff --git a/libs/clients/mms/frigg/src/clientConfig.json b/libs/clients/mms/frigg/src/clientConfig.json index f671fc3c7bf7..6b74326452bd 100644 --- a/libs/clients/mms/frigg/src/clientConfig.json +++ b/libs/clients/mms/frigg/src/clientConfig.json @@ -28,8 +28,7 @@ } } }, - "tags": ["KeyOptionsManagement"], - "security": [{ "Authorization": [] }] + "tags": ["KeyOptionsManagement"] } }, "/keyOptions/types": { @@ -39,8 +38,7 @@ "description": "Get types.", "parameters": [], "responses": { "200": { "description": "" } }, - "tags": ["KeyOptionsManagement"], - "security": [{ "Authorization": [] }] + "tags": ["KeyOptionsManagement"] } }, "/health": { @@ -49,6 +47,56 @@ "parameters": [], "responses": { "200": { "description": "" } } } + }, + "/schools": { + "get": { + "operationId": "getAllSchoolsByMunicipality", + "summary": "Get all schools.", + "description": "Returns a paginated collection of schools.", + "parameters": [], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { "$ref": "#/components/schemas/OrganizationModel" } + } + } + } + } + }, + "tags": ["SchoolsManagement"], + "security": [{ "Authorization": [] }] + } + }, + "/student/{nationalId}": { + "get": { + "operationId": "getUserBySourcedId", + "summary": "Get user by nationalId", + "description": "Get user by Id. ", + "parameters": [ + { + "name": "nationalId", + "required": true, + "in": "path", + "schema": { "type": "string" } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/UserModel" } + } + } + } + }, + "tags": ["UsersManagement"], + "security": [{ "Authorization": [] }] + } } }, "info": { @@ -119,6 +167,139 @@ } }, "required": ["type", "options"] + }, + "OrganizationModel": { + "type": "object", + "properties": { + "id": { "type": "string" }, + "nationalId": { "type": "string" }, + "name": { "type": "string" }, + "type": { + "type": "string", + "enum": ["municipality", "national", "school"] + }, + "gradeLevels": { "type": "array", "items": { "type": "string" } }, + "parent": { + "nullable": true, + "allOf": [{ "$ref": "#/components/schemas/OrganizationModel" }] + }, + "children": { + "nullable": true, + "type": "array", + "items": { "$ref": "#/components/schemas/OrganizationModel" } + } + }, + "required": [ + "id", + "nationalId", + "name", + "type", + "gradeLevels", + "parent", + "children" + ] + }, + "AddressModel": { + "type": "object", + "properties": { + "id": { "type": "string" }, + "street": { "type": "string" }, + "municipality": { "type": "object", "nullable": true }, + "zip": { "type": "string" }, + "country": { "type": "object", "nullable": true } + }, + "required": ["id", "street", "municipality", "zip", "country"] + }, + "MembershipModel": { + "type": "object", + "properties": { + "id": { "type": "string" }, + "role": { + "type": "string", + "enum": [ + "admin", + "guardian", + "parent", + "principal", + "relative", + "student", + "teacher" + ] + }, + "beginDate": { "format": "date-time", "type": "string" }, + "endDate": { + "format": "date-time", + "type": "string", + "nullable": true + }, + "organization": { + "nullable": true, + "allOf": [{ "$ref": "#/components/schemas/OrganizationModel" }] + } + }, + "required": ["id", "role", "beginDate", "endDate", "organization"] + }, + "AgentModel": { + "type": "object", + "properties": { + "id": { "type": "string" }, + "nationalId": { "type": "string" }, + "name": { "type": "string" }, + "phone": { "type": "string" }, + "email": { "type": "string" }, + "role": { "type": "string" }, + "address": { + "nullable": true, + "allOf": [{ "$ref": "#/components/schemas/AddressModel" }] + } + }, + "required": [ + "id", + "nationalId", + "name", + "phone", + "email", + "role", + "address" + ] + }, + "UserModel": { + "type": "object", + "properties": { + "id": { "type": "string" }, + "nationalId": { "type": "string" }, + "name": { "type": "string" }, + "preferredName": { "type": "object", "nullable": true }, + "pronouns": { "type": "array", "items": { "type": "string" } }, + "gradeLevels": { "type": "array", "items": { "type": "string" } }, + "email": { "type": "object", "nullable": true }, + "address": { + "nullable": true, + "allOf": [{ "$ref": "#/components/schemas/AddressModel" }] + }, + "primaryOrgId": { "type": "object" }, + "memberships": { + "type": "array", + "items": { "$ref": "#/components/schemas/MembershipModel" } + }, + "agents": { + "type": "array", + "items": { "$ref": "#/components/schemas/AgentModel" } + } + }, + "required": [ + "id", + "nationalId", + "name", + "preferredName", + "pronouns", + "gradeLevels", + "email", + "address", + "primaryOrgId", + "memberships", + "agents" + ] } } } diff --git a/libs/clients/mms/frigg/src/lib/apiProvider.ts b/libs/clients/mms/frigg/src/lib/apiProvider.ts index d1f77fd70d0b..f8c592ac5100 100644 --- a/libs/clients/mms/frigg/src/lib/apiProvider.ts +++ b/libs/clients/mms/frigg/src/lib/apiProvider.ts @@ -8,23 +8,28 @@ import { Configuration, DefaultApi, KeyOptionsManagementApi, + SchoolsManagementApi, + UsersManagementApi, } from '../../gen/fetch' import { ConfigFactory } from './configFactory' import { FriggClientConfig } from './friggClient.config' -export const apiProvider = [KeyOptionsManagementApi, DefaultApi].map( - (apiRecord) => ({ - provide: apiRecord, - scope: LazyDuringDevScope, - useFactory: ( - xRoadConfig: ConfigType, - config: ConfigType, - idsClientConfig: ConfigType, - ) => { - return new apiRecord( - new Configuration(ConfigFactory(xRoadConfig, config, idsClientConfig)), - ) - }, - inject: [XRoadConfig.KEY, FriggClientConfig.KEY, IdsClientConfig.KEY], - }), -) +export const apiProvider = [ + KeyOptionsManagementApi, + DefaultApi, + SchoolsManagementApi, + UsersManagementApi, +].map((apiRecord) => ({ + provide: apiRecord, + scope: LazyDuringDevScope, + useFactory: ( + xRoadConfig: ConfigType, + config: ConfigType, + idsClientConfig: ConfigType, + ) => { + return new apiRecord( + new Configuration(ConfigFactory(xRoadConfig, config, idsClientConfig)), + ) + }, + inject: [XRoadConfig.KEY, FriggClientConfig.KEY, IdsClientConfig.KEY], +})) diff --git a/libs/clients/mms/frigg/src/lib/friggClient.service.ts b/libs/clients/mms/frigg/src/lib/friggClient.service.ts index 95d7b47117cf..4fc4116feaec 100644 --- a/libs/clients/mms/frigg/src/lib/friggClient.service.ts +++ b/libs/clients/mms/frigg/src/lib/friggClient.service.ts @@ -1,12 +1,22 @@ import { Injectable } from '@nestjs/common' import { Auth, AuthMiddleware, type User } from '@island.is/auth-nest-tools' -import { KeyOption, KeyOptionsManagementApi, DefaultApi } from '../../gen/fetch' +import { + KeyOption, + KeyOptionsManagementApi, + DefaultApi, + UsersManagementApi, + SchoolsManagementApi, + OrganizationModel, + UserModel, +} from '../../gen/fetch' @Injectable() export class FriggClientService { constructor( private readonly keyOptionsManagementApi: KeyOptionsManagementApi, private readonly defaultApi: DefaultApi, + private readonly usersManagementApi: UsersManagementApi, + private readonly schoolsManagementApi: SchoolsManagementApi, ) {} private keyOptionsManagementApiWithAuth = (user: User) => @@ -17,17 +27,36 @@ export class FriggClientService { private defaultApiWithAuth = (user: User) => this.defaultApi.withMiddleware(new AuthMiddleware(user as Auth)) + private usersManagementApiWithAuth = (user: User) => + this.usersManagementApi.withMiddleware(new AuthMiddleware(user as Auth)) + + private schoolsManagementApiWithAuth = (user: User) => + this.schoolsManagementApi.withMiddleware(new AuthMiddleware(user as Auth)) + async getHealth(user: User): Promise { return this.defaultApiWithAuth(user).health() } - async getAllKeyOptions(user: User, type: string): Promise { + async getAllKeyOptions( + user: User, + type: string | undefined, + ): Promise { return this.keyOptionsManagementApiWithAuth(user).getAllKeyOptions({ - type, + type: type, }) } async getTypes(user: User): Promise { return this.keyOptionsManagementApiWithAuth(user).getTypes() } + + async getAllSchoolsByMunicipality(user: User): Promise { + return this.schoolsManagementApiWithAuth(user).getAllSchoolsByMunicipality() + } + + async getUserById(user: User): Promise { + return this.usersManagementApiWithAuth(user).getUserBySourcedId({ + nationalId: user.nationalId, + }) + } } From 750e7271acfb443d47a74bda1b8ab089dda96d55 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Fri, 21 Jun 2024 14:23:01 +0000 Subject: [PATCH 02/22] testing --- libs/api/domains/education/src/lib/graphql/frigg.resolver.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts b/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts index 5a009eac74d1..b86501e79871 100644 --- a/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts +++ b/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts @@ -30,4 +30,5 @@ export class FriggResolver { ): Promise { return this.friggClientService.getAllKeyOptions(user, input.type) } + /* SMALL TEST */ } From ede00b116cbf66bb7627a670f16d23d2e74ce784 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Fri, 21 Jun 2024 14:23:36 +0000 Subject: [PATCH 03/22] Rollback test --- libs/api/domains/education/src/lib/graphql/frigg.resolver.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts b/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts index b86501e79871..5a009eac74d1 100644 --- a/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts +++ b/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts @@ -30,5 +30,4 @@ export class FriggResolver { ): Promise { return this.friggClientService.getAllKeyOptions(user, input.type) } - /* SMALL TEST */ } From e350021b9b24e7282d4e077029f858384608a1e2 Mon Sep 17 00:00:00 2001 From: veronikasif <54938148+veronikasif@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:27:16 +0000 Subject: [PATCH 04/22] feat(new-primary-school): Allergies and intolerances - Data implementation (#15319) * [TS-806] Implement Allergies and intolerances page - Data implementation * Updated function name --- .../FriggOptionsAsyncSelectField/index.tsx | 55 ++++++++++++ .../AllergiesAndIntolerances.tsx | 18 ++-- .../new-primary-school/src/fields/index.ts | 1 + .../allergiesAndIntolerancesSubSection.ts | 80 ++++++++--------- .../src/hooks/useFriggOptions.ts | 25 ++++++ .../new-primary-school/src/lib/constants.ts | 21 ----- .../new-primary-school/src/lib/dataSchema.ts | 10 +-- .../new-primary-school/src/lib/messages.ts | 45 ---------- .../src/lib/newPrimarySchoolUtils.ts | 89 ++++--------------- .../templates/new-primary-school/src/types.ts | 5 ++ 10 files changed, 155 insertions(+), 194 deletions(-) create mode 100644 libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx create mode 100644 libs/application/templates/new-primary-school/src/hooks/useFriggOptions.ts diff --git a/libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx b/libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx new file mode 100644 index 000000000000..530aae120a7b --- /dev/null +++ b/libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx @@ -0,0 +1,55 @@ +import { coreErrorMessages } from '@island.is/application/core' +import { + FieldBaseProps, + FieldComponents, + FieldTypes, + FormText, +} from '@island.is/application/types' +import { AsyncSelectFormField } from '@island.is/application/ui-fields' +import { useLocale } from '@island.is/localization' +import React, { FC } from 'react' +import { OptionsType } from '../../lib/constants' +import { getOptionsListByType } from '../../lib/newPrimarySchoolUtils' + +type FriggOptionsAsyncSelectFieldProps = { + field: { + props: { + optionsType: OptionsType + placeholder: FormText + } + } +} + +const FriggOptionsAsyncSelectField: FC< + React.PropsWithChildren +> = ({ error, field, application }) => { + const { lang } = useLocale() + const { title, props } = field + + return ( + { + return await getOptionsListByType( + apolloClient, + props.optionsType, + lang, + ) + }, + isMulti: true, + backgroundColor: 'blue', + }} + /> + ) +} + +export default FriggOptionsAsyncSelectField diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx index 1b034ee09e9e..6aa822504e78 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx @@ -2,11 +2,12 @@ import { YES } from '@island.is/application/core' import { DataValue, ReviewGroup } from '@island.is/application/ui-components' import { GridColumn, GridRow, Stack } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' +import { useFriggOptions } from '../../../hooks/useFriggOptions' +import { OptionsType } from '../../../lib/constants' import { newPrimarySchoolMessages } from '../../../lib/messages' import { getApplicationAnswers, - getFoodAllergiesOptionsLabel, - getFoodIntolerancesOptionsLabel, + getSelectedOptionLabel, } from '../../../lib/newPrimarySchoolUtils' import { ReviewGroupProps } from './props' @@ -24,6 +25,9 @@ export const AllergiesAndIntolerances = ({ foodIntolerances, } = getApplicationAnswers(application.answers) + const foodAllergiesFriggOptions = useFriggOptions(OptionsType.ALLERGRY) + const foodIntolerancesFriggOptions = useFriggOptions(OptionsType.INTOLERANCE) + return ( { - return formatMessage( - getFoodAllergiesOptionsLabel(allergies), + return getSelectedOptionLabel( + foodAllergiesFriggOptions, + allergies, ) }) .join(', ')} @@ -57,8 +62,9 @@ export const AllergiesAndIntolerances = ({ )} value={foodIntolerances .map((intolerances) => { - return formatMessage( - getFoodIntolerancesOptionsLabel(intolerances), + return getSelectedOptionLabel( + foodIntolerancesFriggOptions, + intolerances, ) }) .join(', ')} diff --git a/libs/application/templates/new-primary-school/src/fields/index.ts b/libs/application/templates/new-primary-school/src/fields/index.ts index 0e2d8dbbffd1..623f7a7748cf 100644 --- a/libs/application/templates/new-primary-school/src/fields/index.ts +++ b/libs/application/templates/new-primary-school/src/fields/index.ts @@ -1 +1,2 @@ +export { default as FriggOptionsAsyncSelectField } from './FriggOptionsAsyncSelectField' export { Review } from './Review' diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts index 050db767ee53..b2491a03a62b 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts @@ -1,18 +1,15 @@ import { buildAlertMessageField, - buildAsyncSelectField, buildCheckboxField, + buildCustomField, buildDescriptionField, buildMultiField, buildSubSection, } from '@island.is/application/core' import { YES } from '@island.is/application/types' +import { OptionsType } from '../../../lib/constants' import { newPrimarySchoolMessages } from '../../../lib/messages' -import { - getApplicationAnswers, - getFoodAllergiesOptions, - getFoodIntolerancesOptions, -} from '../../../lib/newPrimarySchoolUtils' +import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' export const allergiesAndIntolerancesSubSection = buildSubSection({ id: 'allergiesAndIntolerancesSubSection', @@ -41,28 +38,25 @@ export const allergiesAndIntolerancesSubSection = buildSubSection({ }, ], }), - buildAsyncSelectField({ - id: 'allergiesAndIntolerances.foodAllergies', - title: newPrimarySchoolMessages.differentNeeds.typeOfAllergies, - dataTestId: 'food-allergies', - placeholder: - newPrimarySchoolMessages.differentNeeds.typeOfAllergiesPlaceholder, - // TODO: Nota gögn fá Júní - loadOptions: async ({ apolloClient }) => { - /* return await getOptionsListByType( - apolloClient, - OptionsType.ALLERGRY, - )*/ + buildCustomField( + { + id: 'allergiesAndIntolerances.foodAllergies', + title: newPrimarySchoolMessages.differentNeeds.typeOfAllergies, + component: 'FriggOptionsAsyncSelectField', + dataTestId: 'food-allergies', + condition: (answers) => { + const { hasFoodAllergies } = getApplicationAnswers(answers) - return getFoodAllergiesOptions() + return hasFoodAllergies?.includes(YES) + }, }, - isMulti: true, - condition: (answers) => { - const { hasFoodAllergies } = getApplicationAnswers(answers) - - return hasFoodAllergies?.includes(YES) + { + optionsType: OptionsType.ALLERGRY, + placeholder: + newPrimarySchoolMessages.differentNeeds + .typeOfAllergiesPlaceholder, }, - }), + ), buildAlertMessageField({ id: 'allergiesAndIntolerances.info', title: newPrimarySchoolMessages.shared.alertTitle, @@ -91,29 +85,25 @@ export const allergiesAndIntolerancesSubSection = buildSubSection({ }, ], }), - buildAsyncSelectField({ - id: 'allergiesAndIntolerances.foodIntolerances', - title: newPrimarySchoolMessages.differentNeeds.typeOfIntolerances, - dataTestId: 'food-intolerances', - placeholder: - newPrimarySchoolMessages.differentNeeds - .typeOfIntolerancesPlaceholder, - // TODO: Nota gögn fá Júní - loadOptions: async ({ apolloClient }) => { - /*return await getOptionsListByType( - apolloClient, - OptionsType.INTELERENCE, - )*/ + buildCustomField( + { + id: 'allergiesAndIntolerances.foodIntolerances', + title: newPrimarySchoolMessages.differentNeeds.typeOfIntolerances, + component: 'FriggOptionsAsyncSelectField', + dataTestId: 'food-intolerances', + condition: (answers) => { + const { hasFoodIntolerances } = getApplicationAnswers(answers) - return getFoodIntolerancesOptions() + return hasFoodIntolerances?.includes(YES) + }, }, - isMulti: true, - condition: (answers) => { - const { hasFoodIntolerances } = getApplicationAnswers(answers) - - return hasFoodIntolerances?.includes(YES) + { + optionsType: OptionsType.INTOLERANCE, + placeholder: + newPrimarySchoolMessages.differentNeeds + .typeOfIntolerancesPlaceholder, }, - }), + ), buildDescriptionField({ // Needed to add space id: 'allergiesAndIntolerances.divider', diff --git a/libs/application/templates/new-primary-school/src/hooks/useFriggOptions.ts b/libs/application/templates/new-primary-school/src/hooks/useFriggOptions.ts new file mode 100644 index 000000000000..6ffc96650427 --- /dev/null +++ b/libs/application/templates/new-primary-school/src/hooks/useFriggOptions.ts @@ -0,0 +1,25 @@ +import { useQuery } from '@apollo/client' +import { useLocale } from '@island.is/localization' +import { friggOptionsQuery } from '../graphql/queries' +import { OptionsType } from '../lib/constants' +import { FriggOptionsQuery } from '../types/schema' + +export const useFriggOptions = (type?: OptionsType) => { + const { lang } = useLocale() + const { data } = useQuery(friggOptionsQuery, { + variables: { + type: { + type, + }, + }, + }) + + return ( + data?.friggOptions?.flatMap(({ options }) => + options.flatMap(({ value, key }) => { + const content = value.find(({ language }) => language === lang)?.content + return { value: key ?? '', label: content ?? '' } + }), + ) ?? [] + ) +} diff --git a/libs/application/templates/new-primary-school/src/lib/constants.ts b/libs/application/templates/new-primary-school/src/lib/constants.ts index ab0132cfb1c4..1450de0a9278 100644 --- a/libs/application/templates/new-primary-school/src/lib/constants.ts +++ b/libs/application/templates/new-primary-school/src/lib/constants.ts @@ -20,11 +20,6 @@ export enum Roles { APPLICANT = 'applicant', } -export type Option = { - value: string - label: string -} - export enum RelationOptions { GRANDPARENT = 'grandparent', SIBLING = 'sibling', @@ -52,22 +47,6 @@ export enum SiblingRelationOptions { STEP_SIBLING = 'stepSibling', } -export enum FoodAllergiesOptions { - EGG_ALLERGY = 'eggAllergy', - FISH_ALLERGY = 'fishAllergy', - PENUT_ALLERGY = 'peanutAllergy', - WHEAT_ALLERGY = 'wheatAllergy', - MILK_ALLERGY = 'milkAllergy', - OTHER = 'other', -} - -export enum FoodIntolerancesOptions { - LACTOSE_INTOLERANCE = 'lactoseIntolerance', - GLUTEN_INTOLERANCE = 'glutenIntolerance', - MSG_INTOLERANCE = 'msgIntolerance', - OTHER = 'other', -} - export enum Gender { FEMALE = 'FEMALE', MALE = 'MALE', diff --git a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts index 7c38dc235935..941181f346f5 100644 --- a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts +++ b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts @@ -3,12 +3,10 @@ import * as kennitala from 'kennitala' import { parsePhoneNumberFromString } from 'libphonenumber-js' import { z } from 'zod' import { - FoodAllergiesOptions, - FoodIntolerancesOptions, + Gender, ReasonForApplicationOptions, RelationOptions, SiblingRelationOptions, - Gender, } from './constants' import { errorMessages } from './messages' @@ -160,10 +158,8 @@ export const dataSchema = z.object({ .object({ hasFoodAllergies: z.array(z.string()), hasFoodIntolerances: z.array(z.string()), - foodAllergies: z.array(z.nativeEnum(FoodAllergiesOptions)).optional(), - foodIntolerances: z - .array(z.nativeEnum(FoodIntolerancesOptions)) - .optional(), + foodAllergies: z.array(z.string()).optional(), + foodIntolerances: z.array(z.string()).optional(), isUsingEpiPen: z.array(z.string()), }) .refine( diff --git a/libs/application/templates/new-primary-school/src/lib/messages.ts b/libs/application/templates/new-primary-school/src/lib/messages.ts index 904236f680a5..6ae5aa11264d 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -606,51 +606,6 @@ export const newPrimarySchoolMessages: MessageDir = { defaultMessage: 'Notar adrenalínpenna', description: 'Uses epinephrine pen', }, - eggAllergy: { - id: 'dess.nps.application:different.needs.egg.allergy', - defaultMessage: 'Eggjaofnæmi', - description: 'Egg allergy', - }, - fishAllergy: { - id: 'dess.nps.application:different.needs.fish.allergy', - defaultMessage: 'Fiskiofnæmi', - description: 'Fish allergy', - }, - nutAllergy: { - id: 'dess.nps.application:different.needs.nut.allergy', - defaultMessage: 'Hnetuofnæmi', - description: 'Nut allergy', - }, - wheatAllergy: { - id: 'dess.nps.application:different.needs.wheat.allergy', - defaultMessage: 'Hveitiofnæmi', - description: 'Wheat allergy', - }, - milkAllergy: { - id: 'dess.nps.application:different.needs.milk.allergy', - defaultMessage: 'Mjólkurofnæmi', - description: 'Milk allergy', - }, - other: { - id: 'dess.nps.application:different.needs.other', - defaultMessage: 'Annað', - description: 'Other', - }, - lactoseIntolerance: { - id: 'dess.nps.application:different.needs.lactose.intolerance', - defaultMessage: 'Mjólkursykuróþol', - description: 'Lactose intolerance', - }, - glutenIntolerance: { - id: 'dess.nps.application:different.needs.gluten.intolerance', - defaultMessage: 'Glútenóþol', - description: 'Gluten intolerance', - }, - msgIntolerance: { - id: 'dess.nps.application:different.needs.msg.intolerance', - defaultMessage: 'MSG-óþol', - description: 'MSG intolerance', - }, // Support supportSubSectionTitle: { diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index c627c828c780..e5b1867e5e2b 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -5,6 +5,7 @@ import { FormValue, YesOrNo, } from '@island.is/application/types' +import { Locale } from '@island.is/shared/types' import * as kennitala from 'kennitala' import { Child, @@ -12,11 +13,10 @@ import { Parents, Person, RelativesRow, + SelectOption, SiblingsRow, } from '../types' import { - FoodAllergiesOptions, - FoodIntolerancesOptions, Gender, ReasonForApplicationOptions, RelationOptions, @@ -92,7 +92,7 @@ export const getApplicationAnswers = (answers: Application['answers']) => { const foodAllergies = getValueViaPath( answers, 'allergiesAndIntolerances.foodAllergies', - ) as FoodAllergiesOptions[] + ) as string[] const hasFoodIntolerances = getValueViaPath( answers, @@ -102,7 +102,7 @@ export const getApplicationAnswers = (answers: Application['answers']) => { const foodIntolerances = getValueViaPath( answers, 'allergiesAndIntolerances.foodIntolerances', - ) as FoodIntolerancesOptions[] + ) as string[] const isUsingEpiPen = getValueViaPath( answers, @@ -418,72 +418,10 @@ export const getGenderOptionLabel = (value: Gender) => { return genderOptions.find((option) => option.value === value)?.label ?? '' } -export const getFoodAllergiesOptions = () => [ - { - value: FoodAllergiesOptions.EGG_ALLERGY, - label: newPrimarySchoolMessages.differentNeeds.eggAllergy, - }, - { - value: FoodAllergiesOptions.FISH_ALLERGY, - label: newPrimarySchoolMessages.differentNeeds.fishAllergy, - }, - { - value: FoodAllergiesOptions.PENUT_ALLERGY, - label: newPrimarySchoolMessages.differentNeeds.nutAllergy, - }, - { - value: FoodAllergiesOptions.WHEAT_ALLERGY, - label: newPrimarySchoolMessages.differentNeeds.wheatAllergy, - }, - { - value: FoodAllergiesOptions.MILK_ALLERGY, - label: newPrimarySchoolMessages.differentNeeds.milkAllergy, - }, - { - value: FoodAllergiesOptions.OTHER, - label: newPrimarySchoolMessages.differentNeeds.other, - }, -] - -export const getFoodAllergiesOptionsLabel = (value: FoodAllergiesOptions) => { - const foodAllergiesOptions = getFoodAllergiesOptions() - return ( - foodAllergiesOptions.find((option) => option.value === value)?.label ?? '' - ) -} - -export const getFoodIntolerancesOptions = () => [ - { - value: FoodIntolerancesOptions.LACTOSE_INTOLERANCE, - label: newPrimarySchoolMessages.differentNeeds.lactoseIntolerance, - }, - { - value: FoodIntolerancesOptions.GLUTEN_INTOLERANCE, - label: newPrimarySchoolMessages.differentNeeds.glutenIntolerance, - }, - { - value: FoodIntolerancesOptions.MSG_INTOLERANCE, - label: newPrimarySchoolMessages.differentNeeds.msgIntolerance, - }, - { - value: FoodIntolerancesOptions.OTHER, - label: newPrimarySchoolMessages.differentNeeds.other, - }, -] - -export const getFoodIntolerancesOptionsLabel = ( - value: FoodIntolerancesOptions, -) => { - const foodIntolerancesOptions = getFoodIntolerancesOptions() - return ( - foodIntolerancesOptions.find((option) => option.value === value)?.label ?? - '' - ) -} - export const getOptionsListByType = async ( apolloClient: ApolloClient, type: string, + lang: Locale, ) => { const { data } = await apolloClient.query< FriggOptionsQuery, @@ -499,10 +437,21 @@ export const getOptionsListByType = async ( return ( data?.friggOptions?.flatMap(({ options }) => - options.flatMap(({ value, id }) => { - const content = value.find(({ language }) => language === 'is')?.content - return { value: id ?? '', label: content ?? '' } + options.flatMap(({ value, key }) => { + const content = value.find(({ language }) => language === lang)?.content + return { value: key ?? '', label: content ?? '' } }), ) ?? [] ) } + +export const getSelectedOptionLabel = ( + options: SelectOption[], + key?: string, +) => { + if (key === undefined) { + return undefined + } + + return options.find((option) => option.value === key)?.label +} diff --git a/libs/application/templates/new-primary-school/src/types.ts b/libs/application/templates/new-primary-school/src/types.ts index a81c26db3575..7e26d5ff32e1 100644 --- a/libs/application/templates/new-primary-school/src/types.ts +++ b/libs/application/templates/new-primary-school/src/types.ts @@ -61,3 +61,8 @@ export type Parents = { parent1: Person parent2: Person } + +export type SelectOption = { + label: string + value: string +} From 226044f0fbb36787e5fc615bdf007484f1b14bdc Mon Sep 17 00:00:00 2001 From: Alex Diljar Birkisbur Hellsing <42963845+alexdiljar@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:24:02 +0000 Subject: [PATCH 05/22] Refactor/new primary school data implementation (#15381) * refactor: updated apitags * fix? clean * chore: nx format:write update dirty files --------- Co-authored-by: Alex Diljar Co-authored-by: andes-it --- .../new-primary-school.service.ts | 4 -- .../src/dataProviders/index.ts | 6 -- .../src/forms/Prerequisites.ts | 17 ++--- .../src/lib/NewPrimarySchoolTemplate.ts | 10 ++- libs/clients/mms/frigg/src/clientConfig.json | 72 +++++++++++++------ libs/clients/mms/frigg/src/lib/apiProvider.ts | 15 +--- .../mms/frigg/src/lib/friggClient.service.ts | 42 +++-------- 7 files changed, 73 insertions(+), 93 deletions(-) diff --git a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts index 0661eb017eb7..c5b82713f1b1 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts @@ -22,10 +22,6 @@ export class NewPrimarySchoolService extends BaseTemplateApiService { return await this.friggClientService.getAllKeyOptions(auth, undefined) } - async getHealth({ auth }: TemplateApiModuleActionProps) { - return await this.friggClientService.getHealth(auth) - } - async getUserById({ auth }: TemplateApiModuleActionProps) { return await this.friggClientService.getUserById(auth) } diff --git a/libs/application/templates/new-primary-school/src/dataProviders/index.ts b/libs/application/templates/new-primary-school/src/dataProviders/index.ts index a34a6f036b9a..b68798605975 100644 --- a/libs/application/templates/new-primary-school/src/dataProviders/index.ts +++ b/libs/application/templates/new-primary-school/src/dataProviders/index.ts @@ -9,12 +9,6 @@ export const GetTypesApi = defineTemplateApi({ namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, }) -export const GetHealthApi = defineTemplateApi({ - action: 'getHealth', - externalDataId: 'health', - namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, -}) - export const GetUserApi = defineTemplateApi({ action: 'getUserById', externalDataId: 'userInfo', diff --git a/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts b/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts index 87e7d653ee58..ca7aaf84b7d2 100644 --- a/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts +++ b/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts @@ -15,7 +15,6 @@ import { } from '@island.is/application/types' import { newPrimarySchoolMessages } from '../lib/messages' import { - GetHealthApi, GetSchoolsApi, GetTypesApi, GetUserApi, @@ -70,26 +69,22 @@ export const Prerequisites: Form = buildForm({ subTitle: newPrimarySchoolMessages.pre.userProfileInformationSubTitle, }), - /* buildDataProviderItem({ + buildDataProviderItem({ provider: GetTypesApi, title: 'Type', }), - buildDataProviderItem({ - provider: GetHealthApi, - title: 'health', - }), buildDataProviderItem({ provider: OptionsApi, title: 'OPtions', - }), */ - /* buildDataProviderItem({ + }), + buildDataProviderItem({ provider: GetUserApi, title: 'usr', - }),*/ - /* buildDataProviderItem({ + }), + buildDataProviderItem({ provider: GetSchoolsApi, title: 'schools', - }),*/ + }), ], }), ], diff --git a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts index e59e4fa0c685..4ff69fe86f63 100644 --- a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts +++ b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts @@ -25,7 +25,6 @@ import { dataSchema } from './dataSchema' import { newPrimarySchoolMessages, statesMessages } from './messages' import { getApplicationAnswers } from './newPrimarySchoolUtils' import { - GetHealthApi, GetSchoolsApi, GetTypesApi, GetUserApi, @@ -78,11 +77,10 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< ChildrenCustodyInformationApi, NationalRegistryUserApi, UserProfileApi, - /* GetTypesApi, - GetHealthApi, - OptionsApi,*/ - // GetSchoolsApi, - //GetUserApi, + GetTypesApi, + OptionsApi, + GetSchoolsApi, + GetUserApi, ], }, ], diff --git a/libs/clients/mms/frigg/src/clientConfig.json b/libs/clients/mms/frigg/src/clientConfig.json index 6b74326452bd..6e1d906b3367 100644 --- a/libs/clients/mms/frigg/src/clientConfig.json +++ b/libs/clients/mms/frigg/src/clientConfig.json @@ -28,7 +28,7 @@ } } }, - "tags": ["KeyOptionsManagement"] + "tags": ["Frigg"] } }, "/keyOptions/types": { @@ -37,15 +37,25 @@ "summary": "Get list of types of key options", "description": "Get types.", "parameters": [], - "responses": { "200": { "description": "" } }, - "tags": ["KeyOptionsManagement"] + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { "type": "array", "items": { "type": "string" } } + } + } + } + }, + "tags": ["Frigg"] } }, "/health": { "get": { "operationId": "health", "parameters": [], - "responses": { "200": { "description": "" } } + "responses": { "200": { "description": "" } }, + "tags": ["Utils"] } }, "/schools": { @@ -67,8 +77,8 @@ } } }, - "tags": ["SchoolsManagement"], - "security": [{ "Authorization": [] }] + "tags": ["Frigg"], + "security": [{ "bearer": [] }] } }, "/student/{nationalId}": { @@ -94,8 +104,8 @@ } } }, - "tags": ["UsersManagement"], - "security": [{ "Authorization": [] }] + "tags": ["Frigg"], + "security": [{ "bearer": [] }] } } }, @@ -109,13 +119,11 @@ "servers": [], "components": { "securitySchemes": { - "Authorization": { - "scheme": "Bearer", - "bearerFormat": "Bearer", + "bearer": { + "scheme": "bearer", + "bearerFormat": "JWT", "description": "Please enter token in from IAS", - "name": "Authorization", - "type": "http", - "in": "Header" + "type": "http" } }, "schemas": { @@ -168,6 +176,17 @@ }, "required": ["type", "options"] }, + "AddressModel": { + "type": "object", + "properties": { + "id": { "type": "string" }, + "street": { "type": "string" }, + "municipality": { "type": "object", "nullable": true }, + "zip": { "type": "string" }, + "country": { "type": "object", "nullable": true } + }, + "required": ["id", "street", "municipality", "zip", "country"] + }, "OrganizationModel": { "type": "object", "properties": { @@ -179,12 +198,18 @@ "enum": ["municipality", "national", "school"] }, "gradeLevels": { "type": "array", "items": { "type": "string" } }, + "address": { + "nullable": true, + "allOf": [{ "$ref": "#/components/schemas/AddressModel" }] + }, "parent": { "nullable": true, + "default": null, "allOf": [{ "$ref": "#/components/schemas/OrganizationModel" }] }, "children": { "nullable": true, + "default": [], "type": "array", "items": { "$ref": "#/components/schemas/OrganizationModel" } } @@ -195,20 +220,23 @@ "name", "type", "gradeLevels", + "address", "parent", "children" ] }, - "AddressModel": { + "MembershipOrganizationModel": { "type": "object", "properties": { "id": { "type": "string" }, - "street": { "type": "string" }, - "municipality": { "type": "object", "nullable": true }, - "zip": { "type": "string" }, - "country": { "type": "object", "nullable": true } + "nationalId": { "type": "string" }, + "name": { "type": "string" }, + "type": { + "type": "string", + "enum": ["municipality", "national", "school"] + } }, - "required": ["id", "street", "municipality", "zip", "country"] + "required": ["id", "nationalId", "name", "type"] }, "MembershipModel": { "type": "object", @@ -234,7 +262,9 @@ }, "organization": { "nullable": true, - "allOf": [{ "$ref": "#/components/schemas/OrganizationModel" }] + "allOf": [ + { "$ref": "#/components/schemas/MembershipOrganizationModel" } + ] } }, "required": ["id", "role", "beginDate", "endDate", "organization"] diff --git a/libs/clients/mms/frigg/src/lib/apiProvider.ts b/libs/clients/mms/frigg/src/lib/apiProvider.ts index f8c592ac5100..e56219d24758 100644 --- a/libs/clients/mms/frigg/src/lib/apiProvider.ts +++ b/libs/clients/mms/frigg/src/lib/apiProvider.ts @@ -4,22 +4,11 @@ import { LazyDuringDevScope, XRoadConfig, } from '@island.is/nest/config' -import { - Configuration, - DefaultApi, - KeyOptionsManagementApi, - SchoolsManagementApi, - UsersManagementApi, -} from '../../gen/fetch' +import { Configuration, FriggApi } from '../../gen/fetch' import { ConfigFactory } from './configFactory' import { FriggClientConfig } from './friggClient.config' -export const apiProvider = [ - KeyOptionsManagementApi, - DefaultApi, - SchoolsManagementApi, - UsersManagementApi, -].map((apiRecord) => ({ +export const apiProvider = [FriggApi].map((apiRecord) => ({ provide: apiRecord, scope: LazyDuringDevScope, useFactory: ( diff --git a/libs/clients/mms/frigg/src/lib/friggClient.service.ts b/libs/clients/mms/frigg/src/lib/friggClient.service.ts index 4fc4116feaec..607ddfd9bb35 100644 --- a/libs/clients/mms/frigg/src/lib/friggClient.service.ts +++ b/libs/clients/mms/frigg/src/lib/friggClient.service.ts @@ -2,60 +2,38 @@ import { Injectable } from '@nestjs/common' import { Auth, AuthMiddleware, type User } from '@island.is/auth-nest-tools' import { KeyOption, - KeyOptionsManagementApi, - DefaultApi, - UsersManagementApi, - SchoolsManagementApi, + FriggApi, OrganizationModel, UserModel, } from '../../gen/fetch' @Injectable() export class FriggClientService { - constructor( - private readonly keyOptionsManagementApi: KeyOptionsManagementApi, - private readonly defaultApi: DefaultApi, - private readonly usersManagementApi: UsersManagementApi, - private readonly schoolsManagementApi: SchoolsManagementApi, - ) {} + constructor(private readonly friggApi: FriggApi) {} - private keyOptionsManagementApiWithAuth = (user: User) => - this.keyOptionsManagementApi.withMiddleware( - new AuthMiddleware(user as Auth), - ) - - private defaultApiWithAuth = (user: User) => - this.defaultApi.withMiddleware(new AuthMiddleware(user as Auth)) - - private usersManagementApiWithAuth = (user: User) => - this.usersManagementApi.withMiddleware(new AuthMiddleware(user as Auth)) - - private schoolsManagementApiWithAuth = (user: User) => - this.schoolsManagementApi.withMiddleware(new AuthMiddleware(user as Auth)) - - async getHealth(user: User): Promise { - return this.defaultApiWithAuth(user).health() - } + private friggApiWithAuth = (user: User) => + this.friggApi.withMiddleware(new AuthMiddleware(user as Auth)) async getAllKeyOptions( user: User, type: string | undefined, ): Promise { - return this.keyOptionsManagementApiWithAuth(user).getAllKeyOptions({ + return await this.friggApiWithAuth(user).getAllKeyOptions({ type: type, }) } - async getTypes(user: User): Promise { - return this.keyOptionsManagementApiWithAuth(user).getTypes() + async getTypes(user: User): Promise { + return await this.friggApiWithAuth(user).getTypes() } async getAllSchoolsByMunicipality(user: User): Promise { - return this.schoolsManagementApiWithAuth(user).getAllSchoolsByMunicipality() + return await this.friggApiWithAuth(user).getAllSchoolsByMunicipality() } async getUserById(user: User): Promise { - return this.usersManagementApiWithAuth(user).getUserBySourcedId({ + // TODO: use childs nationalid + return await this.friggApiWithAuth(user).getUserBySourcedId({ nationalId: user.nationalId, }) } From 6613335f4c5942e05154974d0c09d20ca5ab9316 Mon Sep 17 00:00:00 2001 From: Veronika Sif Date: Fri, 28 Jun 2024 14:36:05 +0000 Subject: [PATCH 06/22] Comment out UserApi --- .../new-primary-school/src/forms/Prerequisites.ts | 8 ++++---- .../src/lib/NewPrimarySchoolTemplate.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts b/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts index ca7aaf84b7d2..4f9f0d45e0a4 100644 --- a/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts +++ b/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts @@ -77,10 +77,10 @@ export const Prerequisites: Form = buildForm({ provider: OptionsApi, title: 'OPtions', }), - buildDataProviderItem({ - provider: GetUserApi, - title: 'usr', - }), + // buildDataProviderItem({ + // provider: GetUserApi, + // title: 'usr', + // }), buildDataProviderItem({ provider: GetSchoolsApi, title: 'schools', diff --git a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts index 4ff69fe86f63..8c8233a2f023 100644 --- a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts +++ b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts @@ -80,7 +80,7 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< GetTypesApi, OptionsApi, GetSchoolsApi, - GetUserApi, + // GetUserApi, ], }, ], From 0fdad8caa6160e53ca0b7eb38d53a402d41aebe3 Mon Sep 17 00:00:00 2001 From: veronikasif <54938148+veronikasif@users.noreply.github.com> Date: Mon, 1 Jul 2024 14:53:03 +0000 Subject: [PATCH 07/22] feat(new-primary-school): Move child page to prerequisites (#15394) * Move child page to prerequisites * Update clientConfig * Updated Api module action name --- .../new-primary-school.service.ts | 22 ++- .../src/dataProviders/index.ts | 12 +- .../AllergiesAndIntolerances.tsx | 2 +- .../src/fields/Review/review-groups/Child.tsx | 2 +- .../childInfoSubSection.ts | 9 +- .../childrenNParentsSection/index.ts | 8 +- .../allergiesAndIntolerancesSubSection.ts | 2 +- .../src/forms/Prerequisites.ts | 93 ---------- .../childrenSubSection.ts | 28 ++- .../Prerequisites/externalDataSubSection.ts | 59 ++++++ .../src/forms/Prerequisites/index.ts | 20 ++ .../src/lib/NewPrimarySchoolTemplate.ts | 28 ++- .../new-primary-school/src/lib/constants.ts | 25 ++- .../new-primary-school/src/lib/messages.ts | 27 +-- .../src/lib/newPrimarySchoolUtils.ts | 7 + .../templates/new-primary-school/src/types.ts | 46 +++++ libs/clients/mms/frigg/src/clientConfig.json | 172 +++++++++++++++++- .../mms/frigg/src/lib/friggClient.service.ts | 13 +- 18 files changed, 417 insertions(+), 158 deletions(-) delete mode 100644 libs/application/templates/new-primary-school/src/forms/Prerequisites.ts rename libs/application/templates/new-primary-school/src/forms/{NewPrimarySchoolForm/childrenNParentsSection => Prerequisites}/childrenSubSection.ts (54%) create mode 100644 libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts create mode 100644 libs/application/templates/new-primary-school/src/forms/Prerequisites/index.ts diff --git a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts index c5b82713f1b1..2739d28b946a 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts @@ -1,9 +1,10 @@ -import { Inject, Injectable } from '@nestjs/common' +import { getApplicationAnswers } from '@island.is/application/templates/new-primary-school' import { ApplicationTypes } from '@island.is/application/types' -import { BaseTemplateApiService } from '../../base-template-api.service' import { FriggClientService } from '@island.is/clients/mms/frigg' import { LOGGER_PROVIDER } from '@island.is/logging' +import { Inject, Injectable } from '@nestjs/common' import { TemplateApiModuleActionProps } from '../../../types' +import { BaseTemplateApiService } from '../../base-template-api.service' @Injectable() export class NewPrimarySchoolService extends BaseTemplateApiService { @@ -14,19 +15,24 @@ export class NewPrimarySchoolService extends BaseTemplateApiService { super(ApplicationTypes.NEW_PRIMARY_SCHOOL) } - async getTypes({ auth }: TemplateApiModuleActionProps) { - return await this.friggClientService.getTypes(auth) + async getKeyOptionsTypes({ auth }: TemplateApiModuleActionProps) { + return await this.friggClientService.getKeyOptionsTypes(auth) } async getAllKeyOptions({ auth }: TemplateApiModuleActionProps) { return await this.friggClientService.getAllKeyOptions(auth, undefined) } - async getUserById({ auth }: TemplateApiModuleActionProps) { - return await this.friggClientService.getUserById(auth) - } - async getAllSchoolsByMunicipality({ auth }: TemplateApiModuleActionProps) { return await this.friggClientService.getAllSchoolsByMunicipality(auth) } + + async getChildInformation({ + auth, + application, + }: TemplateApiModuleActionProps) { + const { childNationalId } = getApplicationAnswers(application.answers) + + return await this.friggClientService.getUserById(auth, childNationalId) + } } diff --git a/libs/application/templates/new-primary-school/src/dataProviders/index.ts b/libs/application/templates/new-primary-school/src/dataProviders/index.ts index b68798605975..91b3cf1cc7cd 100644 --- a/libs/application/templates/new-primary-school/src/dataProviders/index.ts +++ b/libs/application/templates/new-primary-school/src/dataProviders/index.ts @@ -3,15 +3,9 @@ import { defineTemplateApi, } from '@island.is/application/types' -export const GetTypesApi = defineTemplateApi({ - action: 'getTypes', - externalDataId: 'types', - namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, -}) - -export const GetUserApi = defineTemplateApi({ - action: 'getUserById', - externalDataId: 'userInfo', +export const GetKeyOptionsTypesApi = defineTemplateApi({ + action: 'getKeyOptionsTypes', + externalDataId: 'keyOptionsTypes', namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, }) diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx index 6aa822504e78..76691d0ecbed 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx @@ -25,7 +25,7 @@ export const AllergiesAndIntolerances = ({ foodIntolerances, } = getApplicationAnswers(application.answers) - const foodAllergiesFriggOptions = useFriggOptions(OptionsType.ALLERGRY) + const foodAllergiesFriggOptions = useFriggOptions(OptionsType.ALLERGY) const foodIntolerancesFriggOptions = useFriggOptions(OptionsType.INTOLERANCE) return ( diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx index 3ff01b20e68d..fbb8ce80ca5f 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx @@ -23,7 +23,7 @@ export const Child = ({ return ( goToScreen?.('childrenMultiField')} + editAction={() => goToScreen?.('childInfo')} > diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts index 8cfefc41ef9c..225de6393048 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts @@ -30,7 +30,8 @@ export const childInfoSubSection = buildSubSection({ title: newPrimarySchoolMessages.shared.fullName, disabled: true, defaultValue: (application: Application) => - getSelectedChild(application)?.fullName, + getApplicationExternalData(application.externalData) + .childInformation.name, }), buildTextField({ id: 'childInfo.nationalId', @@ -39,7 +40,8 @@ export const childInfoSubSection = buildSubSection({ format: '######-####', disabled: true, defaultValue: (application: Application) => - getSelectedChild(application)?.nationalId, + getApplicationExternalData(application.externalData) + .childInformation.nationalId, }), buildTextField({ id: 'childInfo.address.streetAddress', @@ -77,6 +79,9 @@ export const childInfoSubSection = buildSubSection({ id: 'childInfo.chosenName', title: newPrimarySchoolMessages.childrenNParents.childInfoChosenName, width: 'half', + defaultValue: (application: Application) => + getApplicationExternalData(application.externalData) + .childInformation.preferredName, }), buildSelectField({ id: 'childInfo.gender', diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/index.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/index.ts index 9779b607c08c..023e05a1e723 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/index.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/index.ts @@ -1,17 +1,11 @@ import { buildSection } from '@island.is/application/core' import { newPrimarySchoolMessages } from '../../../lib/messages' import { childInfoSubSection } from './childInfoSubSection' -import { childrenSubSection } from './childrenSubSection' import { parentsSubSection } from './parentsSubSection' import { relativesSubSection } from './relativesSubSection' export const childrenNParentsSection = buildSection({ id: 'childrenNParentsSection', title: newPrimarySchoolMessages.childrenNParents.sectionTitle, - children: [ - childrenSubSection, - childInfoSubSection, - parentsSubSection, - relativesSubSection, - ], + children: [childInfoSubSection, parentsSubSection, relativesSubSection], }) diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts index b2491a03a62b..61b3f0d8b97e 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts @@ -51,7 +51,7 @@ export const allergiesAndIntolerancesSubSection = buildSubSection({ }, }, { - optionsType: OptionsType.ALLERGRY, + optionsType: OptionsType.ALLERGY, placeholder: newPrimarySchoolMessages.differentNeeds .typeOfAllergiesPlaceholder, diff --git a/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts b/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts deleted file mode 100644 index 4f9f0d45e0a4..000000000000 --- a/libs/application/templates/new-primary-school/src/forms/Prerequisites.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { - buildDataProviderItem, - buildExternalDataProvider, - buildForm, - buildSection, - buildSubmitField, -} from '@island.is/application/core' -import { - ChildrenCustodyInformationApi, - DefaultEvents, - Form, - FormModes, - NationalRegistryUserApi, - UserProfileApi, -} from '@island.is/application/types' -import { newPrimarySchoolMessages } from '../lib/messages' -import { - GetSchoolsApi, - GetTypesApi, - GetUserApi, - OptionsApi, -} from '../dataProviders' - -export const Prerequisites: Form = buildForm({ - id: 'newPrimarySchoolPrerequisites', - title: newPrimarySchoolMessages.shared.formTitle, - mode: FormModes.NOT_STARTED, - renderLastScreenButton: true, - children: [ - buildSection({ - id: 'prerequisites', - title: newPrimarySchoolMessages.pre.externalDataSection, - children: [ - buildExternalDataProvider({ - id: 'approveExternalData', - title: newPrimarySchoolMessages.pre.externalDataSection, - subTitle: newPrimarySchoolMessages.pre.externalDataDescription, - checkboxLabel: newPrimarySchoolMessages.pre.checkboxProvider, - submitField: buildSubmitField({ - id: 'submit', - placement: 'footer', - title: '', - refetchApplicationAfterSubmit: true, - actions: [ - { - event: DefaultEvents.SUBMIT, - name: newPrimarySchoolMessages.pre.startApplication, - type: 'primary', - }, - ], - }), - dataProviders: [ - buildDataProviderItem({ - provider: NationalRegistryUserApi, - title: - newPrimarySchoolMessages.pre.nationalRegistryInformationTitle, - subTitle: - newPrimarySchoolMessages.pre - .nationalRegistryInformationSubTitle, - }), - buildDataProviderItem({ - provider: ChildrenCustodyInformationApi, - title: '', - subTitle: '', - }), - buildDataProviderItem({ - provider: UserProfileApi, - title: newPrimarySchoolMessages.pre.userProfileInformationTitle, - subTitle: - newPrimarySchoolMessages.pre.userProfileInformationSubTitle, - }), - buildDataProviderItem({ - provider: GetTypesApi, - title: 'Type', - }), - buildDataProviderItem({ - provider: OptionsApi, - title: 'OPtions', - }), - // buildDataProviderItem({ - // provider: GetUserApi, - // title: 'usr', - // }), - buildDataProviderItem({ - provider: GetSchoolsApi, - title: 'schools', - }), - ], - }), - ], - }), - ], -}) diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childrenSubSection.ts b/libs/application/templates/new-primary-school/src/forms/Prerequisites/childrenSubSection.ts similarity index 54% rename from libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childrenSubSection.ts rename to libs/application/templates/new-primary-school/src/forms/Prerequisites/childrenSubSection.ts index 3a4ddf4ae7f0..6c0d08869fd2 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childrenSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/Prerequisites/childrenSubSection.ts @@ -2,27 +2,28 @@ import { buildMultiField, buildRadioField, buildSubSection, + buildSubmitField, } from '@island.is/application/core' +import { DefaultEvents } from '@island.is/application/types' import { format as formatKennitala } from 'kennitala' -import { newPrimarySchoolMessages } from '../../../lib/messages' +import { newPrimarySchoolMessages } from '../../lib/messages' import { canApply, getApplicationExternalData, -} from '../../../lib/newPrimarySchoolUtils' +} from '../../lib/newPrimarySchoolUtils' export const childrenSubSection = buildSubSection({ id: 'childrenSubSection', - title: newPrimarySchoolMessages.childrenNParents.childrenSubSectionTitle, + title: newPrimarySchoolMessages.pre.childrenSubSectionTitle, children: [ buildMultiField({ id: 'childrenMultiField', - title: newPrimarySchoolMessages.childrenNParents.childrenSubSectionTitle, - description: - newPrimarySchoolMessages.childrenNParents.childrenDescription, + title: newPrimarySchoolMessages.pre.childrenSubSectionTitle, + description: newPrimarySchoolMessages.pre.childrenDescription, children: [ buildRadioField({ id: 'childNationalId', - title: newPrimarySchoolMessages.childrenNParents.childrenRadioTitle, + title: newPrimarySchoolMessages.pre.childrenRadioTitle, options: (application) => { const { children } = getApplicationExternalData( application.externalData, @@ -40,6 +41,19 @@ export const childrenSubSection = buildSubSection({ }, required: true, }), + buildSubmitField({ + id: 'submit', + placement: 'footer', + title: '', + refetchApplicationAfterSubmit: true, + actions: [ + { + event: DefaultEvents.SUBMIT, + name: newPrimarySchoolMessages.pre.startApplication, + type: 'primary', + }, + ], + }), ], }), ], diff --git a/libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts b/libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts new file mode 100644 index 000000000000..8ab6193df011 --- /dev/null +++ b/libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts @@ -0,0 +1,59 @@ +import { + buildDataProviderItem, + buildExternalDataProvider, + buildSubSection, +} from '@island.is/application/core' +import { + ChildrenCustodyInformationApi, + NationalRegistryUserApi, + UserProfileApi, +} from '@island.is/application/types' +import { + GetKeyOptionsTypesApi, + GetSchoolsApi, + OptionsApi, +} from '../../dataProviders' +import { newPrimarySchoolMessages } from '../../lib/messages' + +export const externalDataSubSection = buildSubSection({ + id: 'externalDataSubSection', + title: newPrimarySchoolMessages.pre.externalDataSubSection, + children: [ + buildExternalDataProvider({ + id: 'approveExternalData', + title: newPrimarySchoolMessages.pre.externalDataSubSection, + subTitle: newPrimarySchoolMessages.pre.externalDataDescription, + checkboxLabel: newPrimarySchoolMessages.pre.checkboxProvider, + dataProviders: [ + buildDataProviderItem({ + provider: NationalRegistryUserApi, + title: newPrimarySchoolMessages.pre.nationalRegistryInformationTitle, + subTitle: + newPrimarySchoolMessages.pre.nationalRegistryInformationSubTitle, + }), + buildDataProviderItem({ + provider: ChildrenCustodyInformationApi, + title: '', + subTitle: '', + }), + buildDataProviderItem({ + provider: UserProfileApi, + title: newPrimarySchoolMessages.pre.userProfileInformationTitle, + subTitle: newPrimarySchoolMessages.pre.userProfileInformationSubTitle, + }), + buildDataProviderItem({ + provider: GetKeyOptionsTypesApi, + title: 'KeyOptionsTypes', + }), + buildDataProviderItem({ + provider: OptionsApi, + title: 'Options', + }), + buildDataProviderItem({ + provider: GetSchoolsApi, + title: 'Schools', + }), + ], + }), + ], +}) diff --git a/libs/application/templates/new-primary-school/src/forms/Prerequisites/index.ts b/libs/application/templates/new-primary-school/src/forms/Prerequisites/index.ts new file mode 100644 index 000000000000..2ea1457ce5f4 --- /dev/null +++ b/libs/application/templates/new-primary-school/src/forms/Prerequisites/index.ts @@ -0,0 +1,20 @@ +import { buildForm, buildSection } from '@island.is/application/core' +import { Form, FormModes } from '@island.is/application/types' +import { newPrimarySchoolMessages } from '../../lib/messages' +import { childrenSubSection } from './childrenSubSection' +import { externalDataSubSection } from './externalDataSubSection' + +export const Prerequisites: Form = buildForm({ + id: 'newPrimarySchoolPrerequisites', + title: newPrimarySchoolMessages.shared.formTitle, + mode: FormModes.NOT_STARTED, + renderLastScreenButton: true, + renderLastScreenBackButton: true, + children: [ + buildSection({ + id: 'prerequisites', + title: newPrimarySchoolMessages.pre.externalDataSection, + children: [externalDataSubSection, childrenSubSection], + }), + ], +}) diff --git a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts index 8c8233a2f023..3af95bf6f1ff 100644 --- a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts +++ b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts @@ -16,20 +16,26 @@ import { DefaultEvents, NationalRegistryUserApi, UserProfileApi, + defineTemplateApi, } from '@island.is/application/types' import { Features } from '@island.is/feature-flags' import unset from 'lodash/unset' import { assign } from 'xstate' -import { Events, ReasonForApplicationOptions, Roles, States } from './constants' -import { dataSchema } from './dataSchema' -import { newPrimarySchoolMessages, statesMessages } from './messages' -import { getApplicationAnswers } from './newPrimarySchoolUtils' import { + GetKeyOptionsTypesApi, GetSchoolsApi, - GetTypesApi, - GetUserApi, OptionsApi, } from '../dataProviders' +import { + ApiModuleActions, + Events, + ReasonForApplicationOptions, + Roles, + States, +} from './constants' +import { dataSchema } from './dataSchema' +import { newPrimarySchoolMessages, statesMessages } from './messages' +import { getApplicationAnswers } from './newPrimarySchoolUtils' const NewPrimarySchoolTemplate: ApplicationTemplate< ApplicationContext, @@ -57,11 +63,16 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< displayStatus: 'success', }, }, + onExit: defineTemplateApi({ + action: ApiModuleActions.getChildInformation, + externalDataId: 'childInformation', + throwOnError: true, + }), roles: [ { id: Roles.APPLICANT, formLoader: () => - import('../forms/Prerequisites').then((val) => + import('../forms/Prerequisites/index').then((val) => Promise.resolve(val.Prerequisites), ), actions: [ @@ -77,10 +88,9 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< ChildrenCustodyInformationApi, NationalRegistryUserApi, UserProfileApi, - GetTypesApi, + GetKeyOptionsTypesApi, OptionsApi, GetSchoolsApi, - // GetUserApi, ], }, ], diff --git a/libs/application/templates/new-primary-school/src/lib/constants.ts b/libs/application/templates/new-primary-school/src/lib/constants.ts index 1450de0a9278..efc846460a62 100644 --- a/libs/application/templates/new-primary-school/src/lib/constants.ts +++ b/libs/application/templates/new-primary-school/src/lib/constants.ts @@ -16,6 +16,10 @@ export type Events = | { type: DefaultEvents.ASSIGN } | { type: DefaultEvents.EDIT } +export enum ApiModuleActions { + getChildInformation = 'getChildInformation', +} + export enum Roles { APPLICANT = 'applicant', } @@ -54,7 +58,26 @@ export enum Gender { } export enum OptionsType { - ALLERGRY = 'allergy', + PRONOUN = 'pronoun', + GENDER = 'gender', INTOLERANCE = 'intolerence', REASON = 'rejectionReason', + RELATION = 'relation', + ALLERGY = 'allergy', +} + +export enum MembershipRole { + Admin = 'admin', + Guardian = 'guardian', + Parent = 'parent', + Principal = 'principal', + Relative = 'relative', + Student = 'student', + Teacher = 'teacher', +} + +export enum MembershipOrganizationType { + Municipality = 'municipality', + National = 'national', + School = 'school', } diff --git a/libs/application/templates/new-primary-school/src/lib/messages.ts b/libs/application/templates/new-primary-school/src/lib/messages.ts index 6ae5aa11264d..5fcf3c9d6e72 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -125,6 +125,11 @@ export const newPrimarySchoolMessages: MessageDir = { pre: defineMessages({ externalDataSection: { id: 'dess.nps.application:external.data.section', + defaultMessage: 'Forsendur', + description: 'Prerequisites', + }, + externalDataSubSection: { + id: 'dess.nps.application:external.data.sub.section', defaultMessage: 'Gagnaöflun', description: 'Data collection', }, @@ -167,31 +172,31 @@ export const newPrimarySchoolMessages: MessageDir = { defaultMessage: 'Hefja umsókn', description: 'Start application', }, - }), - - childrenNParents: defineMessages({ - sectionTitle: { - id: 'dess.nps.application:childrenNParents.section.title', - defaultMessage: 'Börn og foreldrar', - description: 'Children and parents', - }, // Children childrenSubSectionTitle: { - id: 'dess.nps.application:childrenNParents.children.sub.section.title', + id: 'dess.nps.application:prerequisites.children.sub.section.title', defaultMessage: 'Börn', description: 'Children', }, childrenDescription: { - id: 'dess.nps.application:childrenNParents.childrenDescription#markdown', + id: 'dess.nps.application:prerequisites.childrenDescription#markdown', defaultMessage: `Samkvæmt uppflettingu í Þjóðskrá hefur þú forsjá með eftirfarandi barni/börnum. Ef þú sérð ekki barnið þitt hér, þá bendum við þér að hafa samband við Þjóðskrá. \n\nAthugaðu að einungis er hægt að sækja um fyrir eitt barn í einu. Ef skrá á tvö börn svo sem tvíbura er hægt að fara beint í að skrá annað barn þegar búið er að skrá það fyrra.`, description: `According to the Registers Iceland database you have the following children. If you do not see your child in this process, please contact the Registers Iceland. \n\nPlease note that you can only apply for one child at a time. If you have two children, such as twins, you can proceed to register the second child directly after completing the registration for the first one.`, }, childrenRadioTitle: { - id: 'dess.nps.application:childrenNParents.childrenRadioTitle', + id: 'dess.nps.application:prerequisites.childrenRadioTitle', defaultMessage: 'Veldu barn fyrir umsóknina', description: 'Select child for the application', }, + }), + + childrenNParents: defineMessages({ + sectionTitle: { + id: 'dess.nps.application:childrenNParents.section.title', + defaultMessage: 'Börn og foreldrar', + description: 'Children and parents', + }, // Child information childInfoSubSectionTitle: { diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index e5b1867e5e2b..e659be2e195e 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -10,6 +10,7 @@ import * as kennitala from 'kennitala' import { Child, ChildInformation, + FriggChildInformation, Parents, Person, RelativesRow, @@ -224,6 +225,11 @@ export const getApplicationExternalData = ( 'childrenCustodyInformation.data.otherParent.fullName', ) as string + const childInformation = getValueViaPath( + externalData, + 'childInformation.data', + ) as FriggChildInformation + return { children, applicantName, @@ -232,6 +238,7 @@ export const getApplicationExternalData = ( applicantPostalCode, applicantCity, otherParentName, + childInformation, } } diff --git a/libs/application/templates/new-primary-school/src/types.ts b/libs/application/templates/new-primary-school/src/types.ts index 7e26d5ff32e1..07aa02e8da9b 100644 --- a/libs/application/templates/new-primary-school/src/types.ts +++ b/libs/application/templates/new-primary-school/src/types.ts @@ -1,5 +1,7 @@ import { Gender, + MembershipOrganizationType, + MembershipRole, RelationOptions, SiblingRelationOptions, } from './lib/constants' @@ -66,3 +68,47 @@ export type SelectOption = { label: string value: string } + +export type Agent = { + id: string + name: string + role: string + email: string + phone: string + nationalId: string +} + +export type Membership = { + id: string + role: MembershipRole + beginDate: Date + endDate: Date | null + organization?: MembershipOrganization +} + +export type MembershipOrganization = { + id: string + nationalId: string + name: string + type: MembershipOrganizationType +} + +export type FriggChildInformation = { + id: string + name: string + email: string + agents: Agent[] + pronouns: string[] + nationalId: string + gradeLevels: string[] + memberships: Membership[] + primaryOrgId: object + preferredName: object | null + address?: { + id: string + street: string + municipality?: object + zip: string + country?: object + } +} diff --git a/libs/clients/mms/frigg/src/clientConfig.json b/libs/clients/mms/frigg/src/clientConfig.json index 6e1d906b3367..6e64a4ecbca3 100644 --- a/libs/clients/mms/frigg/src/clientConfig.json +++ b/libs/clients/mms/frigg/src/clientConfig.json @@ -1,6 +1,50 @@ { "openapi": "3.0.0", "paths": { + "/forms": { + "post": { + "operationId": "submitForm", + "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/FormDto" } + } + } + }, + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/SuccessModel" } + } + } + } + }, + "tags": ["Frigg"] + } + }, + "/forms/types": { + "get": { + "operationId": "getFormTypes", + "summary": "Get list of types of forms", + "description": "Get types.", + "parameters": [], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { "type": "array", "items": { "type": "string" } } + } + } + } + }, + "tags": ["Frigg"] + } + }, "/keyOptions": { "get": { "operationId": "getAllKeyOptions", @@ -33,7 +77,7 @@ }, "/keyOptions/types": { "get": { - "operationId": "getTypes", + "operationId": "getKeyOptionsTypes", "summary": "Get list of types of key options", "description": "Get types.", "parameters": [], @@ -127,6 +171,132 @@ } }, "schemas": { + "AddressDto": { + "type": "object", + "properties": { + "address": { "type": "string" }, + "postCode": { "type": "number" } + }, + "required": ["address", "postCode"] + }, + "UserDto": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "nationalId": { "type": "string" }, + "preferredName": { "type": "string" }, + "pronouns": { "type": "array", "items": { "type": "string" } }, + "address": { "$ref": "#/components/schemas/AddressDto" } + }, + "required": [ + "name", + "nationalId", + "preferredName", + "pronouns", + "address" + ] + }, + "AgentDto": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "nationalId": { "type": "string" }, + "preferredName": { "type": "string" }, + "pronouns": { "type": "array", "items": { "type": "string" } }, + "address": { "$ref": "#/components/schemas/AddressDto" }, + "email": { "type": "string" }, + "phone": { "type": "string" }, + "relation": { "type": "string" } + }, + "required": [ + "name", + "nationalId", + "preferredName", + "pronouns", + "address", + "email", + "phone", + "relation" + ] + }, + "RegistrationDto": { + "type": "object", + "properties": { + "preRegisteredId": { "type": "string" }, + "defaultOrg": { "type": "string" }, + "selectedOrg": { "type": "string" }, + "requestingMeeting": { "type": "boolean", "default": false }, + "expectedStartDate": { "format": "date-time", "type": "string" }, + "reason": { "type": "string" }, + "movingAbroadCountry": { "type": "string" } + }, + "required": [ + "preRegisteredId", + "defaultOrg", + "selectedOrg", + "requestingMeeting", + "expectedStartDate", + "reason", + "movingAbroadCountry" + ] + }, + "HealthDto": { + "type": "object", + "properties": { + "usesEpipen": { "type": "boolean", "default": false }, + "allergies": { "type": "array", "items": { "type": "string" } }, + "intolerances": { "type": "array", "items": { "type": "string" } } + }, + "required": ["usesEpipen", "allergies", "intolerances"] + }, + "SocialDto": { + "type": "object", + "properties": { + "hasHadSupport": { "type": "boolean", "default": false }, + "hasDiagnoses": { "type": "boolean", "default": false } + }, + "required": ["hasHadSupport", "hasDiagnoses"] + }, + "LanguageDto": { + "type": "object", + "properties": { + "nativeLanguage": { "type": "string" }, + "noIcelandic": { "type": "boolean" }, + "otherLanguages": { "type": "array", "items": { "type": "string" } } + }, + "required": ["nativeLanguage", "noIcelandic", "otherLanguages"] + }, + "FormDto": { + "type": "object", + "properties": { + "type": { "type": "string", "enum": ["registration"] }, + "user": { "$ref": "#/components/schemas/UserDto" }, + "agents": { + "type": "array", + "items": { "$ref": "#/components/schemas/AgentDto" } + }, + "registration": { "$ref": "#/components/schemas/RegistrationDto" }, + "health": { "$ref": "#/components/schemas/HealthDto" }, + "social": { "$ref": "#/components/schemas/SocialDto" }, + "language": { "$ref": "#/components/schemas/LanguageDto" } + }, + "required": [ + "type", + "user", + "agents", + "registration", + "health", + "social", + "language" + ] + }, + "SuccessModel": { + "type": "object", + "properties": { + "success": { "type": "boolean", "description": "Submission response" } + }, + "required": ["success"] + }, "Value": { "type": "object", "properties": { diff --git a/libs/clients/mms/frigg/src/lib/friggClient.service.ts b/libs/clients/mms/frigg/src/lib/friggClient.service.ts index 607ddfd9bb35..6e0a24bf739b 100644 --- a/libs/clients/mms/frigg/src/lib/friggClient.service.ts +++ b/libs/clients/mms/frigg/src/lib/friggClient.service.ts @@ -1,8 +1,8 @@ -import { Injectable } from '@nestjs/common' import { Auth, AuthMiddleware, type User } from '@island.is/auth-nest-tools' +import { Injectable } from '@nestjs/common' import { - KeyOption, FriggApi, + KeyOption, OrganizationModel, UserModel, } from '../../gen/fetch' @@ -23,18 +23,17 @@ export class FriggClientService { }) } - async getTypes(user: User): Promise { - return await this.friggApiWithAuth(user).getTypes() + async getKeyOptionsTypes(user: User): Promise { + return await this.friggApiWithAuth(user).getKeyOptionsTypes() } async getAllSchoolsByMunicipality(user: User): Promise { return await this.friggApiWithAuth(user).getAllSchoolsByMunicipality() } - async getUserById(user: User): Promise { - // TODO: use childs nationalid + async getUserById(user: User, childNationalId: string): Promise { return await this.friggApiWithAuth(user).getUserBySourcedId({ - nationalId: user.nationalId, + nationalId: childNationalId, }) } } From 0b4582babbe39d05ca6a60e9558d2b82224cd9cd Mon Sep 17 00:00:00 2001 From: veronikasif <54938148+veronikasif@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:57:29 +0000 Subject: [PATCH 08/22] feat(new-primary-school): Relatives - Data implementation (#15403) * Relatives - Data implementation * Fixed after review --- .../fields/RelativesTableRepeater/index.tsx | 121 ++++++++++++++++++ .../fields/Review/review-groups/Relatives.tsx | 8 +- .../new-primary-school/src/fields/index.ts | 1 + .../relativesSubSection.ts | 100 +-------------- .../new-primary-school/src/lib/constants.ts | 8 -- .../new-primary-school/src/lib/dataSchema.ts | 3 +- .../new-primary-school/src/lib/messages.ts | 25 ---- .../src/lib/newPrimarySchoolUtils.ts | 32 ----- .../templates/new-primary-school/src/types.ts | 3 +- 9 files changed, 134 insertions(+), 167 deletions(-) create mode 100644 libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx diff --git a/libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx b/libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx new file mode 100644 index 000000000000..07619b74980e --- /dev/null +++ b/libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx @@ -0,0 +1,121 @@ +import { + FieldBaseProps, + FieldComponents, + FieldTypes, + YES, +} from '@island.is/application/types' +import { + formatPhoneNumber, + removeCountryCode, +} from '@island.is/application/ui-components' +import { TableRepeaterFormField } from '@island.is/application/ui-fields' +import { format as formatKennitala } from 'kennitala' +import React, { FC } from 'react' +import { useFriggOptions } from '../../hooks/useFriggOptions' +import { OptionsType } from '../../lib/constants' +import { newPrimarySchoolMessages } from '../../lib/messages' +import { getSelectedOptionLabel } from '../../lib/newPrimarySchoolUtils' + +const RelativesTableRepeater: FC< + React.PropsWithChildren +> = ({ error, field, application }) => { + const { id, title } = field + + const relationFriggOptions = useFriggOptions(OptionsType.RELATION) + + return ( + + formatPhoneNumber(removeCountryCode(value ?? '')), + nationalId: (value) => formatKennitala(value), + relation: (value) => + getSelectedOptionLabel(relationFriggOptions, value) ?? '', + canPickUpChild: (value) => + value?.includes(YES) + ? newPrimarySchoolMessages.shared.yes + : newPrimarySchoolMessages.shared.no, + }, + header: [ + newPrimarySchoolMessages.shared.fullName, + newPrimarySchoolMessages.shared.phoneNumber, + newPrimarySchoolMessages.shared.nationalId, + newPrimarySchoolMessages.shared.relation, + newPrimarySchoolMessages.childrenNParents + .relativesCanPickUpChildTableHeader, + ], + }, + }} + /> + ) +} + +export default RelativesTableRepeater diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Relatives.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Relatives.tsx index 7e2073e7967e..2936074b1f1d 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Relatives.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Relatives.tsx @@ -9,10 +9,12 @@ import { StaticTableFormField } from '@island.is/application/ui-fields' import { Box, GridColumn, GridRow } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' import { format as formatKennitala } from 'kennitala' +import { useFriggOptions } from '../../../hooks/useFriggOptions' +import { OptionsType } from '../../../lib/constants' import { newPrimarySchoolMessages } from '../../../lib/messages' import { getApplicationAnswers, - getRelationOptionLabel, + getSelectedOptionLabel, } from '../../../lib/newPrimarySchoolUtils' import { ReviewGroupProps } from './props' @@ -24,12 +26,14 @@ export const Relatives = ({ const { formatMessage } = useLocale() const { relatives } = getApplicationAnswers(application.answers) + const relationFriggOptions = useFriggOptions(OptionsType.RELATION) + const rows = relatives.map((r) => { return [ r.fullName, formatPhoneNumber(removeCountryCode(r.phoneNumber ?? '')), formatKennitala(r.nationalId), - getRelationOptionLabel(r.relation), + getSelectedOptionLabel(relationFriggOptions, r.relation) ?? '', r.canPickUpChild?.includes(YES) ? newPrimarySchoolMessages.shared.yes : newPrimarySchoolMessages.shared.no, diff --git a/libs/application/templates/new-primary-school/src/fields/index.ts b/libs/application/templates/new-primary-school/src/fields/index.ts index 623f7a7748cf..671bdef85414 100644 --- a/libs/application/templates/new-primary-school/src/fields/index.ts +++ b/libs/application/templates/new-primary-school/src/fields/index.ts @@ -1,2 +1,3 @@ export { default as FriggOptionsAsyncSelectField } from './FriggOptionsAsyncSelectField' +export { default as RelativesTableRepeater } from './RelativesTableRepeater' export { Review } from './Review' diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/relativesSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/relativesSubSection.ts index 5fe016271a70..532264378bc7 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/relativesSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/relativesSubSection.ts @@ -1,20 +1,9 @@ import { + buildCustomField, buildMultiField, buildSubSection, - buildTableRepeaterField, } from '@island.is/application/core' -import { YES } from '@island.is/application/types' -import { - formatPhoneNumber, - removeCountryCode, -} from '@island.is/application/ui-components' -import { format as formatKennitala } from 'kennitala' -import { RelationOptions } from '../../../lib/constants' import { newPrimarySchoolMessages } from '../../../lib/messages' -import { - getRelationOptionLabel, - getRelationOptions, -} from '../../../lib/newPrimarySchoolUtils' export const relativesSubSection = buildSubSection({ id: 'relativesSubSection', @@ -26,91 +15,10 @@ export const relativesSubSection = buildSubSection({ description: newPrimarySchoolMessages.childrenNParents.relativesDescription, children: [ - buildTableRepeaterField({ + buildCustomField({ id: 'relatives', - title: '', - formTitle: - newPrimarySchoolMessages.childrenNParents - .relativesRegistrationTitle, - addItemButtonText: - newPrimarySchoolMessages.childrenNParents.relativesAddRelative, - saveItemButtonText: - newPrimarySchoolMessages.childrenNParents.relativesRegisterRelative, - removeButtonTooltipText: - newPrimarySchoolMessages.childrenNParents.relativesDeleteRelative, - marginTop: 0, - maxRows: 6, - fields: { - fullName: { - component: 'input', - label: newPrimarySchoolMessages.shared.fullName, - width: 'half', - type: 'text', - dataTestId: 'relative-full-name', - }, - phoneNumber: { - component: 'input', - label: newPrimarySchoolMessages.shared.phoneNumber, - width: 'half', - type: 'tel', - format: '###-####', - placeholder: '000-0000', - dataTestId: 'relative-phone-number', - }, - nationalId: { - component: 'input', - label: newPrimarySchoolMessages.shared.nationalId, - width: 'half', - type: 'text', - format: '######-####', - placeholder: '000000-0000', - dataTestId: 'relative-national-id', - }, - relation: { - component: 'select', - label: newPrimarySchoolMessages.shared.relation, - width: 'half', - placeholder: newPrimarySchoolMessages.shared.relationPlaceholder, - // TODO: Nota gögn fá Júní - options: getRelationOptions(), - dataTestId: 'relative-relation', - }, - canPickUpChild: { - component: 'checkbox', - width: 'full', - large: true, - options: [ - { - label: - newPrimarySchoolMessages.childrenNParents - .relativesCanPickUpChild, - value: YES, - }, - ], - dataTestId: 'relative-can-pick-up-child', - }, - }, - table: { - format: { - phoneNumber: (value) => - formatPhoneNumber(removeCountryCode(value ?? '')), - nationalId: (value) => formatKennitala(value), - relation: (value) => - getRelationOptionLabel(value as RelationOptions), - canPickUpChild: (value) => - value?.includes(YES) - ? newPrimarySchoolMessages.shared.yes - : newPrimarySchoolMessages.shared.no, - }, - header: [ - newPrimarySchoolMessages.shared.fullName, - newPrimarySchoolMessages.shared.phoneNumber, - newPrimarySchoolMessages.shared.nationalId, - newPrimarySchoolMessages.shared.relation, - newPrimarySchoolMessages.childrenNParents - .relativesCanPickUpChildTableHeader, - ], - }, + title: newPrimarySchoolMessages.differentNeeds.typeOfAllergies, + component: 'RelativesTableRepeater', }), ], }), diff --git a/libs/application/templates/new-primary-school/src/lib/constants.ts b/libs/application/templates/new-primary-school/src/lib/constants.ts index efc846460a62..6576edfb101f 100644 --- a/libs/application/templates/new-primary-school/src/lib/constants.ts +++ b/libs/application/templates/new-primary-school/src/lib/constants.ts @@ -24,14 +24,6 @@ export enum Roles { APPLICANT = 'applicant', } -export enum RelationOptions { - GRANDPARENT = 'grandparent', - SIBLING = 'sibling', - STEPPARENT = 'stepparent', - RELATIVE = 'relative', - FRIEND_OR_OTHER = 'friendOrOther', -} - export enum ReasonForApplicationOptions { TRANSFER_OF_LEGAL_DOMICILE = 'transferOfLegalDomicile', STUDY_STAY_FOR_PARENTS = 'studyStayForParents', diff --git a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts index 941181f346f5..42a43ecb66a2 100644 --- a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts +++ b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts @@ -5,7 +5,6 @@ import { z } from 'zod' import { Gender, ReasonForApplicationOptions, - RelationOptions, SiblingRelationOptions, } from './constants' import { errorMessages } from './messages' @@ -69,7 +68,7 @@ export const dataSchema = z.object({ nationalId: z.string().refine((n) => kennitala.isValid(n), { params: errorMessages.nationalId, }), - relation: z.nativeEnum(RelationOptions), + relation: z.string(), }), ) .refine((r) => r === undefined || r.length > 0, { diff --git a/libs/application/templates/new-primary-school/src/lib/messages.ts b/libs/application/templates/new-primary-school/src/lib/messages.ts index 5fcf3c9d6e72..456d9729b207 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -304,31 +304,6 @@ export const newPrimarySchoolMessages: MessageDir = { defaultMessage: 'Eyða aðstandanda', description: 'Remove relative', }, - relativesRelationGrandparent: { - id: 'dess.nps.application:childrenNParents.relatives.relation.grandparent', - defaultMessage: 'Afi/amma', - description: 'Grandparent', - }, - relativesRelationSibling: { - id: 'dess.nps.application:childrenNParents.relatives.relation.sibling', - defaultMessage: 'Systkini', - description: 'Sibling', - }, - relativesRelationStepparent: { - id: 'dess.nps.application:childrenNParents.relatives.relation.stepparent', - defaultMessage: 'Stjúpforeldri', - description: 'Stepparent', - }, - relativesRelationRelative: { - id: 'dess.nps.application:childrenNParents.relatives.relation.relative', - defaultMessage: 'Frændfólk', - description: 'Relative', - }, - relativesRelationFriendOrOther: { - id: 'dess.nps.application:childrenNParents.relatives.relation.friend.or.other', - defaultMessage: 'Vinafólk/annað', - description: 'Friend/other', - }, relativesCanPickUpChild: { id: 'dess.nps.application:childrenNParents.relatives.can.pick.up.child', defaultMessage: 'Má sækja barn í skólann', diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index e659be2e195e..7ac9832d80bf 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -20,7 +20,6 @@ import { import { Gender, ReasonForApplicationOptions, - RelationOptions, SiblingRelationOptions, } from './constants' import { newPrimarySchoolMessages } from './messages' @@ -282,37 +281,6 @@ export const hasOtherParent = ( return !!otherParent } -export const getRelationOptions = () => [ - { - value: RelationOptions.GRANDPARENT, - label: - newPrimarySchoolMessages.childrenNParents.relativesRelationGrandparent, - }, - { - value: RelationOptions.SIBLING, - label: newPrimarySchoolMessages.childrenNParents.relativesRelationSibling, - }, - { - value: RelationOptions.STEPPARENT, - label: - newPrimarySchoolMessages.childrenNParents.relativesRelationStepparent, - }, - { - value: RelationOptions.RELATIVE, - label: newPrimarySchoolMessages.childrenNParents.relativesRelationRelative, - }, - { - value: RelationOptions.FRIEND_OR_OTHER, - label: - newPrimarySchoolMessages.childrenNParents.relativesRelationFriendOrOther, - }, -] - -export const getRelationOptionLabel = (value: RelationOptions) => { - const relationOptions = getRelationOptions() - return relationOptions.find((option) => option.value === value)?.label ?? '' -} - export const getReasonForApplicationOptions = () => [ { value: ReasonForApplicationOptions.TRANSFER_OF_LEGAL_DOMICILE, diff --git a/libs/application/templates/new-primary-school/src/types.ts b/libs/application/templates/new-primary-school/src/types.ts index 07aa02e8da9b..80dce1a4e3d0 100644 --- a/libs/application/templates/new-primary-school/src/types.ts +++ b/libs/application/templates/new-primary-school/src/types.ts @@ -2,7 +2,6 @@ import { Gender, MembershipOrganizationType, MembershipRole, - RelationOptions, SiblingRelationOptions, } from './lib/constants' @@ -10,7 +9,7 @@ export interface RelativesRow { fullName: string phoneNumber: string nationalId: string - relation: RelationOptions + relation: string canPickUpChild: string[] } From 4a00af1c2d4b37242a700ae18f33cfaf3bd0c4e9 Mon Sep 17 00:00:00 2001 From: helgifr Date: Wed, 10 Jul 2024 10:25:36 +0000 Subject: [PATCH 09/22] feat(new-primary-school): pronoun (#15408) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(new-primary-school): Pronoun Select Field Added a select field for selecting pronoun https://dit-iceland.atlassian.net/browse/TS-811 * Make pronoun full width and change place with preferred name * Use gender data from Júní * Review comment fixes * use defaultValue for pronouns --------- Co-authored-by: hfhelgason --- .../FriggOptionsAsyncSelectField/index.tsx | 17 +++--- .../src/fields/Review/review-groups/Child.tsx | 35 ++++++++++-- .../childInfoSubSection.ts | 56 +++++++++++++------ .../src/hooks/useFriggOptions.ts | 5 +- .../new-primary-school/src/lib/constants.ts | 7 ++- .../new-primary-school/src/lib/dataSchema.ts | 5 +- .../new-primary-school/src/lib/messages.ts | 29 ++++------ .../src/lib/newPrimarySchoolUtils.ts | 25 ++------- .../templates/new-primary-school/src/types.ts | 6 +- 9 files changed, 106 insertions(+), 79 deletions(-) diff --git a/libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx b/libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx index 530aae120a7b..1840afb56e2a 100644 --- a/libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx +++ b/libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx @@ -16,6 +16,7 @@ type FriggOptionsAsyncSelectFieldProps = { props: { optionsType: OptionsType placeholder: FormText + isMulti?: boolean } } } @@ -24,7 +25,8 @@ const FriggOptionsAsyncSelectField: FC< React.PropsWithChildren > = ({ error, field, application }) => { const { lang } = useLocale() - const { title, props } = field + const { title, props, defaultValue, id } = field + const { isMulti = true, optionsType, placeholder } = props return ( { - return await getOptionsListByType( - apolloClient, - props.optionsType, - lang, - ) + return await getOptionsListByType(apolloClient, optionsType, lang) }, - isMulti: true, + isMulti, backgroundColor: 'blue', }} /> diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx index fbb8ce80ca5f..a79616cf3291 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx @@ -6,9 +6,11 @@ import { format as formatKennitala } from 'kennitala' import { newPrimarySchoolMessages } from '../../../lib/messages' import { getApplicationAnswers, - getGenderOptionLabel, + getSelectedOptionLabel, } from '../../../lib/newPrimarySchoolUtils' import { ReviewGroupProps } from './props' +import { useFriggOptions } from '../../../hooks/useFriggOptions' +import { OptionsType } from '../../../lib/constants' export const Child = ({ application, @@ -20,6 +22,9 @@ export const Child = ({ application.answers, ) + const genderOptions = useFriggOptions(OptionsType.GENDER) + const pronounOptions = useFriggOptions(OptionsType.PRONOUN) + return ( {(childInfo.gender || - childInfo.chosenName || + childInfo.preferredName || + childInfo.pronouns || differentPlaceOfResidence === YES) && ( - {childInfo.chosenName && ( + {childInfo.preferredName && ( )} @@ -84,7 +90,24 @@ export const Child = ({ label={formatMessage( newPrimarySchoolMessages.childrenNParents.childInfoGender, )} - value={formatMessage(getGenderOptionLabel(childInfo.gender))} + value={getSelectedOptionLabel( + genderOptions, + childInfo.gender, + )} + /> + + )} + {childInfo.pronouns?.length > 0 && ( + + + getSelectedOptionLabel(pronounOptions, pronoun), + ) + .join(', ')} /> )} diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts index 225de6393048..bf76f25e1769 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts @@ -1,7 +1,7 @@ import { + buildCustomField, buildMultiField, buildRadioField, - buildSelectField, buildSubSection, buildTextField, } from '@island.is/application/core' @@ -11,9 +11,9 @@ import { formatGender, getApplicationAnswers, getApplicationExternalData, - getGenderOptions, getSelectedChild, } from '../../../lib/newPrimarySchoolUtils' +import { OptionsType } from '../../../lib/constants' export const childInfoSubSection = buildSubSection({ id: 'childInfoSubSection', @@ -76,25 +76,47 @@ export const childInfoSubSection = buildSubSection({ getApplicationExternalData(application.externalData).applicantCity, }), buildTextField({ - id: 'childInfo.chosenName', - title: newPrimarySchoolMessages.childrenNParents.childInfoChosenName, + id: 'childInfo.preferredName', + title: + newPrimarySchoolMessages.childrenNParents.childInfoPreferredName, width: 'half', defaultValue: (application: Application) => getApplicationExternalData(application.externalData) - .childInformation.preferredName, - }), - buildSelectField({ - id: 'childInfo.gender', - title: newPrimarySchoolMessages.childrenNParents.childInfoGender, - placeholder: - newPrimarySchoolMessages.childrenNParents - .childInfoGenderPlaceholder, - width: 'half', - // TODO: Nota gögn fá Júní - options: getGenderOptions(), - defaultValue: (application: Application) => - formatGender(getSelectedChild(application)?.genderCode), + .childInformation.preferredName ?? undefined, }), + buildCustomField( + { + id: 'childInfo.gender', + title: newPrimarySchoolMessages.childrenNParents.childInfoGender, + width: 'half', + component: 'FriggOptionsAsyncSelectField', + defaultValue: (application: Application) => + formatGender(getSelectedChild(application)?.genderCode), + }, + { + placeholder: + newPrimarySchoolMessages.childrenNParents + .childInfoGenderPlaceholder, + optionsType: OptionsType.GENDER, + isMulti: false, + }, + ), + buildCustomField( + { + id: 'childInfo.pronouns', + title: newPrimarySchoolMessages.childrenNParents.childInfoPronouns, + component: 'FriggOptionsAsyncSelectField', + defaultValue: (application: Application) => + getApplicationExternalData(application.externalData) + .childInformation.pronouns, + }, + { + optionsType: OptionsType.PRONOUN, + placeholder: + newPrimarySchoolMessages.childrenNParents + .childInfoPronounsPlaceholder, + }, + ), buildRadioField({ id: 'childInfo.differentPlaceOfResidence', title: diff --git a/libs/application/templates/new-primary-school/src/hooks/useFriggOptions.ts b/libs/application/templates/new-primary-school/src/hooks/useFriggOptions.ts index 6ffc96650427..0b277a9054f2 100644 --- a/libs/application/templates/new-primary-school/src/hooks/useFriggOptions.ts +++ b/libs/application/templates/new-primary-school/src/hooks/useFriggOptions.ts @@ -17,7 +17,10 @@ export const useFriggOptions = (type?: OptionsType) => { return ( data?.friggOptions?.flatMap(({ options }) => options.flatMap(({ value, key }) => { - const content = value.find(({ language }) => language === lang)?.content + let content = value.find(({ language }) => language === lang)?.content + if (!content) { + content = value.find(({ language }) => language === 'is')?.content + } return { value: key ?? '', label: content ?? '' } }), ) ?? [] diff --git a/libs/application/templates/new-primary-school/src/lib/constants.ts b/libs/application/templates/new-primary-school/src/lib/constants.ts index 6576edfb101f..aa9db8e42f2e 100644 --- a/libs/application/templates/new-primary-school/src/lib/constants.ts +++ b/libs/application/templates/new-primary-school/src/lib/constants.ts @@ -43,10 +43,11 @@ export enum SiblingRelationOptions { STEP_SIBLING = 'stepSibling', } +// Mapping Þjóðskrá gender to Júní data export enum Gender { - FEMALE = 'FEMALE', - MALE = 'MALE', - OTHER = 'OTHER', + FEMALE = 'kvk', + MALE = 'kk', + OTHER = 'other', } export enum OptionsType { diff --git a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts index 42a43ecb66a2..811615786581 100644 --- a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts +++ b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts @@ -3,7 +3,6 @@ import * as kennitala from 'kennitala' import { parsePhoneNumberFromString } from 'libphonenumber-js' import { z } from 'zod' import { - Gender, ReasonForApplicationOptions, SiblingRelationOptions, } from './constants' @@ -25,7 +24,9 @@ export const dataSchema = z.object({ childNationalId: z.string().min(1), childInfo: z .object({ - gender: z.nativeEnum(Gender).optional(), + gender: z.string().optional(), + preferredName: z.string().optional(), + pronouns: z.array(z.string()).optional(), differentPlaceOfResidence: z.enum([YES, NO]), placeOfResidence: z .object({ diff --git a/libs/application/templates/new-primary-school/src/lib/messages.ts b/libs/application/templates/new-primary-school/src/lib/messages.ts index 456d9729b207..f10cf5f2407f 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -105,21 +105,6 @@ export const newPrimarySchoolMessages: MessageDir = { defaultMessage: 'Veldu skóla', description: 'Select school', }, - male: { - id: 'dess.nps.application:gender.male', - defaultMessage: 'Karlkyns', - description: 'Male', - }, - female: { - id: 'dess.nps.application:gender.female', - defaultMessage: 'Kvenkyns', - description: 'Female', - }, - otherGender: { - id: 'dess.nps.application:gender.other', - defaultMessage: 'Kynsegin/Annað', - description: 'non-binary/Other', - }, }), pre: defineMessages({ @@ -215,11 +200,21 @@ export const newPrimarySchoolMessages: MessageDir = { 'Athugaðu hvort upplýsingarnar séu réttar áður en þú heldur áfram.', description: 'Check that the information is correct before proceeding.', }, - childInfoChosenName: { - id: 'dess.nps.application:childrenNParents.child.info.chosen.name', + childInfoPreferredName: { + id: 'dess.nps.application:childrenNParents.child.info.preferred.name', defaultMessage: 'Valið nafn', description: 'Preferred name', }, + childInfoPronouns: { + id: 'dess.nps.application:childrenNParents.child.info.pronouns', + defaultMessage: 'Fornafn', + description: 'Pronoun', + }, + childInfoPronounsPlaceholder: { + id: 'dess.nps.application:childrenNParents.child.info.pronouns.placeholder', + defaultMessage: 'Veldu fornafn', + description: 'Select pronoun', + }, childInfoGender: { id: 'dess.nps.application:childrenNParents.child.info.gender', defaultMessage: 'Kyn', diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index 7ac9832d80bf..b3415b24c601 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -357,21 +357,6 @@ export const getSiblingRelationOptionLabel = ( return relationOptions.find((option) => option.value === value)?.label ?? '' } -export const getGenderOptions = () => [ - { - value: Gender.MALE, - label: newPrimarySchoolMessages.shared.male, - }, - { - value: Gender.FEMALE, - label: newPrimarySchoolMessages.shared.female, - }, - { - value: Gender.OTHER, - label: newPrimarySchoolMessages.shared.otherGender, - }, -] - export const formatGender = (genderCode?: string): Gender | undefined => { switch (genderCode) { case '1': @@ -388,11 +373,6 @@ export const formatGender = (genderCode?: string): Gender | undefined => { } } -export const getGenderOptionLabel = (value: Gender) => { - const genderOptions = getGenderOptions() - return genderOptions.find((option) => option.value === value)?.label ?? '' -} - export const getOptionsListByType = async ( apolloClient: ApolloClient, type: string, @@ -413,7 +393,10 @@ export const getOptionsListByType = async ( return ( data?.friggOptions?.flatMap(({ options }) => options.flatMap(({ value, key }) => { - const content = value.find(({ language }) => language === lang)?.content + let content = value.find(({ language }) => language === lang)?.content + if (!content) { + content = value.find(({ language }) => language === 'is')?.content + } return { value: key ?? '', label: content ?? '' } }), ) ?? [] diff --git a/libs/application/templates/new-primary-school/src/types.ts b/libs/application/templates/new-primary-school/src/types.ts index 80dce1a4e3d0..50d0772b867a 100644 --- a/libs/application/templates/new-primary-school/src/types.ts +++ b/libs/application/templates/new-primary-school/src/types.ts @@ -1,5 +1,4 @@ import { - Gender, MembershipOrganizationType, MembershipRole, SiblingRelationOptions, @@ -37,8 +36,9 @@ export type ChildInformation = { postalCode: string city: string } - gender: Gender - chosenName: string + gender: string + preferredName: string + pronouns: string[] differentPlaceOfResidence: string placeOfResidence?: { streetAddress: string From e668d0a5731571cc1352fe07b779b24d31314cd8 Mon Sep 17 00:00:00 2001 From: Veronika Sif Date: Fri, 6 Sep 2024 13:42:35 +0000 Subject: [PATCH 10/22] Update Frigg service path --- charts/islandis/values.dev.yaml | 4 +- charts/islandis/values.prod.yaml | 4 +- charts/islandis/values.staging.yaml | 4 +- infra/src/dsl/xroad.ts | 6 +- libs/clients/mms/frigg/project.json | 2 +- libs/clients/mms/frigg/src/clientConfig.json | 134 ++++++++++++------ .../mms/frigg/src/lib/friggClient.config.ts | 2 +- 7 files changed, 98 insertions(+), 58 deletions(-) diff --git a/charts/islandis/values.dev.yaml b/charts/islandis/values.dev.yaml index af8f99c4d36f..ee6bd3e4d65a 100644 --- a/charts/islandis/values.dev.yaml +++ b/charts/islandis/values.dev.yaml @@ -365,7 +365,7 @@ api: XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS-DEV/EDU/10049/LHI-Protected/brautskraning-v1' XROAD_INNA_PATH: 'IS-DEV/GOV/10066/MMS-Protected/inna-v1' XROAD_INTELLECTUAL_PROPERTIES_PATH: 'IS-DEV/GOV/10030/WebAPI-Public/HUG-webAPI/' - XROAD_MMS_FRIGG_PATH: 'IS-DEV/GOV/10066/MMS-Protected/frigg-api' + XROAD_MMS_FRIGG_PATH: 'IS-DEV/GOV/10066/MMS-Protected/frigg-form-service' XROAD_MMS_GRADE_SERVICE_ID: 'IS-DEV/GOV/10066/MMS-Protected/grade-api-v1' XROAD_MMS_LICENSE_SERVICE_ID: 'IS-DEV/GOV/10066/MMS-Protected/license-api-v1' XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379"]' @@ -642,7 +642,7 @@ application-system-api: XROAD_HOLAR_UNIVERSITY_PATH: 'IS-DEV/EDU/10055/Holar-Protected/brautskraning-v1' XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS-DEV/EDU/10049/LHI-Protected/brautskraning-v1' XROAD_INNA_PATH: 'IS-DEV/GOV/10066/MMS-Protected/inna-v1' - XROAD_MMS_FRIGG_PATH: 'IS-DEV/GOV/10066/MMS-Protected/frigg-api' + XROAD_MMS_FRIGG_PATH: 'IS-DEV/GOV/10066/MMS-Protected/frigg-form-service' XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379"]' XROAD_NATIONAL_REGISTRY_SERVICE_PATH: 'IS-DEV/GOV/10001/SKRA-Protected/Einstaklingar-v1' XROAD_OFFICIAL_JOURNAL_APPLICATION_PATH: 'IS-DEV/GOV/10014/DMR-Protected/official-journal-application' diff --git a/charts/islandis/values.prod.yaml b/charts/islandis/values.prod.yaml index c47adc3b38ed..2b26d1904eaf 100644 --- a/charts/islandis/values.prod.yaml +++ b/charts/islandis/values.prod.yaml @@ -355,7 +355,7 @@ api: XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS/EDU/4210984099/LHI-Protected/brautskraning-v1' XROAD_INNA_PATH: 'IS/GOV/6601241280/MMS-Protected/inna-v1' XROAD_INTELLECTUAL_PROPERTIES_PATH: 'IS/GOV/6501912189/WebAPI-Public/HUG-webAPI/' - XROAD_MMS_FRIGG_PATH: 'IS/GOV/10066/MMS-Protected/frigg-api' + XROAD_MMS_FRIGG_PATH: 'IS/GOV/10066/MMS-Protected/frigg-form-service' XROAD_MMS_GRADE_SERVICE_ID: 'IS/GOV/6601241280/MMS-Protected/grade-api-v1' XROAD_MMS_LICENSE_SERVICE_ID: 'IS/GOV/6601241280/MMS-Protected/license-api-v1' XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.whakos.euw1.cache.amazonaws.com:6379"]' @@ -632,7 +632,7 @@ application-system-api: XROAD_HOLAR_UNIVERSITY_PATH: 'IS/EDU/5001694359/Holar-Protected/brautskraning-v1' XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS/EDU/4210984099/LHI-Protected/brautskraning-v1' XROAD_INNA_PATH: 'IS/GOV/6601241280/MMS-Protected/inna-v1' - XROAD_MMS_FRIGG_PATH: 'IS/GOV/10066/MMS-Protected/frigg-api' + XROAD_MMS_FRIGG_PATH: 'IS/GOV/10066/MMS-Protected/frigg-form-service' XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.whakos.euw1.cache.amazonaws.com:6379"]' XROAD_NATIONAL_REGISTRY_SERVICE_PATH: 'IS/GOV/6503760649/SKRA-Protected/Einstaklingar-v1' XROAD_OFFICIAL_JOURNAL_APPLICATION_PATH: 'IS/GOV/10014/DMR-Protected/official-journal-application' diff --git a/charts/islandis/values.staging.yaml b/charts/islandis/values.staging.yaml index b25e6403014a..6ad96ce67465 100644 --- a/charts/islandis/values.staging.yaml +++ b/charts/islandis/values.staging.yaml @@ -365,7 +365,7 @@ api: XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS-TEST/EDU/10049/LHI-Protected/brautskraning-v1' XROAD_INNA_PATH: 'IS-TEST/GOV/6601241280/MMS-Protected/inna-v1' XROAD_INTELLECTUAL_PROPERTIES_PATH: 'IS-TEST/GOV/6501912189/WebAPI-Public/HUG-webAPI/' - XROAD_MMS_FRIGG_PATH: 'IS-TEST/GOV/10066/MMS-Protected/frigg-api' + XROAD_MMS_FRIGG_PATH: 'IS-TEST/GOV/10066/MMS-Protected/frigg-form-service' XROAD_MMS_GRADE_SERVICE_ID: 'IS-TEST/GOV/6601241280/MMS-Protected/grade-api-v1' XROAD_MMS_LICENSE_SERVICE_ID: 'IS-TEST/GOV/6601241280/MMS-Protected/license-api-v1' XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379"]' @@ -640,7 +640,7 @@ application-system-api: XROAD_HOLAR_UNIVERSITY_PATH: 'IS-TEST/EDU/10055/Holar-Protected/brautskraning-v1' XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS-TEST/EDU/10049/LHI-Protected/brautskraning-v1' XROAD_INNA_PATH: 'IS-TEST/GOV/6601241280/MMS-Protected/inna-v1' - XROAD_MMS_FRIGG_PATH: 'IS-TEST/GOV/10066/MMS-Protected/frigg-api' + XROAD_MMS_FRIGG_PATH: 'IS-TEST/GOV/10066/MMS-Protected/frigg-form-service' XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379"]' XROAD_NATIONAL_REGISTRY_SERVICE_PATH: 'IS-TEST/GOV/6503760649/SKRA-Protected/Einstaklingar-v1' XROAD_OFFICIAL_JOURNAL_APPLICATION_PATH: 'IS-TEST/GOV/10014/DMR-Protected/official-journal-application' diff --git a/infra/src/dsl/xroad.ts b/infra/src/dsl/xroad.ts index a61c0e718b27..00fd067b6a2b 100644 --- a/infra/src/dsl/xroad.ts +++ b/infra/src/dsl/xroad.ts @@ -884,9 +884,9 @@ export const OfficialJournalOfIcelandApplication = new XroadConf({ export const Frigg = new XroadConf({ env: { XROAD_MMS_FRIGG_PATH: { - dev: 'IS-DEV/GOV/10066/MMS-Protected/frigg-api', - staging: 'IS-TEST/GOV/10066/MMS-Protected/frigg-api', - prod: 'IS/GOV/10066/MMS-Protected/frigg-api', + dev: 'IS-DEV/GOV/10066/MMS-Protected/frigg-form-service', + staging: 'IS-TEST/GOV/10066/MMS-Protected/frigg-form-service', + prod: 'IS/GOV/10066/MMS-Protected/frigg-form-service', }, }, }) diff --git a/libs/clients/mms/frigg/project.json b/libs/clients/mms/frigg/project.json index 333343cfaecd..d67cd8a8c925 100644 --- a/libs/clients/mms/frigg/project.json +++ b/libs/clients/mms/frigg/project.json @@ -22,7 +22,7 @@ "executor": "nx:run-commands", "options": { "commands": [ - "curl -H \"X-Road-Client: IS-DEV/GOV/10000/island-is-client\" http://localhost:8081/r1/IS-DEV/GOV/10066/MMS-Protected/getOpenAPI?serviceCode=frigg-api > src/clientConfig.json", + "curl -H \"X-Road-Client: IS-DEV/GOV/10000/island-is-client\" http://localhost:8081/r1/IS-DEV/GOV/10066/MMS-Protected/getOpenAPI?serviceCode=frigg-form-service > src/clientConfig.json", "prettier --write src/clientConfig.json" ], "parallel": false, diff --git a/libs/clients/mms/frigg/src/clientConfig.json b/libs/clients/mms/frigg/src/clientConfig.json index 6e64a4ecbca3..f216c079d12c 100644 --- a/libs/clients/mms/frigg/src/clientConfig.json +++ b/libs/clients/mms/frigg/src/clientConfig.json @@ -18,12 +18,15 @@ "description": "", "content": { "application/json": { - "schema": { "$ref": "#/components/schemas/SuccessModel" } + "schema": { + "$ref": "#/components/schemas/FormSubmitSuccessModel" + } } } } }, - "tags": ["Frigg"] + "tags": ["Frigg"], + "security": [{ "bearer": [] }] } }, "/forms/types": { @@ -42,10 +45,39 @@ } } }, - "tags": ["Frigg"] + "tags": ["Frigg"], + "security": [{ "bearer": [] }] + } + }, + "/forms/reviews/{reviewId}/{action}": { + "post": { + "operationId": "updateReview", + "summary": "Review form", + "description": "Review form.", + "parameters": [ + { + "name": "reviewId", + "required": true, + "in": "path", + "schema": { "type": "string" } + }, + { "name": "action", "required": true, "in": "path", "schema": { "type": "string" } } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/SuccessModel" } + } + } + } + }, + "tags": ["Frigg"], + "security": [{ "bearer": [] }] } }, - "/keyOptions": { + "/key-options": { "get": { "operationId": "getAllKeyOptions", "summary": "Get all key options.", @@ -75,7 +107,7 @@ "tags": ["Frigg"] } }, - "/keyOptions/types": { + "/key-options/types": { "get": { "operationId": "getKeyOptionsTypes", "summary": "Get list of types of key options", @@ -121,15 +153,14 @@ } } }, - "tags": ["Frigg"], - "security": [{ "bearer": [] }] + "tags": ["Frigg"] } }, - "/student/{nationalId}": { + "/students/{nationalId}": { "get": { "operationId": "getUserBySourcedId", "summary": "Get user by nationalId", - "description": "Get user by Id. ", + "description": "Get user by Id.", "parameters": [ { "name": "nationalId", @@ -154,7 +185,7 @@ } }, "info": { - "title": "MMS Internal API", + "title": "MMS FORM SERVICE API", "description": "Frigg - student information system", "version": "1", "contact": {} @@ -186,15 +217,10 @@ "nationalId": { "type": "string" }, "preferredName": { "type": "string" }, "pronouns": { "type": "array", "items": { "type": "string" } }, - "address": { "$ref": "#/components/schemas/AddressDto" } + "domicile": { "$ref": "#/components/schemas/AddressDto" }, + "residence": { "$ref": "#/components/schemas/AddressDto" } }, - "required": [ - "name", - "nationalId", - "preferredName", - "pronouns", - "address" - ] + "required": ["name", "nationalId"] }, "AgentDto": { "type": "object", @@ -203,41 +229,43 @@ "nationalId": { "type": "string" }, "preferredName": { "type": "string" }, "pronouns": { "type": "array", "items": { "type": "string" } }, - "address": { "$ref": "#/components/schemas/AddressDto" }, - "email": { "type": "string" }, + "domicile": { "$ref": "#/components/schemas/AddressDto" }, + "email": { "type": "string", "example": "name@frigg.is" }, "phone": { "type": "string" }, - "relation": { "type": "string" } + "role": { + "type": "string", + "description": "Agents connection to the student, strings can be found under key option type \"relation\"" + } }, - "required": [ - "name", - "nationalId", - "preferredName", - "pronouns", - "address", - "email", - "phone", - "relation" - ] + "required": ["name", "nationalId", "role"] }, "RegistrationDto": { "type": "object", "properties": { - "preRegisteredId": { "type": "string" }, - "defaultOrg": { "type": "string" }, - "selectedOrg": { "type": "string" }, + "preRegisteredId": { + "type": "string", + "description": "If a user has an open ongoing registration, for exaple first year students submit the id here" + }, + "defaultOrg": { + "type": "string", + "description": "The school a student should or does belong to, pre registered school or current school" + }, + "selectedOrg": { + "type": "string", + "description": "The school selected for a student in the application process" + }, "requestingMeeting": { "type": "boolean", "default": false }, "expectedStartDate": { "format": "date-time", "type": "string" }, "reason": { "type": "string" }, - "movingAbroadCountry": { "type": "string" } + "movingAbroadCountry": { "type": "string" }, + "newDomicile": { "$ref": "#/components/schemas/AddressDto" } }, "required": [ - "preRegisteredId", "defaultOrg", "selectedOrg", "requestingMeeting", "expectedStartDate", - "reason", - "movingAbroadCountry" + "reason" ] }, "HealthDto": { @@ -246,16 +274,14 @@ "usesEpipen": { "type": "boolean", "default": false }, "allergies": { "type": "array", "items": { "type": "string" } }, "intolerances": { "type": "array", "items": { "type": "string" } } - }, - "required": ["usesEpipen", "allergies", "intolerances"] + } }, "SocialDto": { "type": "object", "properties": { "hasHadSupport": { "type": "boolean", "default": false }, "hasDiagnoses": { "type": "boolean", "default": false } - }, - "required": ["hasHadSupport", "hasDiagnoses"] + } }, "LanguageDto": { "type": "object", @@ -264,7 +290,7 @@ "noIcelandic": { "type": "boolean" }, "otherLanguages": { "type": "array", "items": { "type": "string" } } }, - "required": ["nativeLanguage", "noIcelandic", "otherLanguages"] + "required": ["nativeLanguage", "noIcelandic"] }, "FormDto": { "type": "object", @@ -290,6 +316,15 @@ "language" ] }, + "FormSubmitSuccessModel": { + "type": "object", + "properties": { + "formId": { "type": "string", "description": "Id of form created" }, + "reviewId": { "type": "string", "description": "Id of review" }, + "status": { "type": "string", "description": "Status of form" } + }, + "required": ["formId", "reviewId", "status"] + }, "SuccessModel": { "type": "object", "properties": { @@ -448,7 +483,7 @@ "phone": { "type": "string" }, "email": { "type": "string" }, "role": { "type": "string" }, - "address": { + "domicile": { "nullable": true, "allOf": [{ "$ref": "#/components/schemas/AddressModel" }] } @@ -460,7 +495,7 @@ "phone", "email", "role", - "address" + "domicile" ] }, "UserModel": { @@ -473,7 +508,11 @@ "pronouns": { "type": "array", "items": { "type": "string" } }, "gradeLevels": { "type": "array", "items": { "type": "string" } }, "email": { "type": "object", "nullable": true }, - "address": { + "domicile": { + "nullable": true, + "allOf": [{ "$ref": "#/components/schemas/AddressModel" }] + }, + "residence": { "nullable": true, "allOf": [{ "$ref": "#/components/schemas/AddressModel" }] }, @@ -495,7 +534,8 @@ "pronouns", "gradeLevels", "email", - "address", + "domicile", + "residence", "primaryOrgId", "memberships", "agents" diff --git a/libs/clients/mms/frigg/src/lib/friggClient.config.ts b/libs/clients/mms/frigg/src/lib/friggClient.config.ts index 300f2cd6d438..8889c509c261 100644 --- a/libs/clients/mms/frigg/src/lib/friggClient.config.ts +++ b/libs/clients/mms/frigg/src/lib/friggClient.config.ts @@ -13,7 +13,7 @@ export const FriggClientConfig = defineConfig>({ load: (env) => ({ xRoadServicePath: env.required( 'XROAD_MMS_FRIGG_PATH', - 'IS-DEV/GOV/10066/MMS-Protected/frigg-api', + 'IS-DEV/GOV/10066/MMS-Protected/frigg-form-service', ), scope: [MMSScope.frigg], }), From d0eb54b31725c81dfe5649a4911d0bd7c7aca3c3 Mon Sep 17 00:00:00 2001 From: Veronika Sif Date: Mon, 9 Sep 2024 16:25:53 +0000 Subject: [PATCH 11/22] Update clientConfig --- libs/clients/mms/frigg/src/clientConfig.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/clients/mms/frigg/src/clientConfig.json b/libs/clients/mms/frigg/src/clientConfig.json index f216c079d12c..a2e2e87a7223 100644 --- a/libs/clients/mms/frigg/src/clientConfig.json +++ b/libs/clients/mms/frigg/src/clientConfig.json @@ -518,10 +518,12 @@ }, "primaryOrgId": { "type": "object" }, "memberships": { + "nullable": true, "type": "array", "items": { "$ref": "#/components/schemas/MembershipModel" } }, "agents": { + "nullable": true, "type": "array", "items": { "$ref": "#/components/schemas/AgentModel" } } From d9df37440dcd152437c3713eef297b4482994f1b Mon Sep 17 00:00:00 2001 From: veronikasif <54938148+veronikasif@users.noreply.github.com> Date: Tue, 17 Sep 2024 08:18:34 +0000 Subject: [PATCH 12/22] feat(new-primary-school): Implement no children found page (#15909) * [TS-816] Implement no children found page * Remove comments --- .../new-primary-school.service.ts | 43 ++++++++++++++- .../src/dataProviders/index.ts | 6 +++ .../childInfoSubSection.ts | 6 --- .../forms/Prerequisites/childrenSubSection.ts | 21 +++----- .../Prerequisites/externalDataSubSection.ts | 4 +- .../src/lib/NewPrimarySchoolTemplate.ts | 4 +- .../new-primary-school/src/lib/messages.ts | 13 +++++ .../src/lib/newPrimarySchoolUtils.spec.ts | 53 ++----------------- .../src/lib/newPrimarySchoolUtils.ts | 22 +------- .../templates/new-primary-school/src/types.ts | 1 - 10 files changed, 78 insertions(+), 95 deletions(-) diff --git a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts index 2739d28b946a..1b6a9f106270 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts @@ -1,8 +1,14 @@ -import { getApplicationAnswers } from '@island.is/application/templates/new-primary-school' +import { NationalRegistryXRoadService } from '@island.is/api/domains/national-registry-x-road' +import { + errorMessages, + getApplicationAnswers, +} from '@island.is/application/templates/new-primary-school' import { ApplicationTypes } from '@island.is/application/types' import { FriggClientService } from '@island.is/clients/mms/frigg' import { LOGGER_PROVIDER } from '@island.is/logging' +import { TemplateApiError } from '@island.is/nest/problem' import { Inject, Injectable } from '@nestjs/common' +import * as kennitala from 'kennitala' import { TemplateApiModuleActionProps } from '../../../types' import { BaseTemplateApiService } from '../../base-template-api.service' @@ -11,6 +17,7 @@ export class NewPrimarySchoolService extends BaseTemplateApiService { constructor( @Inject(LOGGER_PROVIDER) private logger: Logger, private readonly friggClientService: FriggClientService, + private readonly nationalRegistryService: NationalRegistryXRoadService, ) { super(ApplicationTypes.NEW_PRIMARY_SCHOOL) } @@ -35,4 +42,38 @@ export class NewPrimarySchoolService extends BaseTemplateApiService { return await this.friggClientService.getUserById(auth, childNationalId) } + + async getChildren({ auth }: TemplateApiModuleActionProps) { + const children = + await this.nationalRegistryService.getChildrenCustodyInformation(auth) + + const currentYear = new Date().getFullYear() + const maxYear = currentYear - 7 // 2nd grade + const minYear = currentYear - 16 // 10th grade + + // Check if the child is at primary school age and lives with the applicant + const filteredChildren = children.filter((child) => { + const yearOfBirth = kennitala + .info(child.nationalId) + .birthday.getFullYear() + + return ( + child.livesWithApplicant && + yearOfBirth >= minYear && + yearOfBirth <= maxYear + ) + }) + + if (filteredChildren.length === 0) { + throw new TemplateApiError( + { + title: errorMessages.noChildrenFoundTitle, + summary: errorMessages.noChildrenFoundMessage, + }, + 400, + ) + } + + return filteredChildren + } } diff --git a/libs/application/templates/new-primary-school/src/dataProviders/index.ts b/libs/application/templates/new-primary-school/src/dataProviders/index.ts index 91b3cf1cc7cd..7fc7818694ac 100644 --- a/libs/application/templates/new-primary-school/src/dataProviders/index.ts +++ b/libs/application/templates/new-primary-school/src/dataProviders/index.ts @@ -20,3 +20,9 @@ export const OptionsApi = defineTemplateApi({ externalDataId: 'KeyOptions', namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, }) + +export const ChildrenApi = defineTemplateApi({ + action: 'getChildren', + externalDataId: 'children', + namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, +}) diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts index bf76f25e1769..73bef63ca346 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts @@ -48,8 +48,6 @@ export const childInfoSubSection = buildSubSection({ title: newPrimarySchoolMessages.shared.address, width: 'half', disabled: true, - // TODO: Nota gögn frá Júní - // TODO: Hægt að nota heimilisfang innskráðs foreldris? (foreldri getur ekki sótt um nema barn sé með sama lögheimili) defaultValue: (application: Application) => getApplicationExternalData(application.externalData) .applicantAddress, @@ -59,8 +57,6 @@ export const childInfoSubSection = buildSubSection({ title: newPrimarySchoolMessages.shared.postalCode, width: 'half', disabled: true, - // TODO: Nota gögn frá Júní - // TODO: Hægt að nota heimilisfang innskráðs foreldris? (foreldri getur ekki sótt um nema barn sé með sama lögheimili) defaultValue: (application: Application) => getApplicationExternalData(application.externalData) .applicantPostalCode, @@ -70,8 +66,6 @@ export const childInfoSubSection = buildSubSection({ title: newPrimarySchoolMessages.shared.municipality, width: 'half', disabled: true, - // TODO: Nota gögn frá Júní - // TODO: Hægt að nota heimilisfang innskráðs foreldris? (foreldri getur ekki sótt um nema barn sé með sama lögheimili) defaultValue: (application: Application) => getApplicationExternalData(application.externalData).applicantCity, }), diff --git a/libs/application/templates/new-primary-school/src/forms/Prerequisites/childrenSubSection.ts b/libs/application/templates/new-primary-school/src/forms/Prerequisites/childrenSubSection.ts index 6c0d08869fd2..25989a1c2999 100644 --- a/libs/application/templates/new-primary-school/src/forms/Prerequisites/childrenSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/Prerequisites/childrenSubSection.ts @@ -7,10 +7,7 @@ import { import { DefaultEvents } from '@island.is/application/types' import { format as formatKennitala } from 'kennitala' import { newPrimarySchoolMessages } from '../../lib/messages' -import { - canApply, - getApplicationExternalData, -} from '../../lib/newPrimarySchoolUtils' +import { getApplicationExternalData } from '../../lib/newPrimarySchoolUtils' export const childrenSubSection = buildSubSection({ id: 'childrenSubSection', @@ -29,15 +26,13 @@ export const childrenSubSection = buildSubSection({ application.externalData, ) - return children - .filter((child) => canApply(child)) - .map((child) => { - return { - value: child.nationalId, - label: child.fullName, - subLabel: formatKennitala(child.nationalId), - } - }) + return children.map((child) => { + return { + value: child.nationalId, + label: child.fullName, + subLabel: formatKennitala(child.nationalId), + } + }) }, required: true, }), diff --git a/libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts b/libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts index 8ab6193df011..9dd64a5d7a32 100644 --- a/libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts @@ -4,11 +4,11 @@ import { buildSubSection, } from '@island.is/application/core' import { - ChildrenCustodyInformationApi, NationalRegistryUserApi, UserProfileApi, } from '@island.is/application/types' import { + ChildrenApi, GetKeyOptionsTypesApi, GetSchoolsApi, OptionsApi, @@ -32,7 +32,7 @@ export const externalDataSubSection = buildSubSection({ newPrimarySchoolMessages.pre.nationalRegistryInformationSubTitle, }), buildDataProviderItem({ - provider: ChildrenCustodyInformationApi, + provider: ChildrenApi, title: '', subTitle: '', }), diff --git a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts index 3af95bf6f1ff..12a12f3d1886 100644 --- a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts +++ b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts @@ -12,7 +12,6 @@ import { ApplicationStateSchema, ApplicationTemplate, ApplicationTypes, - ChildrenCustodyInformationApi, DefaultEvents, NationalRegistryUserApi, UserProfileApi, @@ -22,6 +21,7 @@ import { Features } from '@island.is/feature-flags' import unset from 'lodash/unset' import { assign } from 'xstate' import { + ChildrenApi, GetKeyOptionsTypesApi, GetSchoolsApi, OptionsApi, @@ -85,12 +85,12 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< write: 'all', delete: true, api: [ - ChildrenCustodyInformationApi, NationalRegistryUserApi, UserProfileApi, GetKeyOptionsTypesApi, OptionsApi, GetSchoolsApi, + ChildrenApi, ], }, ], diff --git a/libs/application/templates/new-primary-school/src/lib/messages.ts b/libs/application/templates/new-primary-school/src/lib/messages.ts index f10cf5f2407f..92e4d9df758e 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -839,4 +839,17 @@ export const errorMessages = defineMessages({ defaultMessage: 'Það þarf að velja a.m.k eitt fæðuóþol', description: 'At least one food intolerance must be selected', }, + noChildrenFoundTitle: { + id: 'dess.nps.application:error.no.children.found.title', + defaultMessage: 'Því miður ert þú ekki með skráð barn á grunnskólaaldri', + description: + 'Unfortunately, you do not have a child registered at primary school age', + }, + noChildrenFoundMessage: { + id: 'dess.nps.application:error.no.children.found.message#markdown', + defaultMessage: + 'Eingöngu sá sem er með lögheimilisforsjá hefur heimild til að sækja um fyrir barn. \n\nÞjóðskrá skráir hver eða hverjir teljast foreldrar barns og hver fari með forsjárskyldur þess. Upplýsingar um skráningu forsjár og lögheimilisforeldris má nálgast hér: [Foreldrar og forsjá | Þjóðskrá (skra.is)](https://www.skra.is/folk/skraning-barns/foreldrar-og-forsja/)\n\nUpplýsingum um tengsl á milli barna og foreldra auk forsjáraðila eru einnig aðgengilegar á [Mínum síðum á Ísland.is](https://island.is/minarsidur)', + description: + 'Only the person who has legal custody has the authority to apply for a child.\n\nThe National Registry records who or which individuals are considered to be the parents of a child and who has custody responsibilities. Information on registering custody and legal guardianship can be found here: [Parents and Custody | National Registry (skra.is)](https://www.skra.is/folk/skraning-barns/foreldrar-og-forsja/)\n\nInformation about the relationship between children and parents, as well as custody authorities, is also available on [My Pages on Ísland.is](https://island.is/minarsidur)', + }, }) diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.spec.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.spec.ts index 123ba82b26c6..a6ba6347e256 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.spec.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.spec.ts @@ -1,58 +1,11 @@ import { ExternalData } from '@island.is/application/types' -import { Child } from '../types' -import { canApply, hasOtherParent } from './newPrimarySchoolUtils' -import * as kennitala from 'kennitala' - -describe('canApply', () => { - const getNationalId = (years: number) => { - const currentDate = new Date() - const fithteenYearsAgo = new Date( - currentDate.getFullYear() - years, - currentDate.getMonth(), - currentDate.getDate(), - ) - - return kennitala.generatePerson(fithteenYearsAgo) - } - - it('should return true if child is between 5 and 15 years old and lives with applicant', () => { - const child = { - nationalId: getNationalId(15), - livesWithApplicant: true, - } as Child - expect(canApply(child)).toBe(true) - }) - - it('should return false if child is younger than 5 years old', () => { - const child = { - nationalId: getNationalId(4), - livesWithApplicant: true, - } as Child - expect(canApply(child)).toBe(false) - }) - - it('should return false if child is older than 15 years old', () => { - const child = { - nationalId: getNationalId(16), - livesWithApplicant: true, - } as Child - expect(canApply(child)).toBe(false) - }) - - it('should return false if child does not live with applicant', () => { - const child = { - nationalId: getNationalId(8), - livesWithApplicant: false, - } as Child - expect(canApply(child)).toBe(false) - }) -}) +import { hasOtherParent } from './newPrimarySchoolUtils' describe('hasOtherParent', () => { it('should return true if otherParent exists in externalData', () => { const answers = {} const externalData = { - childrenCustodyInformation: { + children: { data: [ { fullName: 'Stúfur Maack ', @@ -71,7 +24,7 @@ describe('hasOtherParent', () => { it('should return false if otherParent does not exist in externalData', () => { const answers = {} const externalData = { - childrenCustodyInformation: { + children: { data: [ { fullName: 'Stúfur Maack ', diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index b3415b24c601..6014f17d9803 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -6,7 +6,6 @@ import { YesOrNo, } from '@island.is/application/types' import { Locale } from '@island.is/shared/types' -import * as kennitala from 'kennitala' import { Child, ChildInformation, @@ -188,11 +187,7 @@ export const getApplicationAnswers = (answers: Application['answers']) => { export const getApplicationExternalData = ( externalData: Application['externalData'], ) => { - const children = getValueViaPath( - externalData, - 'childrenCustodyInformation.data', - [], - ) as Child[] + const children = getValueViaPath(externalData, 'children.data', []) as Child[] const applicantName = getValueViaPath( externalData, @@ -221,7 +216,7 @@ export const getApplicationExternalData = ( const otherParentName = getValueViaPath( externalData, - 'childrenCustodyInformation.data.otherParent.fullName', + 'children.data.otherParent.fullName', ) as string const childInformation = getValueViaPath( @@ -241,19 +236,6 @@ export const getApplicationExternalData = ( } } -export const canApply = (child: Child): boolean => { - // Check if the child is at primary school age and lives with the applicant - if ( - kennitala.info(child.nationalId).age >= 5 && - kennitala.info(child.nationalId).age <= 15 && - child.livesWithApplicant - ) { - return true - } - - return false -} - export const getSelectedChild = (application: Application) => { const { childNationalId } = getApplicationAnswers(application.answers) const { children } = getApplicationExternalData(application.externalData) diff --git a/libs/application/templates/new-primary-school/src/types.ts b/libs/application/templates/new-primary-school/src/types.ts index 50d0772b867a..da7b33e7543f 100644 --- a/libs/application/templates/new-primary-school/src/types.ts +++ b/libs/application/templates/new-primary-school/src/types.ts @@ -23,7 +23,6 @@ export type Child = { nationalId: string otherParent: object livesWithApplicant: boolean - domicileInIceland: boolean livesWithBothParents: boolean genderCode: string } From d78f21bdb8fa709511a4a180fa7f145cf3b2f598 Mon Sep 17 00:00:00 2001 From: veronikasif <54938148+veronikasif@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:38:42 +0000 Subject: [PATCH 13/22] feat(new-primary): Update new primary school application (#15849) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [TS-883] Remove 'Má sækja barn' - Relatives page * [TS-884] Remove gender - Child info page * [TS-885] Remove use of footage page * Update Child in Review --- .../fields/RelativesTableRepeater/index.tsx | 31 ++----- .../src/fields/Review/index.tsx | 2 - .../src/fields/Review/review-groups/Child.tsx | 19 +--- .../Review/review-groups/Photography.tsx | 64 ------------- .../fields/Review/review-groups/Relatives.tsx | 7 +- .../fields/Review/review-groups/Support.tsx | 1 + .../childInfoSubSection.ts | 20 ---- .../differentNeedsSection/index.ts | 2 - .../useOfFootageSubSection.ts | 91 ------------------- .../src/lib/NewPrimarySchoolTemplate.ts | 13 --- .../new-primary-school/src/lib/constants.ts | 7 -- .../new-primary-school/src/lib/dataSchema.ts | 21 ----- .../new-primary-school/src/lib/messages.ts | 69 -------------- .../src/lib/newPrimarySchoolUtils.ts | 36 -------- .../templates/new-primary-school/src/types.ts | 2 - 15 files changed, 10 insertions(+), 375 deletions(-) delete mode 100644 libs/application/templates/new-primary-school/src/fields/Review/review-groups/Photography.tsx delete mode 100644 libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/useOfFootageSubSection.ts diff --git a/libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx b/libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx index 07619b74980e..11fe686f9ce1 100644 --- a/libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx +++ b/libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx @@ -1,8 +1,7 @@ import { FieldBaseProps, FieldComponents, - FieldTypes, - YES, + FieldTypes } from '@island.is/application/types' import { formatPhoneNumber, @@ -16,9 +15,11 @@ import { OptionsType } from '../../lib/constants' import { newPrimarySchoolMessages } from '../../lib/messages' import { getSelectedOptionLabel } from '../../lib/newPrimarySchoolUtils' -const RelativesTableRepeater: FC< - React.PropsWithChildren -> = ({ error, field, application }) => { +const RelativesTableRepeater: FC> = ({ + error, + field, + application, +}) => { const { id, title } = field const relationFriggOptions = useFriggOptions(OptionsType.RELATION) @@ -77,20 +78,6 @@ const RelativesTableRepeater: FC< options: relationFriggOptions, dataTestId: 'relative-relation', }, - canPickUpChild: { - component: 'checkbox', - width: 'full', - large: true, - options: [ - { - label: - newPrimarySchoolMessages.childrenNParents - .relativesCanPickUpChild, - value: YES, - }, - ], - dataTestId: 'relative-can-pick-up-child', - }, }, table: { format: { @@ -99,18 +86,12 @@ const RelativesTableRepeater: FC< nationalId: (value) => formatKennitala(value), relation: (value) => getSelectedOptionLabel(relationFriggOptions, value) ?? '', - canPickUpChild: (value) => - value?.includes(YES) - ? newPrimarySchoolMessages.shared.yes - : newPrimarySchoolMessages.shared.no, }, header: [ newPrimarySchoolMessages.shared.fullName, newPrimarySchoolMessages.shared.phoneNumber, newPrimarySchoolMessages.shared.nationalId, newPrimarySchoolMessages.shared.relation, - newPrimarySchoolMessages.childrenNParents - .relativesCanPickUpChildTableHeader, ], }, }} diff --git a/libs/application/templates/new-primary-school/src/fields/Review/index.tsx b/libs/application/templates/new-primary-school/src/fields/Review/index.tsx index 4599570d8d9e..68ba915a6033 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/index.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/index.tsx @@ -20,7 +20,6 @@ import { AllergiesAndIntolerances } from './review-groups/AllergiesAndIntoleranc import { Child } from './review-groups/Child' import { Languages } from './review-groups/Languages' import { Parents } from './review-groups/Parents' -import { Photography } from './review-groups/Photography' import { ReasonForApplication } from './review-groups/ReasonForApplication' import { Relatives } from './review-groups/Relatives' import { Siblings } from './review-groups/Siblings' @@ -169,7 +168,6 @@ export const Review: FC = ({ - )} diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx index a79616cf3291..df7ed000027e 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Child.tsx @@ -22,7 +22,6 @@ export const Child = ({ application.answers, ) - const genderOptions = useFriggOptions(OptionsType.GENDER) const pronounOptions = useFriggOptions(OptionsType.PRONOUN) return ( @@ -68,9 +67,8 @@ export const Child = ({ /> - {(childInfo.gender || - childInfo.preferredName || - childInfo.pronouns || + {(childInfo.preferredName || + childInfo.pronouns?.length > 0 || differentPlaceOfResidence === YES) && ( {childInfo.preferredName && ( @@ -84,19 +82,6 @@ export const Child = ({ /> )} - {childInfo.gender && ( - - - - )} {childInfo.pronouns?.length > 0 && ( { - const { formatMessage } = useLocale() - const { photographyConsent, photoSchoolPublication, photoMediaPublication } = - getApplicationAnswers(application.answers) - - return ( - goToScreen?.('photography')} - isLast={true} - > - - - - - - - {photographyConsent === YES && ( - <> - - - - - - - - - - - - )} - - - ) -} diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Relatives.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Relatives.tsx index 2936074b1f1d..9377bdd34b49 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Relatives.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Relatives.tsx @@ -1,4 +1,4 @@ -import { FieldComponents, FieldTypes, YES } from '@island.is/application/types' +import { FieldComponents, FieldTypes } from '@island.is/application/types' import { Label, ReviewGroup, @@ -34,9 +34,6 @@ export const Relatives = ({ formatPhoneNumber(removeCountryCode(r.phoneNumber ?? '')), formatKennitala(r.nationalId), getSelectedOptionLabel(relationFriggOptions, r.relation) ?? '', - r.canPickUpChild?.includes(YES) - ? newPrimarySchoolMessages.shared.yes - : newPrimarySchoolMessages.shared.no, ] }) @@ -68,8 +65,6 @@ export const Relatives = ({ newPrimarySchoolMessages.shared.phoneNumber, newPrimarySchoolMessages.shared.nationalId, newPrimarySchoolMessages.shared.relation, - newPrimarySchoolMessages.childrenNParents - .relativesCanPickUpChildTableHeader, ], rows, }} diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Support.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Support.tsx index ec27b12a2c5a..32d079f5a28a 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Support.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/Support.tsx @@ -18,6 +18,7 @@ export const Support = ({ goToScreen?.('support')} + isLast={true} > diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts index 73bef63ca346..1e272d868fd0 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/childInfoSubSection.ts @@ -8,10 +8,8 @@ import { import { Application, NO, YES } from '@island.is/application/types' import { newPrimarySchoolMessages } from '../../../lib/messages' import { - formatGender, getApplicationAnswers, getApplicationExternalData, - getSelectedChild, } from '../../../lib/newPrimarySchoolUtils' import { OptionsType } from '../../../lib/constants' @@ -73,28 +71,10 @@ export const childInfoSubSection = buildSubSection({ id: 'childInfo.preferredName', title: newPrimarySchoolMessages.childrenNParents.childInfoPreferredName, - width: 'half', defaultValue: (application: Application) => getApplicationExternalData(application.externalData) .childInformation.preferredName ?? undefined, }), - buildCustomField( - { - id: 'childInfo.gender', - title: newPrimarySchoolMessages.childrenNParents.childInfoGender, - width: 'half', - component: 'FriggOptionsAsyncSelectField', - defaultValue: (application: Application) => - formatGender(getSelectedChild(application)?.genderCode), - }, - { - placeholder: - newPrimarySchoolMessages.childrenNParents - .childInfoGenderPlaceholder, - optionsType: OptionsType.GENDER, - isMulti: false, - }, - ), buildCustomField( { id: 'childInfo.pronouns', diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts index 4df41b1c2790..0e60db343854 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts @@ -5,7 +5,6 @@ import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' import { allergiesAndIntolerancesSubSection } from './allergiesAndIntolerancesSubSection' import { languageSubSection } from './languageSubSection' import { supportSubSection } from './supportSubSection' -import { useOfFootageSubSection } from './useOfFootageSubSection' export const differentNeedsSection = buildSection({ id: 'differentNeedsSection', @@ -19,6 +18,5 @@ export const differentNeedsSection = buildSection({ languageSubSection, allergiesAndIntolerancesSubSection, supportSubSection, - useOfFootageSubSection, ], }) diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/useOfFootageSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/useOfFootageSubSection.ts deleted file mode 100644 index 995dfbcf5552..000000000000 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/useOfFootageSubSection.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { - buildAlertMessageField, - buildMultiField, - buildRadioField, - buildSubSection, -} from '@island.is/application/core' -import { NO, YES } from '@island.is/application/types' -import { newPrimarySchoolMessages } from '../../../lib/messages' -import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' - -export const useOfFootageSubSection = buildSubSection({ - id: 'useOfFootageSubSection', - title: newPrimarySchoolMessages.differentNeeds.useOfFootageSubSectionTitle, - children: [ - buildMultiField({ - id: 'photography', - title: newPrimarySchoolMessages.differentNeeds.photography, - description: - newPrimarySchoolMessages.differentNeeds.photographyDescription, - children: [ - buildRadioField({ - id: 'photography.photographyConsent', - title: newPrimarySchoolMessages.differentNeeds.photographyConsent, - width: 'half', - required: true, - options: [ - { - label: newPrimarySchoolMessages.shared.yes, - dataTestId: 'yes-option', - value: YES, - }, - { - label: newPrimarySchoolMessages.shared.no, - dataTestId: 'no-option', - value: NO, - }, - ], - }), - buildRadioField({ - id: 'photography.photoSchoolPublication', - condition: (answers) => { - const { photographyConsent } = getApplicationAnswers(answers) - return photographyConsent === YES - }, - title: newPrimarySchoolMessages.differentNeeds.photoSchoolPublication, - width: 'half', - options: [ - { - label: newPrimarySchoolMessages.shared.yes, - dataTestId: 'yes-option', - value: YES, - }, - { - label: newPrimarySchoolMessages.shared.no, - dataTestId: 'no-option', - value: NO, - }, - ], - }), - buildRadioField({ - id: 'photography.photoMediaPublication', - condition: (answers) => { - const { photographyConsent } = getApplicationAnswers(answers) - return photographyConsent === YES - }, - title: newPrimarySchoolMessages.differentNeeds.photoMediaPublication, - width: 'half', - options: [ - { - label: newPrimarySchoolMessages.shared.yes, - dataTestId: 'yes-option', - value: YES, - }, - { - label: newPrimarySchoolMessages.shared.no, - dataTestId: 'no-option', - value: NO, - }, - ], - }), - buildAlertMessageField({ - id: 'differentNeeds.photographyInfo', - title: newPrimarySchoolMessages.shared.alertTitle, - message: newPrimarySchoolMessages.differentNeeds.photographyInfo, - doesNotRequireAnswer: true, - alertType: 'info', - }), - ], - }), - ], -}) diff --git a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts index 12a12f3d1886..a02d26ce8f5d 100644 --- a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts +++ b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts @@ -105,7 +105,6 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< 'clearPlaceOfResidence', 'clearLanguages', 'clearAllergiesAndIntolerances', - 'clearPublication', ], meta: { name: States.DRAFT, @@ -186,7 +185,6 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< unset(application.answers, 'siblings') unset(application.answers, 'languages') unset(application.answers, 'startDate') - unset(application.answers, 'photography') unset(application.answers, 'allergiesAndIntolerances') } else { // Clear movingAbroad if "Moving abroad" is not selected as reason for application @@ -255,17 +253,6 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< } return context }), - clearPublication: assign((context) => { - const { application } = context - const { photographyConsent } = getApplicationAnswers( - application.answers, - ) - if (photographyConsent === NO) { - unset(application.answers, 'photography.photoSchoolPublication') - unset(application.answers, 'photography.photoMediaPublication') - } - return context - }), }, }, diff --git a/libs/application/templates/new-primary-school/src/lib/constants.ts b/libs/application/templates/new-primary-school/src/lib/constants.ts index aa9db8e42f2e..efb5dea44ee6 100644 --- a/libs/application/templates/new-primary-school/src/lib/constants.ts +++ b/libs/application/templates/new-primary-school/src/lib/constants.ts @@ -43,13 +43,6 @@ export enum SiblingRelationOptions { STEP_SIBLING = 'stepSibling', } -// Mapping Þjóðskrá gender to Júní data -export enum Gender { - FEMALE = 'kvk', - MALE = 'kk', - OTHER = 'other', -} - export enum OptionsType { PRONOUN = 'pronoun', GENDER = 'gender', diff --git a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts index 811615786581..1408dbe67649 100644 --- a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts +++ b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts @@ -24,7 +24,6 @@ export const dataSchema = z.object({ childNationalId: z.string().min(1), childInfo: z .object({ - gender: z.string().optional(), preferredName: z.string().optional(), pronouns: z.array(z.string()).optional(), differentPlaceOfResidence: z.enum([YES, NO]), @@ -187,26 +186,6 @@ export const dataSchema = z.object({ specialSupport: z.enum([YES, NO]), requestMeeting: z.array(z.enum([YES, NO])).optional(), }), - photography: z - .object({ - photographyConsent: z.enum([YES, NO]), - photoSchoolPublication: z.enum([YES, NO]).optional(), - photoMediaPublication: z.enum([YES, NO]).optional(), - }) - .refine( - ({ photographyConsent, photoSchoolPublication }) => - photographyConsent === YES ? !!photoSchoolPublication : true, - { - path: ['photoSchoolPublication'], - }, - ) - .refine( - ({ photographyConsent, photoMediaPublication }) => - photographyConsent === YES ? !!photoMediaPublication : true, - { - path: ['photoMediaPublication'], - }, - ), }) export type SchemaFormValues = z.infer diff --git a/libs/application/templates/new-primary-school/src/lib/messages.ts b/libs/application/templates/new-primary-school/src/lib/messages.ts index 92e4d9df758e..4d11ee847ce5 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -215,16 +215,6 @@ export const newPrimarySchoolMessages: MessageDir = { defaultMessage: 'Veldu fornafn', description: 'Select pronoun', }, - childInfoGender: { - id: 'dess.nps.application:childrenNParents.child.info.gender', - defaultMessage: 'Kyn', - description: 'Gender', - }, - childInfoGenderPlaceholder: { - id: 'dess.nps.application:childrenNParents.child.info.gender.placeholder', - defaultMessage: 'Veldu kyn', - description: 'Select gender', - }, differentPlaceOfResidence: { id: 'dess.nps.application:childrenNParents.child.info.different.place.of.residence', defaultMessage: 'Er dvalarstaður barns annað en skráð lögheimili?', @@ -299,16 +289,6 @@ export const newPrimarySchoolMessages: MessageDir = { defaultMessage: 'Eyða aðstandanda', description: 'Remove relative', }, - relativesCanPickUpChild: { - id: 'dess.nps.application:childrenNParents.relatives.can.pick.up.child', - defaultMessage: 'Má sækja barn í skólann', - description: 'Can pick up the child from school', - }, - relativesCanPickUpChildTableHeader: { - id: 'dess.nps.application:childrenNParents.relatives.can.pick.up.child.table.header', - defaultMessage: 'Má sækja barn', - description: 'Can pick up the child', - }, }), primarySchool: defineMessages({ @@ -626,55 +606,6 @@ export const newPrimarySchoolMessages: MessageDir = { defaultMessage: 'Óska eftir samtali við skóla', description: 'Request meeting with the school', }, - - // Use of footage - useOfFootageSubSectionTitle: { - id: 'dess.nps.application:different.needs.use.of.footage.sub.section.title', - defaultMessage: 'Notkun myndefnis', - description: 'Use of footage', - }, - photography: { - id: 'dess.nps.application:different.needs.photography', - defaultMessage: - 'Samþykki vegna myndatöku, myndbandsupptöku og birtingu myndefnis grunnskóla', - description: - 'Consent for photography, video recording and publication of elementary school footage', - }, - photographyDescription: { - id: 'dess.nps.application:different.needs.photography.description', - defaultMessage: - 'Þegar kemur að myndatöku og myndbirtingu skal virða sjálfsákvörðunarrétt barna og ungmenna og taka tillit til skoðana og viðhorfa þeirra í samræmi við aldur og þroska.', - description: - 'When it comes to taking pictures and publishing pictures, the right of self-determination of children and young people must be respected and their views and attitudes taken into account in accordance with their age and maturity.', - }, - photographyConsent: { - id: 'dess.nps.application:different.needs.photography.consent', - defaultMessage: - 'Er heimilt að taka ljósmyndir/myndbönd af barni þínu í daglegu skólastarfi?', - description: - 'Is it allowed to take photos/videos of your child during daily school activities?', - }, - photoSchoolPublication: { - id: 'dess.nps.application:different.needs.photo.school.publication', - defaultMessage: - 'Má birta myndefni á vettvangi skólans svo sem á vefsíðu hans, í fréttabréfi, samfélagsmiðlum og kynningarefni?', - description: - "Can footage be published on the school's website, in the newsletter, social media and promotional materials?", - }, - photoMediaPublication: { - id: 'dess.nps.application:different.needs.photo.media.publication', - defaultMessage: - 'Má birta myndefni hjá þriðja aðila svo sem í fjölmiðlum?', - description: - 'Can footage be published by third parties such as in the media?', - }, - photographyInfo: { - id: 'dess.nps.application:different.needs.photography.info', - defaultMessage: - 'Ekki er heimilt að nota myndefni í öðrum tilgangi en samþykki nær til.\n\nEf myndefni er notað í öðrum tilgangi, eða myndataka er fyrirhuguð í öðrum tilgangi en samþykki nær til, verða foreldrar upplýstir sérstaklega og sérstaks samþykkis aflað, af viðkomandi skóla.\n\nForeldri getur afturkallað samþykki sitt með því að hafa samband við skóla. Afturköllun hefur þó ekki áhrif á lögmæti þeirrar myndatöku og myndbirtingar sem fram hefur farið fram að þeim tíma.\n\nHver og einn skóli er ábyrgðaraðili vegna persónuupplýsinga sem þar eru unnar. Frekari leiðbeiningar og fræðsla um mynda- og myndbandstökur sem og myndbirtingar má finna á vef viðkomandi sveitarfélags.', - description: - 'It is not allowed to use visual material for any purpose other than what has been approved.\n\nIf visual material is used for a purpose other than what has been approved, or if photography is intended for a purpose other than what has been approved, parents will be informed specifically and a separate consent will be obtained from the relevant school.\n\nA parent can revoke their consent by contacting the school. However, revocation does not affect the legality of any photography or publication that has already taken place up to that time.\n\nEach school is responsible for the personal information processed there. Further guidance and education on photography and publication, as well as image processing, can be found on the website of the relevant municipality.', - }, }), overview: defineMessages({ diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index 6014f17d9803..61481a2f56ff 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -17,7 +17,6 @@ import { SiblingsRow, } from '../types' import { - Gender, ReasonForApplicationOptions, SiblingRelationOptions, } from './constants' @@ -136,21 +135,6 @@ export const getApplicationAnswers = (answers: Application['answers']) => { 'schools.newSchool.school', ) as string - const photographyConsent = getValueViaPath( - answers, - 'photography.photographyConsent', - ) as YesOrNo - - const photoSchoolPublication = getValueViaPath( - answers, - 'photography.photoSchoolPublication', - ) as YesOrNo - - const photoMediaPublication = getValueViaPath( - answers, - 'photography.photoMediaPublication', - ) as YesOrNo - return { childNationalId, childInfo, @@ -174,10 +158,6 @@ export const getApplicationAnswers = (answers: Application['answers']) => { developmentalAssessment, specialSupport, requestMeeting, - photographyConsent, - photoSchoolPublication, - photoMediaPublication, - startDate, schoolMunicipality, selectedSchool, @@ -339,22 +319,6 @@ export const getSiblingRelationOptionLabel = ( return relationOptions.find((option) => option.value === value)?.label ?? '' } -export const formatGender = (genderCode?: string): Gender | undefined => { - switch (genderCode) { - case '1': - case '3': - return Gender.MALE - case '2': - case '4': - return Gender.FEMALE - case '7': - case '8': - return Gender.OTHER - default: - return undefined - } -} - export const getOptionsListByType = async ( apolloClient: ApolloClient, type: string, diff --git a/libs/application/templates/new-primary-school/src/types.ts b/libs/application/templates/new-primary-school/src/types.ts index da7b33e7543f..8e7e773759c1 100644 --- a/libs/application/templates/new-primary-school/src/types.ts +++ b/libs/application/templates/new-primary-school/src/types.ts @@ -9,7 +9,6 @@ export interface RelativesRow { phoneNumber: string nationalId: string relation: string - canPickUpChild: string[] } export interface SiblingsRow { @@ -35,7 +34,6 @@ export type ChildInformation = { postalCode: string city: string } - gender: string preferredName: string pronouns: string[] differentPlaceOfResidence: string From 43d52d14ceaed7efab88ef05289f387224042c7f Mon Sep 17 00:00:00 2001 From: veronikasif <54938148+veronikasif@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:03:37 +0000 Subject: [PATCH 14/22] [TS-904] Remove Allergies and intolerances page (#15923) Co-authored-by: bkristmundsson --- .../src/fields/Review/index.tsx | 2 - .../AllergiesAndIntolerances.tsx | 92 ------------ .../relativesSubSection.ts | 2 +- .../allergiesAndIntolerancesSubSection.ts | 132 ------------------ .../differentNeedsSection/index.ts | 7 +- .../src/lib/NewPrimarySchoolTemplate.ts | 22 --- .../new-primary-school/src/lib/dataSchema.ts | 28 ---- .../new-primary-school/src/lib/messages.ts | 95 ++----------- .../src/lib/newPrimarySchoolUtils.ts | 30 ---- 9 files changed, 13 insertions(+), 397 deletions(-) delete mode 100644 libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx delete mode 100644 libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts diff --git a/libs/application/templates/new-primary-school/src/fields/Review/index.tsx b/libs/application/templates/new-primary-school/src/fields/Review/index.tsx index 68ba915a6033..babded3a9ea1 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/index.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/index.tsx @@ -16,7 +16,6 @@ import { ReasonForApplicationOptions, States } from '../../lib/constants' import { newPrimarySchoolMessages } from '../../lib/messages' import { getApplicationAnswers } from '../../lib/newPrimarySchoolUtils' -import { AllergiesAndIntolerances } from './review-groups/AllergiesAndIntolerances' import { Child } from './review-groups/Child' import { Languages } from './review-groups/Languages' import { Parents } from './review-groups/Parents' @@ -166,7 +165,6 @@ export const Review: FC = ({ )} - )} diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx deleted file mode 100644 index 76691d0ecbed..000000000000 --- a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/AllergiesAndIntolerances.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import { YES } from '@island.is/application/core' -import { DataValue, ReviewGroup } from '@island.is/application/ui-components' -import { GridColumn, GridRow, Stack } from '@island.is/island-ui/core' -import { useLocale } from '@island.is/localization' -import { useFriggOptions } from '../../../hooks/useFriggOptions' -import { OptionsType } from '../../../lib/constants' -import { newPrimarySchoolMessages } from '../../../lib/messages' -import { - getApplicationAnswers, - getSelectedOptionLabel, -} from '../../../lib/newPrimarySchoolUtils' -import { ReviewGroupProps } from './props' - -export const AllergiesAndIntolerances = ({ - application, - editable, - goToScreen, -}: ReviewGroupProps) => { - const { formatMessage } = useLocale() - const { - hasFoodAllergies, - hasFoodIntolerances, - isUsingEpiPen, - foodAllergies, - foodIntolerances, - } = getApplicationAnswers(application.answers) - - const foodAllergiesFriggOptions = useFriggOptions(OptionsType.ALLERGY) - const foodIntolerancesFriggOptions = useFriggOptions(OptionsType.INTOLERANCE) - - return ( - goToScreen?.('allergiesAndIntolerances')} - > - - {hasFoodAllergies.includes(YES) && ( - - - { - return getSelectedOptionLabel( - foodAllergiesFriggOptions, - allergies, - ) - }) - .join(', ')} - /> - - - )} - {hasFoodIntolerances.includes(YES) && ( - - - { - return getSelectedOptionLabel( - foodIntolerancesFriggOptions, - intolerances, - ) - }) - .join(', ')} - /> - - - )} - - - - - - - - ) -} diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/relativesSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/relativesSubSection.ts index 532264378bc7..f3a96abeeae9 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/relativesSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/relativesSubSection.ts @@ -17,7 +17,7 @@ export const relativesSubSection = buildSubSection({ children: [ buildCustomField({ id: 'relatives', - title: newPrimarySchoolMessages.differentNeeds.typeOfAllergies, + title: '', component: 'RelativesTableRepeater', }), ], diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts deleted file mode 100644 index 61b3f0d8b97e..000000000000 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/allergiesAndIntolerancesSubSection.ts +++ /dev/null @@ -1,132 +0,0 @@ -import { - buildAlertMessageField, - buildCheckboxField, - buildCustomField, - buildDescriptionField, - buildMultiField, - buildSubSection, -} from '@island.is/application/core' -import { YES } from '@island.is/application/types' -import { OptionsType } from '../../../lib/constants' -import { newPrimarySchoolMessages } from '../../../lib/messages' -import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' - -export const allergiesAndIntolerancesSubSection = buildSubSection({ - id: 'allergiesAndIntolerancesSubSection', - title: - newPrimarySchoolMessages.differentNeeds - .allergiesAndIntolerancesSubSectionTitle, - children: [ - buildMultiField({ - id: 'allergiesAndIntolerances', - title: - newPrimarySchoolMessages.differentNeeds - .foodAllergiesAndIntolerancesTitle, - description: - newPrimarySchoolMessages.differentNeeds - .foodAllergiesAndIntolerancesDescription, - children: [ - buildCheckboxField({ - id: 'allergiesAndIntolerances.hasFoodAllergies', - title: '', - spacing: 0, - options: [ - { - value: YES, - label: - newPrimarySchoolMessages.differentNeeds.childHasFoodAllergies, - }, - ], - }), - buildCustomField( - { - id: 'allergiesAndIntolerances.foodAllergies', - title: newPrimarySchoolMessages.differentNeeds.typeOfAllergies, - component: 'FriggOptionsAsyncSelectField', - dataTestId: 'food-allergies', - condition: (answers) => { - const { hasFoodAllergies } = getApplicationAnswers(answers) - - return hasFoodAllergies?.includes(YES) - }, - }, - { - optionsType: OptionsType.ALLERGY, - placeholder: - newPrimarySchoolMessages.differentNeeds - .typeOfAllergiesPlaceholder, - }, - ), - buildAlertMessageField({ - id: 'allergiesAndIntolerances.info', - title: newPrimarySchoolMessages.shared.alertTitle, - message: - newPrimarySchoolMessages.differentNeeds - .confirmFoodAllergiesAlertMessage, - doesNotRequireAnswer: true, - alertType: 'info', - marginBottom: 4, - condition: (answers) => { - const { hasFoodAllergies } = getApplicationAnswers(answers) - - return hasFoodAllergies?.includes(YES) - }, - }), - buildCheckboxField({ - id: 'allergiesAndIntolerances.hasFoodIntolerances', - title: '', - spacing: 0, - options: [ - { - value: YES, - label: - newPrimarySchoolMessages.differentNeeds - .childHasFoodIntolerances, - }, - ], - }), - buildCustomField( - { - id: 'allergiesAndIntolerances.foodIntolerances', - title: newPrimarySchoolMessages.differentNeeds.typeOfIntolerances, - component: 'FriggOptionsAsyncSelectField', - dataTestId: 'food-intolerances', - condition: (answers) => { - const { hasFoodIntolerances } = getApplicationAnswers(answers) - - return hasFoodIntolerances?.includes(YES) - }, - }, - { - optionsType: OptionsType.INTOLERANCE, - placeholder: - newPrimarySchoolMessages.differentNeeds - .typeOfIntolerancesPlaceholder, - }, - ), - buildDescriptionField({ - // Needed to add space - id: 'allergiesAndIntolerances.divider', - title: '', - marginBottom: 4, - condition: (answers) => { - const { hasFoodIntolerances } = getApplicationAnswers(answers) - - return hasFoodIntolerances?.includes(YES) - }, - }), - buildCheckboxField({ - id: 'allergiesAndIntolerances.isUsingEpiPen', - title: '', - spacing: 0, - options: [ - { - value: YES, - label: newPrimarySchoolMessages.differentNeeds.usesEpinephrinePen, - }, - ], - }), - ], - }), - ], -}) diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts index 0e60db343854..1c26f46f6c96 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/index.ts @@ -2,7 +2,6 @@ import { buildSection } from '@island.is/application/core' import { ReasonForApplicationOptions } from '../../../lib/constants' import { newPrimarySchoolMessages } from '../../../lib/messages' import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' -import { allergiesAndIntolerancesSubSection } from './allergiesAndIntolerancesSubSection' import { languageSubSection } from './languageSubSection' import { supportSubSection } from './supportSubSection' @@ -14,9 +13,5 @@ export const differentNeedsSection = buildSection({ const { reasonForApplication } = getApplicationAnswers(answers) return reasonForApplication !== ReasonForApplicationOptions.MOVING_ABROAD }, - children: [ - languageSubSection, - allergiesAndIntolerancesSubSection, - supportSubSection, - ], + children: [languageSubSection, supportSubSection], }) diff --git a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts index a02d26ce8f5d..61a447da12f7 100644 --- a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts +++ b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts @@ -185,7 +185,6 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< unset(application.answers, 'siblings') unset(application.answers, 'languages') unset(application.answers, 'startDate') - unset(application.answers, 'allergiesAndIntolerances') } else { // Clear movingAbroad if "Moving abroad" is not selected as reason for application unset(application.answers, 'reasonForApplication.movingAbroad') @@ -232,27 +231,6 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< } return context }), - /** - * If the user changes his answers, - * clear selected food allergies and intolerances. - */ - clearAllergiesAndIntolerances: assign((context) => { - const { application } = context - const { hasFoodAllergies, hasFoodIntolerances } = getApplicationAnswers( - application.answers, - ) - - if (hasFoodAllergies?.length === 0) { - unset(application.answers, 'allergiesAndIntolerances.foodAllergies') - } - if (hasFoodIntolerances?.length === 0) { - unset( - application.answers, - 'allergiesAndIntolerances.foodIntolerances', - ) - } - return context - }), }, }, diff --git a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts index 1408dbe67649..0267d6dd805e 100644 --- a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts +++ b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts @@ -153,34 +153,6 @@ export const dataSchema = z.object({ params: errorMessages.languagesRequired, }, ), - allergiesAndIntolerances: z - .object({ - hasFoodAllergies: z.array(z.string()), - hasFoodIntolerances: z.array(z.string()), - foodAllergies: z.array(z.string()).optional(), - foodIntolerances: z.array(z.string()).optional(), - isUsingEpiPen: z.array(z.string()), - }) - .refine( - ({ hasFoodAllergies, foodAllergies }) => - hasFoodAllergies.includes(YES) - ? !!foodAllergies && foodAllergies.length > 0 - : true, - { - path: ['foodAllergies'], - params: errorMessages.foodAllergyRequired, - }, - ) - .refine( - ({ hasFoodIntolerances, foodIntolerances }) => - hasFoodIntolerances.includes(YES) - ? !!foodIntolerances && foodIntolerances.length > 0 - : true, - { - path: ['foodIntolerances'], - params: errorMessages.foodIntoleranceRequired, - }, - ), support: z.object({ developmentalAssessment: z.enum([YES, NO]), specialSupport: z.enum([YES, NO]), diff --git a/libs/application/templates/new-primary-school/src/lib/messages.ts b/libs/application/templates/new-primary-school/src/lib/messages.ts index 4d11ee847ce5..755cd406901b 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -501,67 +501,6 @@ export const newPrimarySchoolMessages: MessageDir = { "Icelandic is not spoken in the child's immediate environment", }, - // Allergies and intolerances - allergiesAndIntolerancesSubSectionTitle: { - id: 'dess.nps.application:different.needs.allergies.and.intolerances.sub.section.title', - defaultMessage: 'Ofnæmi og óþol', - description: 'Allergies and intolerances', - }, - foodAllergiesAndIntolerancesTitle: { - id: 'dess.nps.application:different.needs.food.allergies.and.intolerances.title', - defaultMessage: 'Fæðuofnæmi og -óþol', - description: 'Food allergies and intolerances', - }, - foodAllergiesAndIntolerancesDescription: { - id: 'dess.nps.application:different.needs.food.allergies.and.intolerances.description', - defaultMessage: - 'Er barnið með fæðuofnæmi eða -óþol sem starfsfólk skóla þarf að vera meðvitað um?', - description: - 'Does the child have food allergies or intolerances that the school staff need to be aware of?', - }, - childHasFoodAllergies: { - id: 'dess.nps.application:different.needs.child.has.food.allergies', - defaultMessage: 'Barnið er með fæðuofnæmi', - description: 'Child has food allergies', - }, - typeOfAllergies: { - id: 'dess.nps.application:different.needs.type.of.allergies', - defaultMessage: 'Tegund ofnæmis', - description: 'Type of allergies', - }, - typeOfAllergiesPlaceholder: { - id: 'dess.nps.application:different.needs.type.of.allergies.placeholder', - defaultMessage: 'Veldu tegund ofnæmis', - description: 'Select type of allergies', - }, - confirmFoodAllergiesAlertMessage: { - id: 'dess.nps.application:different.needs.confirm.food.allergies.alert.message', - defaultMessage: - 'Athugið að skóli mun krefjast vottorðs frá lækni til staðfestingar á fæðuofnæmi.', - description: - "Please note that the school will require a doctor's certificate to confirm food allergies.", - }, - childHasFoodIntolerances: { - id: 'dess.nps.application:different.needs.child.has.food.intolerances', - defaultMessage: 'Barnið er með fæðuóþol', - description: 'Child has food intolerances', - }, - typeOfIntolerances: { - id: 'dess.nps.application:different.needs.type.of.intolerances', - defaultMessage: 'Tegund óþols', - description: 'Type of intolerances', - }, - typeOfIntolerancesPlaceholder: { - id: 'dess.nps.application:different.needs.type.of.intolerances.placeholder', - defaultMessage: 'Veldu tegund óþols', - description: 'Select type of intolerances', - }, - usesEpinephrinePen: { - id: 'dess.nps.application:different.needs.uses.epinephrine.pen', - defaultMessage: 'Notar adrenalínpenna', - description: 'Uses epinephrine pen', - }, - // Support supportSubSectionTitle: { id: 'dess.nps.application:different.needs.support.sub.section.title', @@ -655,21 +594,6 @@ export const newPrimarySchoolMessages: MessageDir = { defaultMessage: 'Íslenska er töluð í nærumhverfi barnsins', description: "Icelandic is spoken in the child's immediate environment", }, - foodAllergies: { - id: 'dess.nps.application:overview.food.allergies', - defaultMessage: 'Fæðuofnæmi', - description: 'Food allergies', - }, - foodIntolerances: { - id: 'dess.nps.application:overview.food.intolerances', - defaultMessage: 'Fæðuóþol', - description: 'Food intolerances', - }, - usesEpinephrinePen: { - id: 'dess.nps.application:overview.uses.epinephrine.pen', - defaultMessage: 'Notar adrenalínpenna', - description: 'Uses an epinephrine pen', - }, schoolTitle: { id: 'dess.nps.application:review.school.title', defaultMessage: 'Upplýsingar um skóla', @@ -760,15 +684,18 @@ export const errorMessages = defineMessages({ defaultMessage: 'Það þarf að velja a.m.k eitt tungumál', description: 'At least one language must be selected', }, - foodAllergyRequired: { - id: 'dess.nps.application:error.food.allergy.required', - defaultMessage: 'Það þarf að velja a.m.k eitt fæðuofnæmi', - description: 'At least one food allergy must be selected', + noChildrenFoundTitle: { + id: 'dess.nps.application:error.no.children.found.title', + defaultMessage: 'Því miður ert þú ekki með skráð barn á grunnskólaaldri', + description: + 'Unfortunately, you do not have a child registered at primary school age', }, - foodIntoleranceRequired: { - id: 'dess.nps.application:error.food.intolerance.required', - defaultMessage: 'Það þarf að velja a.m.k eitt fæðuóþol', - description: 'At least one food intolerance must be selected', + noChildrenFoundMessage: { + id: 'dess.nps.application:error.no.children.found.message#markdown', + defaultMessage: + 'Eingöngu sá sem er með lögheimilisforsjá hefur heimild til að sækja um fyrir barn. \n\nÞjóðskrá skráir hver eða hverjir teljast foreldrar barns og hver fari með forsjárskyldur þess. Upplýsingar um skráningu forsjár og lögheimilisforeldris má nálgast hér: [Foreldrar og forsjá | Þjóðskrá (skra.is)](https://www.skra.is/folk/skraning-barns/foreldrar-og-forsja/)\n\nUpplýsingum um tengsl á milli barna og foreldra auk forsjáraðila eru einnig aðgengilegar á [Mínum síðum á Ísland.is](https://island.is/minarsidur)', + description: + 'Only the person who has legal custody has the authority to apply for a child.\n\nThe National Registry records who or which individuals are considered to be the parents of a child and who has custody responsibilities. Information on registering custody and legal guardianship can be found here: [Parents and Custody | National Registry (skra.is)](https://www.skra.is/folk/skraning-barns/foreldrar-og-forsja/)\n\nInformation about the relationship between children and parents, as well as custody authorities, is also available on [My Pages on Ísland.is](https://island.is/minarsidur)', }, noChildrenFoundTitle: { id: 'dess.nps.application:error.no.children.found.title', diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index 61481a2f56ff..960af648f536 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -82,31 +82,6 @@ export const getApplicationAnswers = (answers: Application['answers']) => { 'languages.icelandicNotSpokenAroundChild', ) as string[] - const hasFoodAllergies = getValueViaPath( - answers, - 'allergiesAndIntolerances.hasFoodAllergies', - ) as string[] - - const foodAllergies = getValueViaPath( - answers, - 'allergiesAndIntolerances.foodAllergies', - ) as string[] - - const hasFoodIntolerances = getValueViaPath( - answers, - 'allergiesAndIntolerances.hasFoodIntolerances', - ) as string[] - - const foodIntolerances = getValueViaPath( - answers, - 'allergiesAndIntolerances.foodIntolerances', - ) as string[] - - const isUsingEpiPen = getValueViaPath( - answers, - 'allergiesAndIntolerances.isUsingEpiPen', - ) as YesOrNo - const developmentalAssessment = getValueViaPath( answers, 'support.developmentalAssessment', @@ -150,11 +125,6 @@ export const getApplicationAnswers = (answers: Application['answers']) => { otherLanguagesSpokenDaily, otherLanguages, icelandicNotSpokenAroundChild, - hasFoodAllergies, - foodAllergies, - hasFoodIntolerances, - foodIntolerances, - isUsingEpiPen, developmentalAssessment, specialSupport, requestMeeting, From f792a93b7f099ddcd97a05788f1a9acdc5b4bd06 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Wed, 18 Sep 2024 09:38:58 +0000 Subject: [PATCH 15/22] Remove duplicated translations --- .../new-primary-school/src/lib/messages.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/libs/application/templates/new-primary-school/src/lib/messages.ts b/libs/application/templates/new-primary-school/src/lib/messages.ts index 755cd406901b..02186c7e16bd 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -697,17 +697,4 @@ export const errorMessages = defineMessages({ description: 'Only the person who has legal custody has the authority to apply for a child.\n\nThe National Registry records who or which individuals are considered to be the parents of a child and who has custody responsibilities. Information on registering custody and legal guardianship can be found here: [Parents and Custody | National Registry (skra.is)](https://www.skra.is/folk/skraning-barns/foreldrar-og-forsja/)\n\nInformation about the relationship between children and parents, as well as custody authorities, is also available on [My Pages on Ísland.is](https://island.is/minarsidur)', }, - noChildrenFoundTitle: { - id: 'dess.nps.application:error.no.children.found.title', - defaultMessage: 'Því miður ert þú ekki með skráð barn á grunnskólaaldri', - description: - 'Unfortunately, you do not have a child registered at primary school age', - }, - noChildrenFoundMessage: { - id: 'dess.nps.application:error.no.children.found.message#markdown', - defaultMessage: - 'Eingöngu sá sem er með lögheimilisforsjá hefur heimild til að sækja um fyrir barn. \n\nÞjóðskrá skráir hver eða hverjir teljast foreldrar barns og hver fari með forsjárskyldur þess. Upplýsingar um skráningu forsjár og lögheimilisforeldris má nálgast hér: [Foreldrar og forsjá | Þjóðskrá (skra.is)](https://www.skra.is/folk/skraning-barns/foreldrar-og-forsja/)\n\nUpplýsingum um tengsl á milli barna og foreldra auk forsjáraðila eru einnig aðgengilegar á [Mínum síðum á Ísland.is](https://island.is/minarsidur)', - description: - 'Only the person who has legal custody has the authority to apply for a child.\n\nThe National Registry records who or which individuals are considered to be the parents of a child and who has custody responsibilities. Information on registering custody and legal guardianship can be found here: [Parents and Custody | National Registry (skra.is)](https://www.skra.is/folk/skraning-barns/foreldrar-og-forsja/)\n\nInformation about the relationship between children and parents, as well as custody authorities, is also available on [My Pages on Ísland.is](https://island.is/minarsidur)', - }, }) From a0f004c8a2647e83f20439b4677175eaf3b9c4d3 Mon Sep 17 00:00:00 2001 From: veronikasif <54938148+veronikasif@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:42:09 +0000 Subject: [PATCH 16/22] feat(new-primary-school): New school - Data implementation (#15437) * New school - Data implementation * testing build problems * testing build problems * build problem testing * build problem testing * Rollback build test --------- Co-authored-by: bkristmundsson --- .../src/lib/graphql/frigg.resolver.ts | 23 +++-- .../lib/graphql/frigg/organization.model.ts | 32 +++++++ .../new-primary-school.service.ts | 4 - .../src/dataProviders/index.ts | 6 -- .../fields/Review/review-groups/School.tsx | 21 ++++- .../newSchoolSubSection.ts | 63 +++++++------- .../Prerequisites/externalDataSubSection.ts | 5 -- .../new-primary-school/src/graphql/queries.ts | 18 ++++ .../src/lib/NewPrimarySchoolTemplate.ts | 2 - .../new-primary-school/src/lib/dataSchema.ts | 1 + .../new-primary-school/src/lib/messages.ts | 19 +++-- .../src/lib/newPrimarySchoolUtils.ts | 83 ++++++++++++++++++- 12 files changed, 204 insertions(+), 73 deletions(-) create mode 100644 libs/api/domains/education/src/lib/graphql/frigg/organization.model.ts diff --git a/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts b/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts index 5a009eac74d1..6a9fb851d3b8 100644 --- a/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts +++ b/libs/api/domains/education/src/lib/graphql/frigg.resolver.ts @@ -1,20 +1,22 @@ -import { Args, Query, Resolver } from '@nestjs/graphql' - -import { UseGuards } from '@nestjs/common' - +import type { User } from '@island.is/auth-nest-tools' import { CurrentUser, IdsUserGuard, Scopes, ScopesGuard, } from '@island.is/auth-nest-tools' - -import type { User } from '@island.is/auth-nest-tools' import { ApiScope } from '@island.is/auth/scopes' -import { FriggClientService, KeyOption } from '@island.is/clients/mms/frigg' +import { + FriggClientService, + KeyOption, + OrganizationModel, +} from '@island.is/clients/mms/frigg' +import { UseGuards } from '@nestjs/common' +import { Args, Query, Resolver } from '@nestjs/graphql' import { KeyOptionModel } from './frigg/keyOption.model' import { FriggOptionListInput } from './frigg/optionList.input' +import { FriggOrganizationModel } from './frigg/organization.model' @UseGuards(IdsUserGuard, ScopesGuard) @Scopes(ApiScope.internal) @@ -30,4 +32,11 @@ export class FriggResolver { ): Promise { return this.friggClientService.getAllKeyOptions(user, input.type) } + + @Query(() => [FriggOrganizationModel], { nullable: true }) + friggSchoolsByMunicipality( + @CurrentUser() user: User, + ): Promise { + return this.friggClientService.getAllSchoolsByMunicipality(user) + } } diff --git a/libs/api/domains/education/src/lib/graphql/frigg/organization.model.ts b/libs/api/domains/education/src/lib/graphql/frigg/organization.model.ts new file mode 100644 index 000000000000..649737b3fa6e --- /dev/null +++ b/libs/api/domains/education/src/lib/graphql/frigg/organization.model.ts @@ -0,0 +1,32 @@ +import { Field, ObjectType, registerEnumType } from '@nestjs/graphql' + +export enum OrganizationModelTypeEnum { + Municipality = 'municipality', + National = 'national', + School = 'school', +} + +registerEnumType(OrganizationModelTypeEnum, { + name: 'OrganizationModelTypeEnum', +}) + +@ObjectType('EducationFriggOrganizationModel') +export class FriggOrganizationModel { + @Field() + id!: string + + @Field() + nationalId!: string + + @Field() + name!: string + + @Field(() => OrganizationModelTypeEnum) + type!: OrganizationModelTypeEnum + + @Field(() => [String], { nullable: true }) + gradeLevels?: string[] + + @Field(() => [FriggOrganizationModel], { nullable: true }) + children?: FriggOrganizationModel[] +} diff --git a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts index 1b6a9f106270..4f67bdb77784 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts @@ -30,10 +30,6 @@ export class NewPrimarySchoolService extends BaseTemplateApiService { return await this.friggClientService.getAllKeyOptions(auth, undefined) } - async getAllSchoolsByMunicipality({ auth }: TemplateApiModuleActionProps) { - return await this.friggClientService.getAllSchoolsByMunicipality(auth) - } - async getChildInformation({ auth, application, diff --git a/libs/application/templates/new-primary-school/src/dataProviders/index.ts b/libs/application/templates/new-primary-school/src/dataProviders/index.ts index 7fc7818694ac..b36fb2d72f90 100644 --- a/libs/application/templates/new-primary-school/src/dataProviders/index.ts +++ b/libs/application/templates/new-primary-school/src/dataProviders/index.ts @@ -9,12 +9,6 @@ export const GetKeyOptionsTypesApi = defineTemplateApi({ namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, }) -export const GetSchoolsApi = defineTemplateApi({ - action: 'getAllSchoolsByMunicipality', - externalDataId: 'schools', - namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL, -}) - export const OptionsApi = defineTemplateApi({ action: 'getAllKeyOptions', externalDataId: 'KeyOptions', diff --git a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/School.tsx b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/School.tsx index d42cbdc63c5f..49ffef4364f9 100644 --- a/libs/application/templates/new-primary-school/src/fields/Review/review-groups/School.tsx +++ b/libs/application/templates/new-primary-school/src/fields/Review/review-groups/School.tsx @@ -2,7 +2,11 @@ import { DataValue, ReviewGroup } from '@island.is/application/ui-components' import { GridColumn, GridRow, Stack, Text } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' import { newPrimarySchoolMessages } from '../../../lib/messages' -import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' +import { + formatGrade, + getApplicationAnswers, + getApplicationExternalData, +} from '../../../lib/newPrimarySchoolUtils' import { ReviewGroupProps } from './props' export const School = ({ @@ -10,10 +14,13 @@ export const School = ({ editable, goToScreen, }: ReviewGroupProps) => { - const { formatMessage, formatDate } = useLocale() + const { formatMessage, formatDate, lang } = useLocale() const { startDate, selectedSchool } = getApplicationAnswers( application.answers, ) + const { childGradeLevel } = getApplicationExternalData( + application.externalData, + ) return ( + {/* TODO: Bæta við núverandi skóla */} diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts index 4abd6c056210..1b2549b525cc 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts @@ -1,11 +1,17 @@ import { buildAsyncSelectField, + buildHiddenInputWithWatchedValue, buildMultiField, buildSubSection, + coreErrorMessages, } from '@island.is/application/core' import { ReasonForApplicationOptions } from '../../../lib/constants' import { newPrimarySchoolMessages } from '../../../lib/messages' -import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' +import { + getApplicationAnswers, + getMunicipalityOptions, + getSchoolsByMunicipalityOptions, +} from '../../../lib/newPrimarySchoolUtils' export const newSchoolSubSection = buildSubSection({ id: 'newSchoolSubSection', @@ -23,47 +29,36 @@ export const newSchoolSubSection = buildSubSection({ buildAsyncSelectField({ id: 'schools.newSchool.municipality', title: newPrimarySchoolMessages.shared.municipality, - // TODO: get data from Juni - loadOptions: async ({ apolloClient }) => { - return [{ value: 'Reykjavík', label: 'Reykjavík' }] - /*const { municipalities } = getApplicationExternalData( - application.externalData, - ) - - return municipalities.map( - (municipality: NationalRegistryMunicipality) => ({ - value: municipality?.code || '', - label: municipality.name || '', - }), - )*/ - }, - placeholder: newPrimarySchoolMessages.shared.municipalityPlaceholder, + loadingError: coreErrorMessages.failedDataProvider, dataTestId: 'new-school-municipality', + loadOptions: async ({ apolloClient }) => { + return getMunicipalityOptions(apolloClient) + }, }), - buildAsyncSelectField({ id: 'schools.newSchool.school', title: newPrimarySchoolMessages.shared.school, - condition: (answers) => { - const { schoolMunicipality } = getApplicationAnswers(answers) - return !!schoolMunicipality - }, - // TODO: get data from Juni - loadOptions: async ({ apolloClient }) => { - return [ - { - value: 'Ártúnsskóli', - label: 'Ártúnsskóli', - }, - { - value: 'Árbæjarskóli', - label: 'Árbæjarskóli', - }, - ] - }, placeholder: newPrimarySchoolMessages.shared.schoolPlaceholder, + loadingError: coreErrorMessages.failedDataProvider, dataTestId: 'new-school-school', + loadOptions: async ({ application, apolloClient }) => { + return getSchoolsByMunicipalityOptions(apolloClient, application) + }, + condition: (answers) => { + const { schoolMunicipality, newSchoolHiddenInput } = + getApplicationAnswers(answers) + + return ( + !!schoolMunicipality && + schoolMunicipality === newSchoolHiddenInput + ) + }, + }), + buildHiddenInputWithWatchedValue({ + // Needed to trigger an update on loadOptions in the async select above + id: 'schools.newSchool.hiddenInput', + watchValue: 'schools.newSchool.municipality', }), ], }), diff --git a/libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts b/libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts index 9dd64a5d7a32..46a2135c0703 100644 --- a/libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/Prerequisites/externalDataSubSection.ts @@ -10,7 +10,6 @@ import { import { ChildrenApi, GetKeyOptionsTypesApi, - GetSchoolsApi, OptionsApi, } from '../../dataProviders' import { newPrimarySchoolMessages } from '../../lib/messages' @@ -49,10 +48,6 @@ export const externalDataSubSection = buildSubSection({ provider: OptionsApi, title: 'Options', }), - buildDataProviderItem({ - provider: GetSchoolsApi, - title: 'Schools', - }), ], }), ], diff --git a/libs/application/templates/new-primary-school/src/graphql/queries.ts b/libs/application/templates/new-primary-school/src/graphql/queries.ts index 0cbfc1ac8157..f27c705e30a7 100644 --- a/libs/application/templates/new-primary-school/src/graphql/queries.ts +++ b/libs/application/templates/new-primary-school/src/graphql/queries.ts @@ -15,3 +15,21 @@ export const friggOptionsQuery = gql` } } ` + +export const friggSchoolsByMunicipalityQuery = gql` + query FriggSchoolsByMunicipality { + friggSchoolsByMunicipality { + id + nationalId + name + type + children { + id + nationalId + name + type + gradeLevels + } + } + } +` diff --git a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts index 61a447da12f7..25f5094d37a1 100644 --- a/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts +++ b/libs/application/templates/new-primary-school/src/lib/NewPrimarySchoolTemplate.ts @@ -23,7 +23,6 @@ import { assign } from 'xstate' import { ChildrenApi, GetKeyOptionsTypesApi, - GetSchoolsApi, OptionsApi, } from '../dataProviders' import { @@ -89,7 +88,6 @@ const NewPrimarySchoolTemplate: ApplicationTemplate< UserProfileApi, GetKeyOptionsTypesApi, OptionsApi, - GetSchoolsApi, ChildrenApi, ], }, diff --git a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts index 0267d6dd805e..54f61828ba0e 100644 --- a/libs/application/templates/new-primary-school/src/lib/dataSchema.ts +++ b/libs/application/templates/new-primary-school/src/lib/dataSchema.ts @@ -120,6 +120,7 @@ export const dataSchema = z.object({ ), schools: z.object({ newSchool: z.object({ + municipality: z.string(), school: z.string(), }), }), diff --git a/libs/application/templates/new-primary-school/src/lib/messages.ts b/libs/application/templates/new-primary-school/src/lib/messages.ts index 02186c7e16bd..a58e62619e0e 100644 --- a/libs/application/templates/new-primary-school/src/lib/messages.ts +++ b/libs/application/templates/new-primary-school/src/lib/messages.ts @@ -554,7 +554,7 @@ export const newPrimarySchoolMessages: MessageDir = { description: 'Overview', }, overviewTitle: { - id: 'dess.nps.application:confirmation.overview.title', + id: 'dess.nps.application:overview.title', defaultMessage: 'Yfirlit', description: 'Overview', }, @@ -595,24 +595,29 @@ export const newPrimarySchoolMessages: MessageDir = { description: "Icelandic is spoken in the child's immediate environment", }, schoolTitle: { - id: 'dess.nps.application:review.school.title', + id: 'dess.nps.application:overview.school.title', defaultMessage: 'Upplýsingar um skóla', description: 'Information about school', }, currentSchool: { - id: 'dess.nps.application:confirm.current.school', + id: 'dess.nps.application:overview.current.school', defaultMessage: 'Núverandi skóli', description: 'Current school', }, selectedSchool: { - id: 'dess.nps.application:confirm.selected.school', + id: 'dess.nps.application:overview.selected.school', defaultMessage: 'Valinn skóli', description: 'Selected school', }, - class: { - id: 'dess.nps.application:confirm.class', + grade: { + id: 'dess.nps.application:overview.grade', defaultMessage: 'Bekkur', - description: 'Class', + description: 'Grade', + }, + currentGrade: { + id: 'dess.nps.application:overview.current.grade', + defaultMessage: '{grade}. bekkur', + description: '{grade} grade', }, }), diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index 960af648f536..cb7c8f447ed6 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -1,3 +1,4 @@ +import { ApolloClient } from '@apollo/client' import { NO, getValueViaPath } from '@island.is/application/core' import { Application, @@ -6,6 +7,11 @@ import { YesOrNo, } from '@island.is/application/types' import { Locale } from '@island.is/shared/types' +import * as kennitala from 'kennitala' +import { + friggOptionsQuery, + friggSchoolsByMunicipalityQuery, +} from '../graphql/queries' import { Child, ChildInformation, @@ -16,16 +22,17 @@ import { SelectOption, SiblingsRow, } from '../types' +import { + FriggOptionsQuery, + FriggOptionsQueryVariables, + FriggSchoolsByMunicipalityQuery, +} from '../types/schema' import { ReasonForApplicationOptions, SiblingRelationOptions, } from './constants' import { newPrimarySchoolMessages } from './messages' -import { ApolloClient } from '@apollo/client' -import { friggOptionsQuery } from '../graphql/queries' -import { FriggOptionsQuery, FriggOptionsQueryVariables } from '../types/schema' - export const getApplicationAnswers = (answers: Application['answers']) => { const childNationalId = getValueViaPath(answers, 'childNationalId') as string @@ -110,6 +117,12 @@ export const getApplicationAnswers = (answers: Application['answers']) => { 'schools.newSchool.school', ) as string + const newSchoolHiddenInput = getValueViaPath( + answers, + 'schools.newSchool.hiddenInput', + ) as string + + return { childNationalId, childInfo, @@ -131,6 +144,7 @@ export const getApplicationAnswers = (answers: Application['answers']) => { startDate, schoolMunicipality, selectedSchool, + newSchoolHiddenInput, } } @@ -174,6 +188,11 @@ export const getApplicationExternalData = ( 'childInformation.data', ) as FriggChildInformation + const childGradeLevel = getValueViaPath( + externalData, + 'childInformation.data.gradeLevels[0]', + ) as string + return { children, applicantName, @@ -183,6 +202,7 @@ export const getApplicationExternalData = ( applicantCity, otherParentName, childInformation, + childGradeLevel, } } @@ -329,3 +349,58 @@ export const getSelectedOptionLabel = ( return options.find((option) => option.value === key)?.label } + +export const getMunicipalityOptions = async ( + apolloClient: ApolloClient, +) => { + const { data } = await apolloClient.query({ + query: friggSchoolsByMunicipalityQuery, + }) + + return ( + data?.friggSchoolsByMunicipality?.map((municipality) => ({ + value: municipality.name, + label: municipality.name, + })) ?? [] + ) +} + +export const getSchoolsByMunicipalityOptions = async ( + apolloClient: ApolloClient, + application: Application, +) => { + const { schoolMunicipality } = getApplicationAnswers(application.answers) + const { childGradeLevel } = getApplicationExternalData( + application.externalData, + ) + + const { data } = await apolloClient.query({ + query: friggSchoolsByMunicipalityQuery, + }) + + return ( + data?.friggSchoolsByMunicipality + ?.find(({ name }) => name === schoolMunicipality) + ?.children?.filter((school) => + school.gradeLevels?.includes(childGradeLevel), + ) + ?.map((school) => ({ value: school.name, label: school.name })) ?? [] + ) +} + +export const formatGrade = (gradeLevel: string, lang: Locale) => { + let grade = gradeLevel + if (gradeLevel[0] === '0') { + grade = gradeLevel[1] + } + switch (grade) { + case '1': + return lang === 'en' ? `${grade}st` : grade + case '2': + return lang === 'en' ? `${grade}nd` : grade + case '3': + return lang === 'en' ? `${grade}rd` : grade + default: + return lang === 'en' ? `${grade}th` : grade + } +} From d62a26ffb83617bdd8ad5ffc0f75d8552e284077 Mon Sep 17 00:00:00 2001 From: Veronika Sif Date: Thu, 19 Sep 2024 13:25:57 +0000 Subject: [PATCH 17/22] Fixed codegen error? --- .../newSchoolSubSection.ts | 45 ++++++++++++++++--- .../src/lib/newPrimarySchoolUtils.ts | 45 +------------------ 2 files changed, 40 insertions(+), 50 deletions(-) diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts index 1b2549b525cc..f2a6b5aaefbb 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts @@ -7,11 +7,12 @@ import { } from '@island.is/application/core' import { ReasonForApplicationOptions } from '../../../lib/constants' import { newPrimarySchoolMessages } from '../../../lib/messages' +import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' import { - getApplicationAnswers, - getMunicipalityOptions, - getSchoolsByMunicipalityOptions, -} from '../../../lib/newPrimarySchoolUtils' + FriggOptionsQuery, + FriggOptionsQueryVariables, + FriggSchoolsByMunicipalityQuery, +} from '../types/schema' export const newSchoolSubSection = buildSubSection({ id: 'newSchoolSubSection', @@ -33,7 +34,17 @@ export const newSchoolSubSection = buildSubSection({ loadingError: coreErrorMessages.failedDataProvider, dataTestId: 'new-school-municipality', loadOptions: async ({ apolloClient }) => { - return getMunicipalityOptions(apolloClient) + const { data } = + await apolloClient.query({ + query: friggSchoolsByMunicipalityQuery, + }) + + return ( + data?.friggSchoolsByMunicipality?.map((municipality) => ({ + value: municipality.name, + label: municipality.name, + })) ?? [] + ) }, }), buildAsyncSelectField({ @@ -43,7 +54,29 @@ export const newSchoolSubSection = buildSubSection({ loadingError: coreErrorMessages.failedDataProvider, dataTestId: 'new-school-school', loadOptions: async ({ application, apolloClient }) => { - return getSchoolsByMunicipalityOptions(apolloClient, application) + const { schoolMunicipality } = getApplicationAnswers( + application.answers, + ) + const { childGradeLevel } = getApplicationExternalData( + application.externalData, + ) + + const { data } = + await apolloClient.query({ + query: friggSchoolsByMunicipalityQuery, + }) + + return ( + data?.friggSchoolsByMunicipality + ?.find(({ name }) => name === schoolMunicipality) + ?.children?.filter((school) => + school.gradeLevels?.includes(childGradeLevel), + ) + ?.map((school) => ({ + value: school.name, + label: school.name, + })) ?? [] + ) }, condition: (answers) => { const { schoolMunicipality, newSchoolHiddenInput } = diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index cb7c8f447ed6..738bf569f04c 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -22,11 +22,7 @@ import { SelectOption, SiblingsRow, } from '../types' -import { - FriggOptionsQuery, - FriggOptionsQueryVariables, - FriggSchoolsByMunicipalityQuery, -} from '../types/schema' +import { FriggOptionsQuery, FriggOptionsQueryVariables } from '../types/schema' import { ReasonForApplicationOptions, SiblingRelationOptions, @@ -122,7 +118,6 @@ export const getApplicationAnswers = (answers: Application['answers']) => { 'schools.newSchool.hiddenInput', ) as string - return { childNationalId, childInfo, @@ -350,44 +345,6 @@ export const getSelectedOptionLabel = ( return options.find((option) => option.value === key)?.label } -export const getMunicipalityOptions = async ( - apolloClient: ApolloClient, -) => { - const { data } = await apolloClient.query({ - query: friggSchoolsByMunicipalityQuery, - }) - - return ( - data?.friggSchoolsByMunicipality?.map((municipality) => ({ - value: municipality.name, - label: municipality.name, - })) ?? [] - ) -} - -export const getSchoolsByMunicipalityOptions = async ( - apolloClient: ApolloClient, - application: Application, -) => { - const { schoolMunicipality } = getApplicationAnswers(application.answers) - const { childGradeLevel } = getApplicationExternalData( - application.externalData, - ) - - const { data } = await apolloClient.query({ - query: friggSchoolsByMunicipalityQuery, - }) - - return ( - data?.friggSchoolsByMunicipality - ?.find(({ name }) => name === schoolMunicipality) - ?.children?.filter((school) => - school.gradeLevels?.includes(childGradeLevel), - ) - ?.map((school) => ({ value: school.name, label: school.name })) ?? [] - ) -} - export const formatGrade = (gradeLevel: string, lang: Locale) => { let grade = gradeLevel if (gradeLevel[0] === '0') { From 07e34d5ac6baf473e743231fcbc283658983207d Mon Sep 17 00:00:00 2001 From: Veronika Sif Date: Thu, 19 Sep 2024 15:00:49 +0000 Subject: [PATCH 18/22] Updated loadOptions in FriggOptionsAsyncSelectField --- .../FriggOptionsAsyncSelectField/index.tsx | 34 ++++++++++++++++- .../newSchoolSubSection.ts | 10 ++--- .../src/lib/newPrimarySchoolUtils.ts | 37 ------------------- 3 files changed, 37 insertions(+), 44 deletions(-) diff --git a/libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx b/libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx index 1840afb56e2a..eae477a04fa9 100644 --- a/libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx +++ b/libs/application/templates/new-primary-school/src/fields/FriggOptionsAsyncSelectField/index.tsx @@ -9,7 +9,11 @@ import { AsyncSelectFormField } from '@island.is/application/ui-fields' import { useLocale } from '@island.is/localization' import React, { FC } from 'react' import { OptionsType } from '../../lib/constants' -import { getOptionsListByType } from '../../lib/newPrimarySchoolUtils' +import { friggOptionsQuery } from '../../graphql/queries' +import { + FriggOptionsQuery, + FriggOptionsQueryVariables, +} from '../../types/schema' type FriggOptionsAsyncSelectFieldProps = { field: { @@ -42,7 +46,33 @@ const FriggOptionsAsyncSelectField: FC< defaultValue, loadingError: coreErrorMessages.failedDataProvider, loadOptions: async ({ apolloClient }) => { - return await getOptionsListByType(apolloClient, optionsType, lang) + const { data } = await apolloClient.query< + FriggOptionsQuery, + FriggOptionsQueryVariables + >({ + query: friggOptionsQuery, + variables: { + type: { + type: optionsType, + }, + }, + }) + + return ( + data?.friggOptions?.flatMap(({ options }) => + options.flatMap(({ value, key }) => { + let content = value.find( + ({ language }) => language === lang, + )?.content + if (!content) { + content = value.find( + ({ language }) => language === 'is', + )?.content + } + return { value: key ?? '', label: content ?? '' } + }), + ) ?? [] + ) }, isMulti, backgroundColor: 'blue', diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts index f2a6b5aaefbb..aaf68f1bee55 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/primarySchoolSection/newSchoolSubSection.ts @@ -7,12 +7,12 @@ import { } from '@island.is/application/core' import { ReasonForApplicationOptions } from '../../../lib/constants' import { newPrimarySchoolMessages } from '../../../lib/messages' -import { getApplicationAnswers } from '../../../lib/newPrimarySchoolUtils' import { - FriggOptionsQuery, - FriggOptionsQueryVariables, - FriggSchoolsByMunicipalityQuery, -} from '../types/schema' + getApplicationAnswers, + getApplicationExternalData, +} from '../../../lib/newPrimarySchoolUtils' +import { FriggSchoolsByMunicipalityQuery } from '../../../types/schema' +import { friggSchoolsByMunicipalityQuery } from '../../../graphql/queries' export const newSchoolSubSection = buildSubSection({ id: 'newSchoolSubSection', diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index 738bf569f04c..ca90f4bc6ede 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -1,4 +1,3 @@ -import { ApolloClient } from '@apollo/client' import { NO, getValueViaPath } from '@island.is/application/core' import { Application, @@ -7,11 +6,6 @@ import { YesOrNo, } from '@island.is/application/types' import { Locale } from '@island.is/shared/types' -import * as kennitala from 'kennitala' -import { - friggOptionsQuery, - friggSchoolsByMunicipalityQuery, -} from '../graphql/queries' import { Child, ChildInformation, @@ -22,7 +16,6 @@ import { SelectOption, SiblingsRow, } from '../types' -import { FriggOptionsQuery, FriggOptionsQueryVariables } from '../types/schema' import { ReasonForApplicationOptions, SiblingRelationOptions, @@ -304,36 +297,6 @@ export const getSiblingRelationOptionLabel = ( return relationOptions.find((option) => option.value === value)?.label ?? '' } -export const getOptionsListByType = async ( - apolloClient: ApolloClient, - type: string, - lang: Locale, -) => { - const { data } = await apolloClient.query< - FriggOptionsQuery, - FriggOptionsQueryVariables - >({ - query: friggOptionsQuery, - variables: { - type: { - type, - }, - }, - }) - - return ( - data?.friggOptions?.flatMap(({ options }) => - options.flatMap(({ value, key }) => { - let content = value.find(({ language }) => language === lang)?.content - if (!content) { - content = value.find(({ language }) => language === 'is')?.content - } - return { value: key ?? '', label: content ?? '' } - }), - ) ?? [] - ) -} - export const getSelectedOptionLabel = ( options: SelectOption[], key?: string, From 3103e5751be54e57fffa92c47f2c378316b3b753 Mon Sep 17 00:00:00 2001 From: Veronika Sif Date: Thu, 19 Sep 2024 15:03:14 +0000 Subject: [PATCH 19/22] Updated clientConfig --- .../new-primary-school/src/lib/newPrimarySchoolUtils.ts | 2 +- libs/application/templates/new-primary-school/src/types.ts | 2 +- libs/clients/mms/frigg/src/clientConfig.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts index ca90f4bc6ede..c8f5887734ad 100644 --- a/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts +++ b/libs/application/templates/new-primary-school/src/lib/newPrimarySchoolUtils.ts @@ -178,7 +178,7 @@ export const getApplicationExternalData = ( const childGradeLevel = getValueViaPath( externalData, - 'childInformation.data.gradeLevels[0]', + 'childInformation.data.gradeLevel', ) as string return { diff --git a/libs/application/templates/new-primary-school/src/types.ts b/libs/application/templates/new-primary-school/src/types.ts index 8e7e773759c1..5ce8212689d4 100644 --- a/libs/application/templates/new-primary-school/src/types.ts +++ b/libs/application/templates/new-primary-school/src/types.ts @@ -96,7 +96,7 @@ export type FriggChildInformation = { agents: Agent[] pronouns: string[] nationalId: string - gradeLevels: string[] + gradeLevel: string memberships: Membership[] primaryOrgId: object preferredName: object | null diff --git a/libs/clients/mms/frigg/src/clientConfig.json b/libs/clients/mms/frigg/src/clientConfig.json index a2e2e87a7223..ede0f33d862c 100644 --- a/libs/clients/mms/frigg/src/clientConfig.json +++ b/libs/clients/mms/frigg/src/clientConfig.json @@ -506,7 +506,7 @@ "name": { "type": "string" }, "preferredName": { "type": "object", "nullable": true }, "pronouns": { "type": "array", "items": { "type": "string" } }, - "gradeLevels": { "type": "array", "items": { "type": "string" } }, + "gradeLevel": { "type": "string" }, "email": { "type": "object", "nullable": true }, "domicile": { "nullable": true, @@ -534,7 +534,7 @@ "name", "preferredName", "pronouns", - "gradeLevels", + "gradeLevel", "email", "domicile", "residence", From f685ab3366fe1c83acaec238c660dfbffcfa0ee6 Mon Sep 17 00:00:00 2001 From: Veronika Sif Date: Thu, 19 Sep 2024 15:08:46 +0000 Subject: [PATCH 20/22] Updated other parent address --- .../childrenNParentsSection/parentsSubSection.ts | 2 +- libs/application/templates/new-primary-school/src/types.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/parentsSubSection.ts b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/parentsSubSection.ts index 3a54030ac709..ec2812b7db09 100644 --- a/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/parentsSubSection.ts +++ b/libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/childrenNParentsSection/parentsSubSection.ts @@ -161,7 +161,7 @@ export const parentsSubSection = buildSubSection({ condition: (answers, externalData) => hasOtherParent(answers, externalData), defaultValue: (application: Application) => - getOtherParent(application)?.address.streetAddress, + getOtherParent(application)?.address.streetName, }), buildTextField({ id: 'parents.parent2.address.postalCode', diff --git a/libs/application/templates/new-primary-school/src/types.ts b/libs/application/templates/new-primary-school/src/types.ts index 5ce8212689d4..630f1fd9a6c8 100644 --- a/libs/application/templates/new-primary-school/src/types.ts +++ b/libs/application/templates/new-primary-school/src/types.ts @@ -50,6 +50,7 @@ export type Person = { phoneNumber: string address: { streetAddress: string + streetName?: string postalCode: string city: string } From be73344af585dc63d932d7fd6e12d09ff5da553d Mon Sep 17 00:00:00 2001 From: Veronika Sif Date: Thu, 19 Sep 2024 15:15:46 +0000 Subject: [PATCH 21/22] Allow children to pass through for testing --- .../new-primary-school.service.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts index 4f67bdb77784..c09cb23ad888 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/new-primary-school/new-primary-school.service.ts @@ -11,6 +11,7 @@ import { Inject, Injectable } from '@nestjs/common' import * as kennitala from 'kennitala' import { TemplateApiModuleActionProps } from '../../../types' import { BaseTemplateApiService } from '../../base-template-api.service' +import { isRunningOnEnvironment } from '@island.is/shared/utils' @Injectable() export class NewPrimarySchoolService extends BaseTemplateApiService { @@ -49,6 +50,20 @@ export class NewPrimarySchoolService extends BaseTemplateApiService { // Check if the child is at primary school age and lives with the applicant const filteredChildren = children.filter((child) => { + // Allow children to pass through + const validChildren = [ + '1111111119', + '2222222229', + '5555555559', + '6666666669', + ] + if ( + isRunningOnEnvironment('local') && + validChildren.includes(child.nationalId) + ) { + return true + } + const yearOfBirth = kennitala .info(child.nationalId) .birthday.getFullYear() From 40871a8b0e815c96dd9ff3aeaaefe94f31b42428 Mon Sep 17 00:00:00 2001 From: andes-it Date: Thu, 19 Sep 2024 15:29:03 +0000 Subject: [PATCH 22/22] chore: nx format:write update dirty files --- .../src/fields/RelativesTableRepeater/index.tsx | 2 +- libs/clients/mms/frigg/src/clientConfig.json | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx b/libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx index 11fe686f9ce1..63c314c1b1d5 100644 --- a/libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx +++ b/libs/application/templates/new-primary-school/src/fields/RelativesTableRepeater/index.tsx @@ -1,7 +1,7 @@ import { FieldBaseProps, FieldComponents, - FieldTypes + FieldTypes, } from '@island.is/application/types' import { formatPhoneNumber, diff --git a/libs/clients/mms/frigg/src/clientConfig.json b/libs/clients/mms/frigg/src/clientConfig.json index ede0f33d862c..1eb150763fb1 100644 --- a/libs/clients/mms/frigg/src/clientConfig.json +++ b/libs/clients/mms/frigg/src/clientConfig.json @@ -61,7 +61,12 @@ "in": "path", "schema": { "type": "string" } }, - { "name": "action", "required": true, "in": "path", "schema": { "type": "string" } } + { + "name": "action", + "required": true, + "in": "path", + "schema": { "type": "string" } + } ], "responses": { "200": {