Skip to content

Commit

Permalink
fix(transfer-of-vehicle-ownership): removing age validation of operat…
Browse files Browse the repository at this point in the history
…ors (#16092)

* removed age validation for operators

* removing from operator change also

* coderabbit
  • Loading branch information
berglindoma13 authored Sep 19, 2024
1 parent e9ebcaf commit cab33e1
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] },
Expand Down
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')
}, [repeaterField.wasRemoved, userMessageId, setValue])

return (
Expand All @@ -73,6 +75,7 @@ export const CoOwnerAndOperatorRepeaterItem: FC<
<NationalIdWithName
{...props}
customId={fieldIndex}
needsAgeValidation={userMessageId !== 'operator'}
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

0 comments on commit cab33e1

Please sign in to comment.