Skip to content

Commit

Permalink
removed age validation for operators
Browse files Browse the repository at this point in the history
  • Loading branch information
berglindoma13 committed Sep 19, 2024
1 parent fd9f281 commit a8eaeef
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
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)
}, [repeaterField.wasRemoved, userMessageId, setValue])

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

Please sign in to comment.