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(inheritance-report): EFS fixes 4.06 #15097

Merged
merged 16 commits into from
Jun 5, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const expandAnswers = (
caseNumber: string
} => {
return {
applicationFor: answers.applicationFor ?? '',
applicant: answers.applicant,
executors: {
executor: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@
updateShareCalculations,
])

const inputError =

Check warning on line 445 in libs/application/templates/inheritance-report/src/fields/CalculateShare/index.tsx

View workflow job for this annotation

GitHub Actions / linting (application-system-form,application-template-api-modules,application-template-loader,app...

'inputError' is assigned a value but never used. Allowed unused vars must match /^_[a-zA-Z0-9]*$/u
(errors?.customShare as { customSpouseSharePercentage: string })
?.customSpouseSharePercentage ?? ''

Expand All @@ -461,7 +461,7 @@
title={m.netProperty}
value={roundedValueToNumber(netTotal)}
/>
<Box marginY={4}>
<Box>
{deceasedWasInCohabitation && (
<TitleRow
title={m.assetsToShareSpouseShare}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import { hasYes } from '@island.is/application/core'
import { Fragment, useEffect, useMemo } from 'react'
import { EstateMember } from '../../types'
import {
ESTATE_INHERITANCE,
ErrorValue,
PREPAID_INHERITANCE,
PrePaidHeirsRelationTypes,
RelationSpouse,
} from '../../lib/constants'
import { LookupPerson } from '../LookupPerson'
import { HeirsAndPartitionRepeaterProps } from './types'
Expand Down Expand Up @@ -131,7 +132,7 @@ export const AdditionalHeir = ({
}, [foreignCitizenship, requiresAdvocate])

return (
<Box position="relative" key={field.id} marginTop={7}>
<Box position="relative" key={field.id} marginTop={3}>
<Controller
name={initialField}
control={control}
Expand Down Expand Up @@ -284,8 +285,9 @@ export const AdditionalHeir = ({
/>
</GridColumn>
) : customField.id === 'taxFreeInheritance' &&
currentHeir?.relation !==
PrePaidHeirsRelationTypes.SPOUSE ? null : (
((values.applicationFor === PREPAID_INHERITANCE &&
currentHeir?.relation !== RelationSpouse) ||
values.applicationFor === ESTATE_INHERITANCE) ? null : (
<GridColumn span={['1/2']} paddingBottom={2}>
<InputController
id={`${fieldIndex}.${customField.id}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
Text,
} from '@island.is/island-ui/core'
import { m } from '../../lib/messages'
import * as kennitala from 'kennitala'
import { formatCurrency } from '@island.is/application/ui-components'
import { Answers, EstateMember, heirAgeValidation } from '../../types'
import { AdditionalHeir } from './AdditionalHeir'
import { getValueViaPath } from '@island.is/application/core'
import { InputController } from '@island.is/shared/form-fields'
import { format as formatNationalId } from 'kennitala'
import { format as formatNationalId, info } from 'kennitala'
import intervalToDuration from 'date-fns/intervalToDuration'
import {
formatPhoneNumber,
Expand All @@ -32,6 +31,7 @@
DEFAULT_TAX_FREE_LIMIT,
PREPAID_INHERITANCE,
PrePaidHeirsRelations,
RelationSpouse,
} from '../../lib/constants'
import DoubleColumnRow from '../../components/DoubleColumnRow'
import ShareInput from '../../components/ShareInput'
Expand All @@ -47,12 +47,13 @@
const { customFields } = props

const { formatMessage } = useLocale()
const { getValues, setError, setValue } = useFormContext()
const { getValues, setError, setValue, clearErrors } = useFormContext()
const values = getValues()
const { fields, append, update, remove, replace } = useFieldArray({
name: id,
})

const values = getValues()
const isPrePaidApplication = answers.applicationFor === PREPAID_INHERITANCE

const heirsRelations = (values?.heirs?.data ?? []).map((x: EstateMember) => {
return x.relation
Expand All @@ -66,7 +67,7 @@
hasForeignCitizenship && birthDate
? intervalToDuration({ start: new Date(birthDate), end: new Date() })
?.years
: kennitala.info(member.nationalId)?.age
: info(member.nationalId)?.age
return (
(memberAge ?? 0) < 18 &&
(member?.nationalId || birthDate) &&
Expand All @@ -78,7 +79,7 @@
const hasEstateMemberUnder18withoutRep = values.estate?.estateMembers?.some(
(member: EstateMember) => {
const advocateAge =
member.advocate && kennitala.info(member.advocate.nationalId)?.age
member.advocate && info(member.advocate.nationalId)?.age
return (
hasEstateMemberUnder18 &&
member?.advocate?.nationalId &&
Expand Down Expand Up @@ -106,34 +107,29 @@
return [true, null]
})

const { clearErrors } = useFormContext()

const externalData = application.externalData.syslumennOnEntry?.data as {
relationOptions: string[]
inheritanceReportInfos: Array<InheritanceReportInfo>
}

const estateData =
answers.applicationFor === PREPAID_INHERITANCE
? undefined
: getEstateDataFromApplication(application)

const inheritanceTaxFreeLimit =
answers.applicationFor === PREPAID_INHERITANCE
? 0
: externalData?.inheritanceReportInfos?.[0]?.inheritanceTax
?.taxExemptionLimit ?? DEFAULT_TAX_FREE_LIMIT

const relations =
answers.applicationFor === PREPAID_INHERITANCE
? PrePaidHeirsRelations.map((relation) => ({
value: relation.value,
label: formatMessage(relation.label),
}))
: externalData?.relationOptions?.map((relation) => ({
value: relation,
label: relation,
})) || []
const estateData = isPrePaidApplication
? undefined
: getEstateDataFromApplication(application)

const inheritanceTaxFreeLimit = isPrePaidApplication
? 0
: externalData?.inheritanceReportInfos?.[0]?.inheritanceTax
?.taxExemptionLimit ?? DEFAULT_TAX_FREE_LIMIT

const relations = isPrePaidApplication
? PrePaidHeirsRelations.map((relation) => ({
value: formatMessage(relation.label),
label: formatMessage(relation.label),
}))
: externalData?.relationOptions?.map((relation) => ({
value: relation,
label: relation,
})) || []

const error =
((errors as any)?.heirs?.data || (errors as any)?.heirs?.total) ?? []
Expand Down Expand Up @@ -177,11 +173,10 @@

const updateValues = useCallback(
(updateIndex: string, value: number, index?: number) => {
const isPrePaid = answers.applicationFor === PREPAID_INHERITANCE
const numValue = isNaN(value) ? 0 : value
const percentage = numValue > 0 ? numValue / 100 : 0
const heirs = getValues()?.heirs?.data as EstateMember[]
let currentHeir = isPrePaid
let currentHeir = isPrePaidApplication
? heirs[index ?? 0]
: (getValueViaPath(answers, updateIndex) as EstateMember)

Expand All @@ -195,20 +190,15 @@

// currently we can only check if heir is spouse by relation string value...
const spouse = (heirs ?? []).filter(
(heir) =>
heir.enabled &&
(heir.relation === 'Maki' ||
heir.relation.toLowerCase() === 'spouse'),
(heir) => heir.enabled && heir.relation === RelationSpouse,
)

let isSpouse = false

// it is not possible to select more than one spouse but for now we will check for it anyway
if (spouse.length > 0) {
if (isPrePaid) {
isSpouse =
currentHeir?.relation === 'Maki' ||
currentHeir?.relation.toLowerCase() === 'spouse'
if (isPrePaidApplication) {
isSpouse = currentHeir?.relation === RelationSpouse
} else {
spouse.forEach((currentSpouse) => {
isSpouse =
Expand All @@ -217,7 +207,7 @@
}
}

const netPropertyForExchange = isPrePaid
const netPropertyForExchange = isPrePaidApplication
? getPrePaidTotalValueFromApplication(application)
: valueToNumber(getValueViaPath(answers, 'netPropertyForExchange'))

Expand Down Expand Up @@ -253,7 +243,7 @@

calculateTotal()
},
[answers, calculateTotal, getValues, inheritanceTaxFreeLimit, setValue],

Check warning on line 246 in libs/application/templates/inheritance-report/src/fields/HeirsAndPartitionRepeater/index.tsx

View workflow job for this annotation

GitHub Actions / linting (application-system-form,application-template-api-modules,application-template-loader,app...

React Hook useCallback has missing dependencies: 'application' and 'isPrePaidApplication'. Either include them or remove the dependency array
)

const initialLoad = useCallback(() => {
Expand All @@ -268,11 +258,6 @@
initialLoad()
}, [heirsRelations, initialLoad])

useEffect(() => {
initialLoad()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

useEffect(() => {
if (!hasEstateMemberUnder18) {
clearErrors(heirAgeValidation)
Expand All @@ -297,25 +282,22 @@
(estateData as any)?.inheritanceReportInfo?.heirs &&
!(application.answers as any)?.heirs?.hasModified
) {
// Keeping this in for now, it may not be needed, will find out later
const heirsData = (estateData as any)?.inheritanceReportInfo?.heirs?.map(
(heir: any) => {
return {
...heir,
phone: heir.phone ? formatPhoneNumber(heir.phone) : '', //Remove all non-digit characters and keep the last 7 digits
phone: heir.phone ? formatPhoneNumber(heir.phone) : '',
initial: true,
enabled: true,
}
},
)
// ran into a problem with "append", as it appeared to be getting called multiple times
// despite checking on the length of the fields
// so now using "replace" instead, for the initial setup
// ran into a problem with "append" as it appeared to be called multiple times
// using "replace" instead, for the initial setup
replace(heirsData)
setValue('heirs.hasModified', true)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

Check warning on line 300 in libs/application/templates/inheritance-report/src/fields/HeirsAndPartitionRepeater/index.tsx

View workflow job for this annotation

GitHub Actions / linting (application-system-form,application-template-api-modules,application-template-loader,app...

React Hook useEffect has missing dependencies: 'application.answers', 'estateData', 'fields.length', 'replace', and 'setValue'. Either include them or remove the dependency array

return (
<Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FieldBaseProps } from '@island.is/application/types'
import { InheritanceReport } from '../../lib/dataSchema'
import { m } from '../../lib/messages'
import { formatCurrency } from '@island.is/application/ui-components'
import { format as formatNationalId } from 'kennitala'

export const HeirsOverview: FC<React.PropsWithChildren<FieldBaseProps>> = ({
application,
Expand All @@ -25,7 +26,7 @@ export const HeirsOverview: FC<React.PropsWithChildren<FieldBaseProps>> = ({
<Box display="flex" marginBottom={2}>
<Box width="half">
<Text variant="h4">{formatMessage(m.nationalId)}</Text>
<Text>{heir.nationalId}</Text>
<Text>{formatNationalId(heir.nationalId ?? '')}</Text>
</Box>
<Box width="half">
<Text variant="h4">{formatMessage(m.name)}</Text>
Expand Down Expand Up @@ -55,16 +56,16 @@ export const HeirsOverview: FC<React.PropsWithChildren<FieldBaseProps>> = ({
</Box>
</Box>
<Box display={'flex'} marginBottom={2}>
<Box width="half">
<Text variant="h4">{formatMessage(m.inheritanceAmount)}</Text>
<Text>{formatCurrency(String(heir.inheritance || '0'))}</Text>
</Box>
<Box width="half">
<Text variant="h4">{formatMessage(m.taxFreeInheritance)}</Text>
<Text>
{formatCurrency(String(heir.taxFreeInheritance || '0'))}
</Text>
</Box>
<Box width="half">
<Text variant="h4">{formatMessage(m.inheritanceAmount)}</Text>
<Text>{formatCurrency(String(heir.inheritance || '0'))}</Text>
</Box>
</Box>
<Box display={'flex'} marginBottom={2}>
<Box width="half">
Expand All @@ -90,7 +91,7 @@ export const HeirsOverview: FC<React.PropsWithChildren<FieldBaseProps>> = ({
<Text variant="h4">
{formatMessage(m.advocateNationalId)}
</Text>
<Text>{heir.advocate.nationalId}</Text>
<Text>{formatNationalId(heir.advocate.nationalId)}</Text>
</Box>
<Box width="half">
<Text variant="h4">{formatMessage(m.advocateName)}</Text>
Expand Down
14 changes: 2 additions & 12 deletions libs/application/templates/inheritance-report/src/forms/form.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import {
YES,
buildCheckboxField,
buildForm,
buildMultiField,
buildSection,
buildSubmitField,
} from '@island.is/application/core'
import { m } from '../lib/messages'
import { DefaultEvents, Form, FormModes } from '@island.is/application/types'
import { buildForm } from '@island.is/application/core'
import { Form, FormModes } from '@island.is/application/types'
import { assets } from './sections/assets'
import { debtsAndFuneralCost } from './sections/debtsAndFuneralCost'
import { heirs } from './sections/heirs'
Expand All @@ -19,7 +11,6 @@ import { preSelection } from './sections/applicationTypeSelection'
import { prePaidHeirs } from './sections/prepaidInheritance/heirs'
import { inheritanceExecutor } from './sections/prepaidInheritance/inheritanceExecutor'
import { inheritance } from './sections/prepaidInheritance/inheritance'
import { prepaidOverview } from './sections/prepaidInheritance/overview'
import { finalStep } from './sections/finalStep'
import { prePaidApplicant } from './sections/prepaidInheritance/applicant'

Expand All @@ -35,7 +26,6 @@ export const prepaidInheritanceForm: Form = buildForm({
inheritance,
assets,
prePaidHeirs,
prepaidOverview,
finalStep,
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export const getForm = (): Form =>
children: [
buildMultiField({
title: m.preDataCollectionApplicationFor,
description: m.preDataCollectionApplicationFoDescription,
albinagu marked this conversation as resolved.
Show resolved Hide resolved
children: [
buildRadioField({
id: 'applicationFor',
title: '',
largeButtons: true,
backgroundColor: 'blue',
required: true,
options: [
{
value: ESTATE_INHERITANCE,
Expand Down
Loading
Loading