Skip to content

Commit

Permalink
fix(application-estate): Show error if missing heir in undivided esta…
Browse files Browse the repository at this point in the history
…te (#16560)

* Show error if missing heir in undivided estate

* thanks rabbit

* minor refactor

* moar refactor

* the rabbit hole

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
juni-haukur and kodiakhq[bot] authored Oct 25, 2024
1 parent 97b8a92 commit 4f5bc17
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
NO,
YES,
heirAgeValidation,
missingHeirUndividedEstateValidation,
relationWithApplicant,
} from '../../lib/constants'
import intervalToDuration from 'date-fns/intervalToDuration'
Expand Down Expand Up @@ -74,6 +75,12 @@ export const EstateMembersRepeater: FC<
},
)

const missingHeirsForUndividedEstate =
selectedEstate === EstateTypes.permitForUndividedEstate &&
!values.estate?.estateMembers?.some(
(member: EstateMember) => member.enabled,
)

setBeforeSubmitCallback &&
setBeforeSubmitCallback(async () => {
if (
Expand All @@ -96,6 +103,13 @@ export const EstateMembersRepeater: FC<
return [false, 'invalid member age']
}

if (missingHeirsForUndividedEstate) {
setError(missingHeirUndividedEstateValidation, {
type: 'custom',
})
return [false, 'missing heir for undivided estate']
}

return [true, null]
})

Expand Down Expand Up @@ -136,11 +150,15 @@ export const EstateMembersRepeater: FC<
if (!hasEstateMemberUnder18withoutRep) {
clearErrors(heirAgeValidation)
}
if (!missingHeirsForUndividedEstate) {
clearErrors(missingHeirUndividedEstateValidation)
}
}, [
fields,
hasEstateMemberUnder18withoutRep,
hasEstateMemberUnder18,
clearErrors,
missingHeirsForUndividedEstate,
])

useEffect(() => {
Expand Down Expand Up @@ -418,7 +436,7 @@ export const EstateMembersRepeater: FC<
{formatMessage(m.inheritanceAddMember)}
</Button>
</Box>
{errors && errors[heirAgeValidation] ? (
{!!errors?.[heirAgeValidation] && (
<Box marginTop={4}>
<InputError
errorMessage={
Expand All @@ -428,7 +446,14 @@ export const EstateMembersRepeater: FC<
}
/>
</Box>
) : null}
)}
{!!errors?.[missingHeirUndividedEstateValidation] && (
<Box marginTop={4}>
<InputError
errorMessage={formatMessage(m.missingHeirUndividedEstateValidation)}
/>
</Box>
)}
</Box>
)
}
Expand Down
2 changes: 2 additions & 0 deletions libs/application/templates/estate/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ export const relationWithApplicant = [
]

export const heirAgeValidation = 'heirAgeValidation'
export const missingHeirUndividedEstateValidation =
'missingHeirUndividedEstateValidation'
6 changes: 6 additions & 0 deletions libs/application/templates/estate/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,12 @@ export const m = defineMessages({
'Ekki er hægt að halda áfram með umsókn þar sem aðili undir 18 er skráður án málssvara yfir lögaldri',
description: '',
},
missingHeirUndividedEstateValidation: {
id: 'es.application:missingHeirUndividedEstateValidation',
defaultMessage:
'Ekki er hægt að halda áfram með umsókn þar sem engin erfingi er skráður',
description: '',
},

// Properties
realEstatesDescription: {
Expand Down

0 comments on commit 4f5bc17

Please sign in to comment.