Skip to content

Commit

Permalink
feat: Make it posible to select only child for health insurance decla…
Browse files Browse the repository at this point in the history
…ration and fix a bug that stopped the list of applicants from including children
  • Loading branch information
norda-gunni committed Aug 29, 2024
1 parent 58ad76e commit d0ec816
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1658,4 +1658,4 @@
],
"data": [],
"callbacks": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
getCountryNameFromCode,
getFullNameFromExternalData,
getInsuranceStatus,
getSelectedFamily,
getSelectedApplicants,
getApplicantAsOption,
getSpouseAsOptions,
hasFamilySelected,
} from '../utils'
Expand All @@ -48,6 +49,7 @@ import {
import format from 'date-fns/format'
import sub from 'date-fns/sub'
import { ApplicantType } from '../shared/constants'
import { get } from 'lodash'

export const HealthInsuranceDeclarationForm: Form = buildForm({
id: 'HealthInsuranceDeclarationDraft',
Expand Down Expand Up @@ -268,6 +270,14 @@ export const HealthInsuranceDeclarationForm: Form = buildForm({
id: 'registerPersonsMultiFiled',
title: m.application.registerPersons.sectionDescription,
children: [
buildCheckboxField({
id: 'selectedApplicants.registerPersonsApplicantCheckboxField',
title: m.application.registerPersons.applicantTitle,
defaultValue: (application: any) => [
getApplicantAsOption(application.externalData)[0]?.value,
],
options: ({ externalData }) => getApplicantAsOption(externalData),
}),
buildCheckboxField({
id: 'selectedApplicants.registerPersonsSpouseCheckboxField',
title: m.application.registerPersons.spousetitle,
Expand Down Expand Up @@ -489,11 +499,11 @@ export const HealthInsuranceDeclarationForm: Form = buildForm({
),
}),
buildDividerField({}),
// Family table
// Applicants table
buildStaticTableField({
title: m.application.overview.familyTableTitle,
title: m.application.overview.applicantsTableTitle,
rows: ({ answers, externalData }) =>
getSelectedFamily(
getSelectedApplicants(
answers as HealthInsuranceDeclaration,
externalData,
),
Expand All @@ -502,8 +512,6 @@ export const HealthInsuranceDeclarationForm: Form = buildForm({
applicantInformationMessages.labels.nationalId,
'Tengsl',
],
condition: (answers) =>
hasFamilySelected(answers as HealthInsuranceDeclaration),
}),
buildDividerField({
condition: (answers) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ export const HealthInsuranceDeclarationSchema = z.object({
.refine((v) => !!v),
selectedApplicants: z
.object({
registerPersonsApplicantCheckboxField: z.string().array().optional(),
registerPersonsSpouseCheckboxField: z.string().array().optional(),
registerPersonsChildrenCheckboxField: z.string().array().optional(),
isHealthInsured: z.boolean(),
})
.superRefine((v, ctx) => {
console.log('validation object', v)
if (
!v.isHealthInsured &&
!v.registerPersonsApplicantCheckboxField?.length &&
!v.registerPersonsSpouseCheckboxField?.length &&
!v.registerPersonsChildrenCheckboxField?.length
) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ['registerPersonsApplicantCheckboxField'],
params: errors.fields.noSelectedApplicant,
})
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ['registerPersonsChildrenCheckboxField'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ export const application = {
studentOrTourist: defineMessages({
sectionTitle: {
id: 'hid.application:studentOrTourist.section.title',
defaultMessage: 'Námsmaður/ferðamaður',
defaultMessage: 'Nám/ferðir',
description: 'Student or Tourist section title',
},
sectionDescription: {
id: 'hid.application:studentOrTourist.section.description',
defaultMessage: 'Ertu ferðamaður eða námsmaður?',
defaultMessage: 'Er sótt um vegna ferða eða náms?',
description: 'Student or Tourist section description',
},
touristRadioFieldText: {
Expand Down Expand Up @@ -79,9 +79,14 @@ export const application = {
},
sectionDescription: {
id: 'hid.application:registerPersons.section.description',
defaultMessage: 'Ég er einnig að sækja um fyrir',
defaultMessage: 'Ég er að sækja um fyrir',
description: 'Register persons section description',
},
applicantTitle: {
id: 'hid.application:registerPersons.section.applicantTitle',
defaultMessage: 'Umsækjandi',
description: 'Register persons title',
},
spousetitle: {
id: 'hid.application:registerPersons.section.spouseTitle',
defaultMessage: 'Maki',
Expand Down Expand Up @@ -116,7 +121,7 @@ export const application = {
},
studentSectionPlaceholderText: {
id: 'hid.application:residency.section.student.placeholderSelectText',
defaultMessage: 'Veldur land sem þú ferðast til',
defaultMessage: 'Veldur land sem ferðast á til',
description: 'Student residency selection placeholder text',
},
}),
Expand Down Expand Up @@ -200,43 +205,48 @@ export const application = {
},
studentOrTouristTitle: {
id: 'hid.application:overview.section.studentOrTouristTitle',
defaultMessage: 'Ertu ferðamaður eða námsmaður',
defaultMessage: 'Er sótt um vegna ferða eða náms',
description: 'Overview section Student or Tourist title',
},
studentOrTouristTouristText: {
id: 'hid.application:overview.section.studentOrTouristTouristText',
defaultMessage: 'Ferðamaður',
defaultMessage: 'Ferða',
description: 'Overview section Student or Tourist: Tourist text',
},
studentOrTouristStudentText: {
id: 'hid.application:overview.section.studentOrTouristStudentText',
defaultMessage: 'Námsmaður',
defaultMessage: 'Náms',
description: 'Overview section Student or Tourist: Student text',
},
applicantInfoTitle: {
id: 'hid.application:overview.section.applicantTitle',
defaultMessage: 'Persónu upplýsingar',
description: 'Overview section applicant title',
},
familyTableTitle: {
id: 'hid.application:overview.section.familyTableHeader',
defaultMessage: 'Maki og börn',
description: 'Overview section family table title',
applicantsTableTitle: {
id: 'hid.application:overview.section.applicantsTableHeader',
defaultMessage: 'Sótt er um fyrir',
description: 'Overview section applicant table title',
},
familyTableRelationHeader: {
id: 'hid.application:overview.section.familyTableHeaderRelationText',
defaultMessage: 'Tengsl',
description: 'Overview section family table title',
description: 'Overview section applicant table title',
},
familyTableRelationApplicantText: {
id: 'hid.application:overview.section.applicantTableApplicantRelationText',
defaultMessage: 'Umsækjandi',
description: 'Overview section applicant table applicant text',
},
familyTableRelationSpouseText: {
id: 'hid.application:overview.section.familyTableSpouseRelationText',
id: 'hid.application:overview.section.applicantTableSpouseRelationText',
defaultMessage: 'Maki',
description: 'Overview section family table spouse relation text',
description: 'Overview section applicant table spouse relation text',
},
familyTableRelationChildText: {
id: 'hid.application:overview.section.familyTableChildRelationText',
id: 'hid.application:overview.section.applicantTableChildRelationText',
defaultMessage: 'Barn',
description: 'Overview section family table child relation text',
description: 'Overview section applicant table child relation text',
},
dateTitle: {
id: 'hid.application:overview.section.DateTitle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ export const getChildrenAsOptions = (externalData: ExternalData): Option[] => {
return []
}

export const getApplicantFromExternalData = (
externalData: ExternalData,
): NationalRegistryIndividual => {
return externalData.nationalRegistry?.data as NationalRegistryIndividual
}

export const getApplicantAsOption = (externalData: ExternalData): Option[] => {
const individual = getApplicantFromExternalData(externalData)
return [
{
value: individual?.nationalId,
label: individual?.fullName,
subLabel: `${format(individual?.nationalId)}`,
},
]
}

export const getSpouseAsOptions = (externalData: ExternalData): Option[] => {
const spouse = getSpouseFromExternalData(externalData)

Expand All @@ -150,16 +167,33 @@ export const getSpouseAsOptions = (externalData: ExternalData): Option[] => {
return []
}

export const getSelectedFamily = (
export const getSelectedApplicants = (
answers: HealthInsuranceDeclaration,
externalData: ExternalData,
) => {
const applicant = getApplicantFromExternalData(externalData)
const spouse = getSpouseFromExternalData(externalData)
const children = getChildrenFromExternalData(externalData)
let selectedFamily: StaticText[][] = []
let selectedApplicants: StaticText[][] = []

selectedApplicants = selectedApplicants.concat(
answers.selectedApplicants?.registerPersonsApplicantCheckboxField
? answers.selectedApplicants?.registerPersonsApplicantCheckboxField?.map(
(a) => {
if (a === applicant.nationalId) {
return [
applicant.fullName,
applicant.nationalId,
m.overview.familyTableRelationApplicantText,
]
} else return []
},
)
: [],
)

if (spouse) {
selectedFamily = selectedFamily.concat(
selectedApplicants = selectedApplicants.concat(
answers.selectedApplicants?.registerPersonsSpouseCheckboxField
? answers.selectedApplicants?.registerPersonsSpouseCheckboxField?.map(
(s) => {
Expand Down Expand Up @@ -187,11 +221,10 @@ export const getSelectedFamily = (
]
},
)

if (selectedChildren) {
selectedFamily.concat(selectedChildren)
selectedApplicants = selectedApplicants.concat(selectedChildren)
}
return selectedFamily
return selectedApplicants
}

export const getInsuranceStatementDataFromExternalData = (
Expand Down

0 comments on commit d0ec816

Please sign in to comment.