Skip to content

Commit

Permalink
fix: update same address field conditional (#1010)
Browse files Browse the repository at this point in the history
* fix: update same address field conditional

* chore: update divider and address field conditionals

* chore: convert conditional expression to array
  • Loading branch information
Nil20 authored Jun 13, 2024
1 parent 69bbc49 commit 33b3b53
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
14 changes: 8 additions & 6 deletions src/form/addresses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import {
informantNotMotherOrFather,
isInformantSpouse,
mothersDetailsDontExistOnOtherPage,
primaryAddressSameAsOtherPrimaryAddress /*,
primaryAddressSameAsOtherPrimaryAddress,
hideIfDeceasedAddressNotAvailable,
hideIfMotherAddressNotAvailable /*,
SPOUSE_DETAILS_DONT_EXIST*/
} from '../common/default-validation-conditionals'
import { formMessageDescriptors } from '../common/messages'
Expand Down Expand Up @@ -121,14 +123,14 @@ export const defaultAddressConfiguration: IAddressConfiguration[] = [
{
config: AddressSubsections.PRIMARY_ADDRESS_SUBSECTION,
label: formMessageDescriptors.primaryAddress,
conditionalCase: `${FATHER_DETAILS_DONT_EXIST}`
conditionalCase: `${FATHER_DETAILS_DONT_EXIST} || ${hideIfMotherAddressNotAvailable[0].expression}`
},
{
config: AddressCopyConfigCases.PRIMARY_ADDRESS_SAME_AS_OTHER_PRIMARY,
label: formMessageDescriptors.primaryAddressSameAsOtherPrimary,
xComparisonSection: 'father',
yComparisonSection: 'mother',
conditionalCase: `(${detailsDontExist} || ${mothersDetailsDontExistOnOtherPage})`
conditionalCase: `(${detailsDontExist} || ${mothersDetailsDontExistOnOtherPage}) || ${hideIfMotherAddressNotAvailable[0].expression}`
},
{
config: AddressCases.PRIMARY_ADDRESS,
Expand Down Expand Up @@ -176,7 +178,7 @@ export const defaultAddressConfiguration: IAddressConfiguration[] = [
{
config: AddressCopyConfigCases.PRIMARY_ADDRESS_SAME_AS_OTHER_PRIMARY,
label: formMessageDescriptors.primaryAddressSameAsDeceasedsPrimary,
conditionalCase: `${isInformantSpouse}`,
conditionalCase: `${isInformantSpouse} || ${hideIfDeceasedAddressNotAvailable[0].expression}`,
xComparisonSection: 'informant',
yComparisonSection: 'deceased'
},
Expand Down Expand Up @@ -242,14 +244,14 @@ export const defaultAddressConfiguration: IAddressConfiguration[] = [
{
config: AddressSubsections.PRIMARY_ADDRESS_SUBSECTION,
label: formMessageDescriptors.primaryAddress,
conditionalCase: `${SPOUSE_DETAILS_DONT_EXIST}`
conditionalCase: `${SPOUSE_DETAILS_DONT_EXIST} || ${hideIfDeceasedAddressNotAvailable[0].expression}`
},
{
config: AddressCopyConfigCases.PRIMARY_ADDRESS_SAME_AS_OTHER_PRIMARY,
label: formMessageDescriptors.primaryAddressSameAsDeceasedsPrimary,
xComparisonSection: 'spouse',
yComparisonSection: 'deceased',
conditionalCase: `${detailsDontExist}`
conditionalCase: `${detailsDontExist} || ${hideIfDeceasedAddressNotAvailable[0].expression}`
},
{
config: AddressCases.PRIMARY_ADDRESS,
Expand Down
8 changes: 6 additions & 2 deletions src/form/birth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ import {
informantNotMotherOrFather,
detailsExistConditional,
ageOfIndividualValidators,
ageOfParentsConditionals
ageOfParentsConditionals,
hideIfMotherAddressNotAvailable
} from '../common/default-validation-conditionals'
import {
informantFirstNameConditionals,
Expand Down Expand Up @@ -440,7 +441,10 @@ export const birthForm: ISerializedForm = {
// preceding field of address fields
divider('father-nid-seperator', detailsExist),
// ADDRESS FIELDS WILL RENDER HERE
divider('father-address-seperator', detailsExist),
divider('father-address-seperator', [
...detailsExist,
...hideIfMotherAddressNotAvailable
]),
getMaritalStatus(certificateHandlebars.fatherMaritalStatus, [
{
action: 'hide',
Expand Down
14 changes: 14 additions & 0 deletions src/form/common/default-validation-conditionals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ export const hideIfInformantMotherOrFather = [
export const isInformantSpouse =
'!values.informantType || values.informantType==="SPOUSE"'

export const hideIfDeceasedAddressNotAvailable = [
{
action: 'hide',
expression: '!(draftData && draftData.deceased?.countryPrimaryDeceased)'
}
]

export const hideIfMotherAddressNotAvailable = [
{
action: 'hide',
expression: '!(draftData && draftData.mother?.countryPrimaryMother)'
}
]

export const hideIfInformantSpouse = [
{
action: 'hide',
Expand Down
13 changes: 10 additions & 3 deletions src/form/death/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ import {
spouseFamilyNameConditionals,
spouseFirstNameConditionals,
hideIfInformantSpouse,
hideIfNidIntegrationEnabled
hideIfNidIntegrationEnabled,
hideIfDeceasedAddressNotAvailable
} from '../common/default-validation-conditionals'
import { documentsSection, registrationSection } from './required-sections'
import {
Expand Down Expand Up @@ -360,9 +361,15 @@ export const deathForm = {
getIDType('death', 'spouse', detailsExist, true),
...getIDNumberFields('spouse', detailsExist, true),
// preceding field of address fields
divider('spouse-nid-seperator', detailsExist),
divider('spouse-nid-seperator', [
...detailsExist,
...hideIfDeceasedAddressNotAvailable
]),
// ADDRESS FIELDS WILL RENDER HERE
divider('spouse-address-separator')
divider(
'spouse-address-separator',
hideIfDeceasedAddressNotAvailable
)
],
previewGroups: [spouseNameInEnglish]
}
Expand Down

0 comments on commit 33b3b53

Please sign in to comment.