Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transfer-of-vehicle-ownership): removing age validation of operators #16092

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -52,6 +53,7 @@ export const CoOwnerAndOperatorRepeaterItem: FC<
useEffect(() => {
setValue(wasRemovedField, repeaterField.wasRemoved)
setValue(typeField, userMessageId)
setValue(needsAgeValidation, userMessageId === 'operator' ? false : true)
berglindoma13 marked this conversation as resolved.
Show resolved Hide resolved
}, [repeaterField.wasRemoved, userMessageId, setValue])

return (
Expand All @@ -73,6 +75,7 @@ export const CoOwnerAndOperatorRepeaterItem: FC<
<NationalIdWithName
{...props}
customId={fieldIndex}
needsAgeValidation={userMessageId === 'operator' ? false : true}
berglindoma13 marked this conversation as resolved.
Show resolved Hide resolved
customNameLabel={formatMessage(information.labels[userMessageId].name)}
customNationalIdLabel={formatMessage(
information.labels[userMessageId].nationalId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const CoOwnerAndOperatorRepeater: FC<
nationalId: '',
email: '',
phone: '',
needsAgeValidation: type === 'operator' ? false : true,
type,
},
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Props {
customId?: string
customNationalIdLabel?: string
customNameLabel?: string
needsAgeValidation?: boolean
onNationalIdChange?: (s: string) => void
onNameChange?: (s: string) => void
nationalIdDefaultValue?: string
Expand All @@ -30,6 +31,7 @@ export const NationalIdWithName: FC<
customId = '',
customNationalIdLabel = '',
customNameLabel = '',
needsAgeValidation = true,
field,
application,
onNationalIdChange,
Expand All @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] },
Expand Down
Loading