From 78bbee6d2110ada8a2b6fb19bedefda002be2ab0 Mon Sep 17 00:00:00 2001 From: Alex Diljar Birkisbur Hellsing <42963845+alexdiljar@users.noreply.github.com> Date: Mon, 17 Oct 2022 16:44:50 +0000 Subject: [PATCH] fix(driving-license-application): Name mapping and formatting (#8711) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/lib/util/hasResidenceHistory.ts | 2 +- .../src/forms/draft/subSectionSummary.ts | 53 ++++++++++--------- .../driving-license/src/lib/dataSchema.ts | 1 - .../operating-license/src/lib/utils.ts | 2 +- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/libs/api/domains/driving-license/src/lib/util/hasResidenceHistory.ts b/libs/api/domains/driving-license/src/lib/util/hasResidenceHistory.ts index 4d4f39d27dc4..c54c933c9aab 100644 --- a/libs/api/domains/driving-license/src/lib/util/hasResidenceHistory.ts +++ b/libs/api/domains/driving-license/src/lib/util/hasResidenceHistory.ts @@ -71,7 +71,7 @@ export const hasLocalResidence = ( ({ dateOfChange: a }, { dateOfChange: b }) => compareDesc(new Date(a), new Date(b)), ) - return sorted[0].country === 'IS' + return sorted[0]?.country === 'IS' || false } return false } diff --git a/libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts b/libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts index f061b56b03c5..49e1dedca682 100644 --- a/libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts +++ b/libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts @@ -17,6 +17,7 @@ import { YES } from '../../lib/constants' import { B_TEMP } from '../../shared/constants' import { hasNoDrivingLicenseInOtherCountry, + isApplicationForCondition, needsHealthCertificateCondition, } from '../../lib/utils' @@ -46,7 +47,10 @@ export const subSectionSummary = buildSubSection({ }), buildKeyValueField({ label: m.overviewSubType, - value: ({ answers: { subType } }) => subType as string[], + value: ({ answers: { applicationFor } }) => + applicationFor === B_TEMP + ? m.applicationForTempLicenseTitle + : m.applicationForFullLicenseTitle, }), buildDividerField({}), buildKeyValueField({ @@ -55,25 +59,32 @@ export const subSectionSummary = buildSubSection({ value: ({ externalData: { nationalRegistry } }) => (nationalRegistry.data as NationalRegistryUser).fullName, }), + buildKeyValueField({ + label: m.overviewNationalId, + width: 'half', + value: ({ externalData: { nationalRegistry } }) => + formatKennitala( + (nationalRegistry.data as NationalRegistryUser).nationalId, + ), + }), buildKeyValueField({ label: m.overviewPhoneNumber, width: 'half', + condition: (answers) => !!answers?.phone, value: ({ answers: { phone } }) => phone as string, }), buildKeyValueField({ - label: m.overviewStreetAddress, + label: m.overviewEmail, width: 'half', - value: ({ externalData: { nationalRegistry } }) => - (nationalRegistry.data as NationalRegistryUser).address - ?.streetAddress, + condition: (answers) => !!answers?.email, + value: ({ answers: { email } }) => email as string, }), buildKeyValueField({ - label: m.overviewNationalId, + label: m.overviewStreetAddress, width: 'half', value: ({ externalData: { nationalRegistry } }) => - formatKennitala( - (nationalRegistry.data as NationalRegistryUser).nationalId, - ), + (nationalRegistry.data as NationalRegistryUser).address + ?.streetAddress, }), buildKeyValueField({ label: m.overviewPostalCode, @@ -81,36 +92,30 @@ export const subSectionSummary = buildSubSection({ value: ({ externalData: { nationalRegistry } }) => (nationalRegistry.data as NationalRegistryUser).address?.postalCode, }), - buildKeyValueField({ - label: m.overviewEmail, - width: 'half', - value: ({ answers: { email } }) => email as string, - }), buildKeyValueField({ label: m.overviewCity, width: 'half', value: ({ externalData: { nationalRegistry } }) => (nationalRegistry.data as NationalRegistryUser).address?.city, }), - buildDividerField({}), + buildDividerField({ + condition: isApplicationForCondition(B_TEMP), + }), buildKeyValueField({ label: m.overviewTeacher, width: 'half', + condition: isApplicationForCondition(B_TEMP), value: ({ externalData: { - studentAssessment, teachers: { data }, }, answers, }) => { - if (answers.applicationFor === B_TEMP) { - const teacher = (data as Teacher[]).find( - ({ nationalId }) => - getValueViaPath(answers, 'drivingInstructor') === nationalId, - ) - return teacher?.name - } - return (studentAssessment.data as StudentAssessment).teacherName + const teacher = (data as Teacher[]).find( + ({ nationalId }) => + getValueViaPath(answers, 'drivingInstructor') === nationalId, + ) + return teacher?.name }, }), buildDividerField({ diff --git a/libs/application/templates/driving-license/src/lib/dataSchema.ts b/libs/application/templates/driving-license/src/lib/dataSchema.ts index f1bc27fa5bc6..65feff727780 100644 --- a/libs/application/templates/driving-license/src/lib/dataSchema.ts +++ b/libs/application/templates/driving-license/src/lib/dataSchema.ts @@ -10,7 +10,6 @@ const isValidPhoneNumber = (phoneNumber: string) => { export const dataSchema = z.object({ type: z.array(z.enum(['car', 'trailer', 'motorcycle'])).nonempty(), - subType: z.array(z.string()).nonempty(), approveExternalData: z.boolean().refine((v) => v), juristiction: z.string(), healthDeclaration: z.object({ diff --git a/libs/application/templates/operating-license/src/lib/utils.ts b/libs/application/templates/operating-license/src/lib/utils.ts index a9d38c8f76f5..0329304d3d81 100644 --- a/libs/application/templates/operating-license/src/lib/utils.ts +++ b/libs/application/templates/operating-license/src/lib/utils.ts @@ -67,7 +67,7 @@ export const get24HFormatTime = (value: string) => { } const { hours, minutes } = getHoursMinutes(value) - return `${hours}:${minutes}` + return `${hours}:${minutes > 10 ? minutes : '0' + minutes}` } const vskNrRegex = /([0-9]){6}/