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..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,7 +29,10 @@ export const SelectChildren: FC = ({ field, application }) => { return { value: child.nationalId, - label: `${child.givenName} ${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/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 3657196ad917..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 @@ -50,16 +50,18 @@ 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] - + : index < custodyChildren.length + ? custodyChildren[index] + : undefined 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..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,7 +28,9 @@ export const getSelectedIndividualName = ( ) if (selectedChild) { - return `${selectedChild.givenName} ${selectedChild.familyName}` + return selectedChild.givenName && selectedChild.familyName + ? `${selectedChild.givenName} ${selectedChild.familyName}` + : `${selectedChild.fullName}` } return undefined