diff --git a/libs/application/templates/transport-authority/change-operator-of-vehicle/src/fields/NationalIdWithName/index.tsx b/libs/application/templates/transport-authority/change-operator-of-vehicle/src/fields/NationalIdWithName/index.tsx index 7e7e72e1269f..f2c800eaa80a 100644 --- a/libs/application/templates/transport-authority/change-operator-of-vehicle/src/fields/NationalIdWithName/index.tsx +++ b/libs/application/templates/transport-authority/change-operator-of-vehicle/src/fields/NationalIdWithName/index.tsx @@ -56,12 +56,6 @@ export const NationalIdWithName: FC< let nationalIdFieldErrors: string | undefined if (errorMessage && nationalIdDefaultValue?.length === 0) { nationalIdFieldErrors = errorMessage - } else if ( - kennitala.isValid(nationalIdInput) && - !kennitala.isCompany(nationalIdInput) && - kennitala.info(nationalIdInput).age < 18 - ) { - nationalIdFieldErrors = formatMessage(error.minAgeNotFulfilled) } else if (!errorMessage) { nationalIdFieldErrors = getErrorViaPath(errors, nationaIdField) } diff --git a/libs/application/templates/transport-authority/change-operator-of-vehicle/src/lib/dataSchema.ts b/libs/application/templates/transport-authority/change-operator-of-vehicle/src/lib/dataSchema.ts index f4d3fddd0e3a..012d5f5b01c9 100644 --- a/libs/application/templates/transport-authority/change-operator-of-vehicle/src/lib/dataSchema.ts +++ b/libs/application/templates/transport-authority/change-operator-of-vehicle/src/lib/dataSchema.ts @@ -31,11 +31,7 @@ const RemovableUserSchemaBase = z ({ nationalId, wasRemoved }) => { return ( wasRemoved === 'true' || - (nationalId && - nationalId.length > 0 && - kennitala.isValid(nationalId) && - (kennitala.isCompany(nationalId) || - kennitala.info(nationalId).age >= 18)) + (nationalId && nationalId.length > 0 && kennitala.isValid(nationalId)) ) }, { path: ['nationalId'] }, diff --git a/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/CoOwnerAndOperatorRepeater/CoOwnerAndOperatorRepeaterItem.tsx b/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/CoOwnerAndOperatorRepeater/CoOwnerAndOperatorRepeaterItem.tsx index 00c2b762b393..865335e36582 100644 --- a/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/CoOwnerAndOperatorRepeater/CoOwnerAndOperatorRepeaterItem.tsx +++ b/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/CoOwnerAndOperatorRepeater/CoOwnerAndOperatorRepeaterItem.tsx @@ -44,6 +44,7 @@ export const CoOwnerAndOperatorRepeaterItem: FC< const phoneField = `${fieldIndex}.phone` const typeField = `${fieldIndex}.type` const wasRemovedField = `${fieldIndex}.wasRemoved` + const needsAgeValidation = `${fieldIndex}.needsAgeValidation` const onNationalIdChange = (nationalId: string) => { addNationalIdToCoOwners(nationalId, index) @@ -52,6 +53,7 @@ export const CoOwnerAndOperatorRepeaterItem: FC< useEffect(() => { setValue(wasRemovedField, repeaterField.wasRemoved) setValue(typeField, userMessageId) + setValue(needsAgeValidation, userMessageId !== 'operator') }, [repeaterField.wasRemoved, userMessageId, setValue]) return ( @@ -73,6 +75,7 @@ export const CoOwnerAndOperatorRepeaterItem: FC< void onNameChange?: (s: string) => void nationalIdDefaultValue?: string @@ -30,6 +31,7 @@ export const NationalIdWithName: FC< customId = '', customNationalIdLabel = '', customNameLabel = '', + needsAgeValidation = true, field, application, onNationalIdChange, @@ -49,6 +51,7 @@ export const NationalIdWithName: FC< const [nationalIdInput, setNationalIdInput] = useState('') const nameField = `${usedId}.name` const nationaIdField = `${usedId}.nationalId` + const nameFieldErrors = errorMessage ? nameDefaultValue?.length === 0 ? errorMessage @@ -61,6 +64,7 @@ export const NationalIdWithName: FC< } else if ( kennitala.isValid(nationalIdInput) && !kennitala.isCompany(nationalIdInput) && + needsAgeValidation && kennitala.info(nationalIdInput).age < 18 ) { nationalIdFieldErrors = formatMessage(error.minAgeNotFulfilled) diff --git a/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/ReviewCoOwnerAndOperatorRepeater/ReviewCoOwnerAndOperatorRepeaterItem.tsx b/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/ReviewCoOwnerAndOperatorRepeater/ReviewCoOwnerAndOperatorRepeaterItem.tsx index 5294c5d6df8b..f5b88e96e3c6 100644 --- a/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/ReviewCoOwnerAndOperatorRepeater/ReviewCoOwnerAndOperatorRepeaterItem.tsx +++ b/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/ReviewCoOwnerAndOperatorRepeater/ReviewCoOwnerAndOperatorRepeaterItem.tsx @@ -69,6 +69,7 @@ export const ReviewCoOwnerAndOperatorRepeaterItem: FC< name, type: userMessageId as 'operator' | 'coOwner', wasRemoved: repeaterField.wasRemoved, + needsAgeValidation: repeaterField.needsAgeValidation, } temp[index] = itemValue setCoOwnersAndOperators(temp) diff --git a/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/lib/dataSchema.ts b/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/lib/dataSchema.ts index 4348fccda8e7..2ebd9c218f8b 100644 --- a/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/lib/dataSchema.ts +++ b/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/lib/dataSchema.ts @@ -26,16 +26,17 @@ const RemovableUserSchemaBase = z email: z.string().optional(), phone: z.string().optional(), wasRemoved: z.string().optional(), + needsAgeValidation: z.boolean().optional(), }) .refine( - ({ nationalId, wasRemoved }) => { + ({ nationalId, wasRemoved, needsAgeValidation }) => { return ( wasRemoved === 'true' || (nationalId && nationalId.length !== 0 && kennitala.isValid(nationalId) && (kennitala.isCompany(nationalId) || - kennitala.info(nationalId).age >= 18)) + (needsAgeValidation ? kennitala.info(nationalId).age >= 18 : true))) ) }, { path: ['nationalId'] },