Skip to content

Commit

Permalink
fix(Inheritance-report): fixing phone number error msg and format val…
Browse files Browse the repository at this point in the history
…ue (#14705)

* fixing phone number error msg and format value

* use formatPhonenumber

* Update libs/application/templates/inheritance-report/src/lib/utils/helpers.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 10, 2024
1 parent 9313e8a commit 1e05ec6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { InputController } from '@island.is/shared/form-fields'
import { format as formatNationalId } from 'kennitala'
import intervalToDuration from 'date-fns/intervalToDuration'
import {
formatPhoneNumber,
getEstateDataFromApplication,
valueToNumber,
} from '../../lib/utils/helpers'
Expand Down Expand Up @@ -273,6 +274,7 @@ export const HeirsAndPartitionRepeater: FC<
(heir) => {
return {
...heir,
phone: heir.phone ? formatPhoneNumber(heir.phone) : '', //Remove all non-digit characters and keep the last 7 digits
initial: true,
enabled: true,
}
Expand Down Expand Up @@ -560,7 +562,6 @@ export const HeirsAndPartitionRepeater: FC<
)}
{fields.map((member: GenericFormField<EstateMember>, index) => {
if (member.initial) return null

return (
<Box key={member.id}>
<AdditionalHeir
Expand All @@ -571,7 +572,7 @@ export const HeirsAndPartitionRepeater: FC<
relationOptions={relations}
updateValues={updateValues}
remove={remove}
error={error ?? null}
error={error[index] ?? null}
/>
</Box>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const isValidPhoneNumber = (phoneNumber: string) => {
return phone && phone.isValid()
}

export const formatPhoneNumber = (phoneNumber: string) => {
return phoneNumber.replace(/\D/g, '').slice(-7)
}

/**
* Returns zero if value is not a number or number string
* @param value
Expand Down

0 comments on commit 1e05ec6

Please sign in to comment.