From b96aa32dd26ea95fd96e694b74d4231875b4757f Mon Sep 17 00:00:00 2001 From: berglindoma13 Date: Mon, 2 Dec 2024 14:55:35 +0000 Subject: [PATCH 1/4] fix --- .../citizenship/src/utils/childrenInfo.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts b/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts index 3657196ad917..03ebeca4341a 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts @@ -50,12 +50,12 @@ export const getSelectedCustodyChild = ( const custodyChildren = getValueViaPath( externalData, 'childrenCustodyInformation.data', - undefined, - ) as ApplicantChildCustodyInformation[] | undefined + [], + ) as ApplicantChildCustodyInformation[] const childInfo = childNationalId ? custodyChildren?.find((x) => x.nationalId === childNationalId) - : custodyChildren?.[index] + : custodyChildren[index] const selectedChildren = (answers as Citizenship).selectedChildren const isSelected = From f4020309c45fc2772ef8d6d847b21c6688cc342e Mon Sep 17 00:00:00 2001 From: berglindoma13 Date: Wed, 4 Dec 2024 13:06:11 +0000 Subject: [PATCH 2/4] updates to application --- .../citizenship/citizenship.service.ts | 17 ++++++------ .../fields/Review/ChildrenPassportReview.tsx | 2 +- .../src/fields/Review/DocumentReview.tsx | 2 +- .../src/fields/SelectChildren/index.tsx | 4 ++- .../ChildrenOtherDocumentsSubSection.ts | 20 +++++++------- .../ChildrenPassportSubSection.ts | 26 +++++++++++-------- .../PassportSubSection.ts | 9 +------ .../citizenship/src/lib/dataSchema.ts | 2 +- .../citizenship/src/utils/childrenInfo.ts | 3 ++- .../src/utils/selectedIndividual.ts | 10 ++++++- 10 files changed, 53 insertions(+), 42 deletions(-) diff --git a/libs/application/template-api-modules/src/lib/modules/templates/directorate-of-immigration/citizenship/citizenship.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/directorate-of-immigration/citizenship/citizenship.service.ts index 9e8087e553fd..b91c5902f984 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/directorate-of-immigration/citizenship/citizenship.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/directorate-of-immigration/citizenship/citizenship.service.ts @@ -283,6 +283,7 @@ export class CitizenshipService extends BaseTemplateApiService { }) } } + const nonNullPassports = answers.childrenPassport?.filter((x) => !!x) // Submit the application await this.directorateOfImmigrationClient.submitApplicationForCitizenship( @@ -392,14 +393,14 @@ export class CitizenshipService extends BaseTemplateApiService { familyName: c.familyName, })) || [], childrenPassport: await Promise.all( - answers.childrenPassport?.map(async (p) => ({ - nationalId: p.nationalId, - dateOfIssue: new Date(p.publishDate), - dateOfExpiry: new Date(p.expirationDate), - passportNumber: p.passportNumber, - passportTypeId: parseInt(p.passportTypeId), - countryIdOfIssuer: p.countryOfIssuerId, - file: await this.getUrlForAttachment(application, p.attachment), + nonNullPassports?.map(async (p) => ({ + nationalId: p?.nationalId ?? '', + dateOfIssue: new Date(p?.publishDate ?? ''), + dateOfExpiry: new Date(p?.expirationDate ?? ''), + passportNumber: p?.passportNumber ?? '', + passportTypeId: parseInt(p?.passportTypeId ?? ''), + countryIdOfIssuer: p?.countryOfIssuerId ?? '', + file: await this.getUrlForAttachment(application, p?.attachment), })) || [], ), childrenSupportingDocuments: await Promise.all( diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/fields/Review/ChildrenPassportReview.tsx b/libs/application/templates/directorate-of-immigration/citizenship/src/fields/Review/ChildrenPassportReview.tsx index 969a0c47e721..ce664998619e 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/fields/Review/ChildrenPassportReview.tsx +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/fields/Review/ChildrenPassportReview.tsx @@ -40,7 +40,7 @@ export const ChildrenPassportReview: FC = ({ ) as OptionSetItem[] const passport = answers.childrenPassport?.find( - (x) => x.nationalId === child.nationalId, + (x) => x?.nationalId === child.nationalId, ) if (passport) { diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/fields/Review/DocumentReview.tsx b/libs/application/templates/directorate-of-immigration/citizenship/src/fields/Review/DocumentReview.tsx index 6e76745fe1b0..ed73191e0c25 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/fields/Review/DocumentReview.tsx +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/fields/Review/DocumentReview.tsx @@ -109,7 +109,7 @@ export const DocumentReview: FC = ({ }, })} {answers.childrenPassport?.map((passportFiles) => { - return passportFiles.attachment?.map((file) => { + return passportFiles?.attachment?.map((file) => { return {file.name} }) })} diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/fields/SelectChildren/index.tsx b/libs/application/templates/directorate-of-immigration/citizenship/src/fields/SelectChildren/index.tsx index bf3331ca01fa..d0ebb7db7519 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/fields/SelectChildren/index.tsx +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/fields/SelectChildren/index.tsx @@ -29,7 +29,9 @@ export const SelectChildren: FC = ({ field, application }) => { return { value: child.nationalId, - label: `${child.givenName} ${child.familyName}`, + label: `${ + child.givenName && child.familyName ? child.givenName : child.fullName + } ${child.givenName && child.familyName ? child.familyName : ''}`, subLabel: child.otherParent ? `${formatMessage(selectChildren.checkboxes.subLabel)} ${ child.otherParent?.fullName diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/ChildrenSupportingDocuments/ChildrenOtherDocumentsSubSection.ts b/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/ChildrenSupportingDocuments/ChildrenOtherDocumentsSubSection.ts index cb942a3ec657..8249d7eb819e 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/ChildrenSupportingDocuments/ChildrenOtherDocumentsSubSection.ts +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/ChildrenSupportingDocuments/ChildrenOtherDocumentsSubSection.ts @@ -12,6 +12,7 @@ import { supportingDocuments } from '../../../lib/messages' import { Application, FormValue } from '@island.is/application/types' import { Citizenship } from '../../../lib/dataSchema' import { + getSelectedCustodyChild, getSelectedIndividualAge, getSelectedIndividualName, } from '../../../utils' @@ -48,16 +49,17 @@ export const ChildrenOtherDocumentsSubSection = (index: number) => titleVariant: 'h5', title: '', }), - buildCustomField( - { - id: `${Routes.CHILDSUPPORTINGDOCUMENTS}[${index}].nationalId`, - title: '', - component: 'HiddenTextInput', - }, - { - index: index, + buildHiddenInput({ + id: `${Routes.CHILDSUPPORTINGDOCUMENTS}[${index}].nationalId`, + defaultValue: (application: Application) => { + const selectedChild = getSelectedCustodyChild( + application.externalData, + application.answers, + index, + ) + return selectedChild?.nationalId }, - ), + }), buildFileUploadField({ id: `${Routes.CHILDSUPPORTINGDOCUMENTS}[${index}].birthCertificate`, title: diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/ChildrenSupportingDocuments/ChildrenPassportSubSection.ts b/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/ChildrenSupportingDocuments/ChildrenPassportSubSection.ts index bb5e6e8e0f91..4b592446262d 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/ChildrenSupportingDocuments/ChildrenPassportSubSection.ts +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/ChildrenSupportingDocuments/ChildrenPassportSubSection.ts @@ -7,11 +7,14 @@ import { buildFileUploadField, buildSelectField, getValueViaPath, - buildCustomField, + buildHiddenInput, } from '@island.is/application/core' import { supportingDocuments } from '../../../lib/messages' import { Application } from '@island.is/application/types' -import { getSelectedIndividualName } from '../../../utils' +import { + getSelectedCustodyChild, + getSelectedIndividualName, +} from '../../../utils' import { OptionSetItem } from '@island.is/clients/directorate-of-immigration' import { Routes } from '../../../lib/constants' import { FILE_TYPES_ALLOWED } from '../../../shared' @@ -45,16 +48,17 @@ export const ChildrenPassportSubSection = (index: number) => title: supportingDocuments.labels.passport.title, titleVariant: 'h5', }), - buildCustomField( - { - id: `${Routes.CHILDRENPASSPORT}[${index}].nationalId`, - title: '', - component: 'HiddenTextInput', - }, - { - index: index, + buildHiddenInput({ + id: `${Routes.CHILDRENPASSPORT}[${index}].nationalId`, + defaultValue: (application: Application) => { + const selectedChild = getSelectedCustodyChild( + application.externalData, + application.answers, + index, + ) + return selectedChild?.nationalId }, - ), + }), buildDateField({ id: `${Routes.CHILDRENPASSPORT}[${index}].publishDate`, title: supportingDocuments.labels.passport.publishDate, diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/SupportingDocumentsSection/PassportSubSection.ts b/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/SupportingDocumentsSection/PassportSubSection.ts index 60596972fa6f..8a11eea3f82f 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/SupportingDocumentsSection/PassportSubSection.ts +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/forms/CitizenshipForm/SupportingDocumentsSection/PassportSubSection.ts @@ -137,14 +137,7 @@ export const PassportSubSection = buildSubSection({ const countryStr = JSON.stringify(countryOptions) const countryParsed = JSON.parse(countryStr) as OptionSetItem[] - const sortedCountryOptions = countryParsed.sort((x, y) => { - const splitX = x.name?.split(/-(.*)/s)[1].replace(' ', '') - const splitY = y.name?.split(/-(.*)/s)[1].replace(' ', '') - if (splitX && splitY && splitX > splitY) return 1 - else return -1 - }) - - return sortedCountryOptions.map(({ id, name }) => ({ + return countryParsed.map(({ id, name }) => ({ value: id?.toString() || '', label: name || '', })) diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/lib/dataSchema.ts b/libs/application/templates/directorate-of-immigration/citizenship/src/lib/dataSchema.ts index 4a976db39636..736359993cd1 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/lib/dataSchema.ts +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/lib/dataSchema.ts @@ -347,7 +347,7 @@ export const CitizenshipSchema = z.object({ countriesOfResidence: CountriesOfResidenceSchema, staysAbroad: StaysAbroadSchema, passport: PassportSchema, - childrenPassport: z.array(ChildrenPassportSchema).optional(), + childrenPassport: z.array(ChildrenPassportSchema.nullable()).optional(), maritalStatus: MaritalStatusSchema, formerIcelander: z.enum([YES, NO]), //.refine((v) => v === YES) // TODO REVERT WHEN UTL FIXED SERVICES supportingDocuments: SupportingDocumentsSchema, diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts b/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts index 03ebeca4341a..99544301b2b8 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts @@ -59,7 +59,8 @@ export const getSelectedCustodyChild = ( const selectedChildren = (answers as Citizenship).selectedChildren const isSelected = - selectedChildren && selectedChildren.find((sc) => sc === childNationalId) + selectedChildren && + selectedChildren.find((sc) => sc === childInfo?.nationalId) return isSelected ? childInfo : undefined } diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/utils/selectedIndividual.ts b/libs/application/templates/directorate-of-immigration/citizenship/src/utils/selectedIndividual.ts index 17d2e64602da..db055375bbd8 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/utils/selectedIndividual.ts +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/utils/selectedIndividual.ts @@ -28,7 +28,15 @@ export const getSelectedIndividualName = ( ) if (selectedChild) { - return `${selectedChild.givenName} ${selectedChild.familyName}` + return `${ + selectedChild.givenName && selectedChild.familyName + ? selectedChild.givenName + : selectedChild.fullName + } ${ + selectedChild.givenName && selectedChild.familyName + ? selectedChild.familyName + : '' + }` } return undefined From 6dbb78cf86de3a232b9c39bd8260d70621e367dd Mon Sep 17 00:00:00 2001 From: berglindoma13 Date: Wed, 4 Dec 2024 13:09:31 +0000 Subject: [PATCH 3/4] boundary check --- .../citizenship/src/utils/childrenInfo.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts b/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts index 99544301b2b8..26e728b99e98 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/utils/childrenInfo.ts @@ -55,8 +55,9 @@ export const getSelectedCustodyChild = ( const childInfo = childNationalId ? custodyChildren?.find((x) => x.nationalId === childNationalId) - : custodyChildren[index] - + : index < custodyChildren.length + ? custodyChildren[index] + : undefined const selectedChildren = (answers as Citizenship).selectedChildren const isSelected = selectedChildren && From 8586e99464545c71d1f4b1601e01c95c6124a01a Mon Sep 17 00:00:00 2001 From: berglindoma13 Date: Wed, 4 Dec 2024 13:43:09 +0000 Subject: [PATCH 4/4] fix --- .../citizenship/src/fields/SelectChildren/index.tsx | 7 ++++--- .../citizenship/src/utils/selectedIndividual.ts | 12 +++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/fields/SelectChildren/index.tsx b/libs/application/templates/directorate-of-immigration/citizenship/src/fields/SelectChildren/index.tsx index d0ebb7db7519..227f281c57cf 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/fields/SelectChildren/index.tsx +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/fields/SelectChildren/index.tsx @@ -29,9 +29,10 @@ export const SelectChildren: FC = ({ field, application }) => { return { value: child.nationalId, - label: `${ - child.givenName && child.familyName ? child.givenName : child.fullName - } ${child.givenName && child.familyName ? child.familyName : ''}`, + label: + child.givenName && child.familyName + ? `${child.givenName} ${child.familyName}` + : `${child.fullName}`, subLabel: child.otherParent ? `${formatMessage(selectChildren.checkboxes.subLabel)} ${ child.otherParent?.fullName diff --git a/libs/application/templates/directorate-of-immigration/citizenship/src/utils/selectedIndividual.ts b/libs/application/templates/directorate-of-immigration/citizenship/src/utils/selectedIndividual.ts index db055375bbd8..1d6eca44648e 100644 --- a/libs/application/templates/directorate-of-immigration/citizenship/src/utils/selectedIndividual.ts +++ b/libs/application/templates/directorate-of-immigration/citizenship/src/utils/selectedIndividual.ts @@ -28,15 +28,9 @@ export const getSelectedIndividualName = ( ) if (selectedChild) { - return `${ - selectedChild.givenName && selectedChild.familyName - ? selectedChild.givenName - : selectedChild.fullName - } ${ - selectedChild.givenName && selectedChild.familyName - ? selectedChild.familyName - : '' - }` + return selectedChild.givenName && selectedChild.familyName + ? `${selectedChild.givenName} ${selectedChild.familyName}` + : `${selectedChild.fullName}` } return undefined