diff --git a/libs/application/templates/driving-license/src/fields/AdvancedLicense/AdvancedLicense.tsx b/libs/application/templates/driving-license/src/fields/AdvancedLicense/AdvancedLicense.tsx index c21683dce18e..6c7d3b373c1b 100644 --- a/libs/application/templates/driving-license/src/fields/AdvancedLicense/AdvancedLicense.tsx +++ b/libs/application/templates/driving-license/src/fields/AdvancedLicense/AdvancedLicense.tsx @@ -42,12 +42,17 @@ const AdvancedLicense: FC> = ({ const requiredAgeText = s1 && s2 && - formatMessage(m[`applicationForAdvancedAgeRequired`]) - ?.replace('%1', s1) - ?.replace('%2', String(s2)) + formatMessage(m[`applicationForAdvancedAgeRequired`], { + licenses: s1, + age: String(s2), + }) return ( - + {requiredAgeText && ( diff --git a/libs/application/templates/driving-license/src/forms/prerequisites/getForm.ts b/libs/application/templates/driving-license/src/forms/prerequisites/getForm.ts index 72f2db07ff35..1b33b409a53a 100644 --- a/libs/application/templates/driving-license/src/forms/prerequisites/getForm.ts +++ b/libs/application/templates/driving-license/src/forms/prerequisites/getForm.ts @@ -41,7 +41,7 @@ export const getForm = ({ ), ] : []), - sectionAdvancedLicenseSelection, + ...(allowAdvanced ? [sectionAdvancedLicenseSelection] : []), sectionDigitalLicenseInfo, sectionRequirements, ], diff --git a/libs/application/templates/driving-license/src/forms/prerequisites/sectionAdvancedLicenseSelection.ts b/libs/application/templates/driving-license/src/forms/prerequisites/sectionAdvancedLicenseSelection.ts index 769811f4ad58..fe3afd760c0c 100644 --- a/libs/application/templates/driving-license/src/forms/prerequisites/sectionAdvancedLicenseSelection.ts +++ b/libs/application/templates/driving-license/src/forms/prerequisites/sectionAdvancedLicenseSelection.ts @@ -16,7 +16,7 @@ export const sectionAdvancedLicenseSelection = buildSubSection({ 'applicationFor', ) - return applicationFor === LicenseTypes.B_ADVANCED + return applicationFor != null && applicationFor === LicenseTypes.B_ADVANCED }, children: [ buildMultiField({ diff --git a/libs/application/templates/driving-license/src/lib/dataSchema.ts b/libs/application/templates/driving-license/src/lib/dataSchema.ts index 82b32ab65483..9a7d6ccbac65 100644 --- a/libs/application/templates/driving-license/src/lib/dataSchema.ts +++ b/libs/application/templates/driving-license/src/lib/dataSchema.ts @@ -47,7 +47,7 @@ export const dataSchema = z.object({ certificate: z.array(z.enum([YES, NO])).nonempty(), applicationFor: z.enum([B_FULL, B_TEMP, BE, B_FULL_RENEWAL_65, B_ADVANCED]), advancedLicense: z - .array(z.enum(Object.keys(AdvancedLicense) as [string, ...string[]])) + .array(z.enum(Object.values(AdvancedLicense) as [string, ...string[]])) .nonempty(), email: z.string().email(), phone: z.string().refine((v) => isValidPhoneNumber(v)), diff --git a/libs/application/templates/driving-license/src/lib/messages.ts b/libs/application/templates/driving-license/src/lib/messages.ts index 5e6f8bea1202..e791358839a1 100644 --- a/libs/application/templates/driving-license/src/lib/messages.ts +++ b/libs/application/templates/driving-license/src/lib/messages.ts @@ -890,8 +890,8 @@ export const m = defineMessages({ }, applicationForAdvancedAgeRequired: { id: 'dl.application:applicationForAdvancedAgeFor', - defaultMessage: 'Réttindaaldur fyrir %1 er %2 ára', - description: 'Required age for %1 is %2 years', + defaultMessage: 'Réttindaaldur fyrir {licenses} er {age} ára', + description: 'Required age for {licenses} is {age} years', }, applicationForAdvancedLicenseTitleC1: { id: 'dl.application:applicationForAdvancedLicenseTitleC1', diff --git a/libs/application/templates/driving-license/src/lib/utils/formUtils.ts b/libs/application/templates/driving-license/src/lib/utils/formUtils.ts index 41d0a473768c..2d1192d6357b 100644 --- a/libs/application/templates/driving-license/src/lib/utils/formUtils.ts +++ b/libs/application/templates/driving-license/src/lib/utils/formUtils.ts @@ -88,9 +88,15 @@ export const hasHealthRemarks = (externalData: ExternalData) => { } export const joinWithAnd = (arr: string[], andString = 'og'): string => { - if (arr.length === 0) return '' - if (arr.length === 1) return arr[0] - if (arr.length === 2) return arr.join(` ${andString} `) + const validStrings = arr.filter( + (str) => typeof str === 'string' && str.trim().length > 0, + ) + + if (validStrings.length === 0) return '' + if (validStrings.length === 1) return validStrings[0] + if (validStrings.length === 2) return validStrings.join(` ${andString} `) - return `${arr.slice(0, -1).join(', ')}, ${andString} ${arr[arr.length - 1]}` + return `${validStrings.slice(0, -1).join(', ')}, ${andString} ${ + validStrings[validStrings.length - 1] + }` }