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

Farajaland form updates #805

Merged
merged 9 commits into from
Feb 15, 2024
4 changes: 3 additions & 1 deletion src/api/content/client/client.json
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@
"fieldAgentHome.requireUpdatesCountLoading": "Checking your declarations",
"fieldAgentHome.sentForReviewCount": "Sent for review ({total})",
"fieldAgentHome.zeroUpdatesText": "No declarations require updates",
"form.customField.label.numberOfDependants": "No. of dependants",
"form.field.label.addFile": "Upload",
"form.field.showLabel": "Show",
"form.field.hideLabel": "Hide",
Expand Down Expand Up @@ -2960,6 +2961,7 @@
"fieldAgentHome.requireUpdatesCountLoading": "Vérification de vos déclarations",
"fieldAgentHome.sentForReviewCount": "Envoyées pour révision ({total})",
"fieldAgentHome.zeroUpdatesText": "Aucune déclaration ne nécessite de mise à jour",
"form.customField.label.numberOfDependants": "Nombre de personnes à charge",
"form.field.showLabel": "Afficher",
"form.field.hideLabel": "Cacher",
"form.field.nidNotVerified": "Authentifier",
Expand Down Expand Up @@ -4233,4 +4235,4 @@
}
}
]
}
}
12 changes: 8 additions & 4 deletions src/form/addresses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import {
FATHER_DETAILS_DONT_EXIST,
MOTHER_DETAILS_DONT_EXIST,
SPOUSE_DETAILS_DONT_EXIST,
detailsDontExist,
hideIfInformantBrideOrGroom,
informantNotMotherOrFather,
isInformantSpouse,
mothersDetailsDontExistOnOtherPage,
primaryAddressSameAsOtherPrimaryAddress /*,
SPOUSE_DETAILS_DONT_EXIST*/
Expand Down Expand Up @@ -149,7 +151,7 @@ export const defaultAddressConfiguration: IAddressConfiguration[] = [
},
{
// DECEASED ADDRESS FIELDS
precedingFieldId: 'death.deceased.deceased-view-group.maritalStatus',
precedingFieldId: 'death.deceased.deceased-view-group.numberOfDependants',
configurations: [
{
config: AddressSubsections.PRIMARY_ADDRESS_SUBSECTION,
Expand All @@ -167,11 +169,13 @@ export const defaultAddressConfiguration: IAddressConfiguration[] = [
},
{
// INFORMANT ADDRESS FIELDS
precedingFieldId: 'death.informant.informant-view-group.informantID',
precedingFieldId:
'death.informant.informant-view-group.informantBirthRegistrationNumber',
configurations: [
{
config: AddressCopyConfigCases.PRIMARY_ADDRESS_SAME_AS_OTHER_PRIMARY,
label: formMessageDescriptors.primaryAddressSameAsDeceasedsPrimary,
conditionalCase: `${isInformantSpouse}`,
xComparisonSection: 'informant',
yComparisonSection: 'deceased'
},
Expand Down Expand Up @@ -229,7 +233,7 @@ export const defaultAddressConfiguration: IAddressConfiguration[] = [
conditionalCase: `((${FATHER_DETAILS_DONT_EXIST} || ${primaryAddressSameAsOtherPrimaryAddress}) && !(${mothersDetailsDontExistOnOtherPage}) || ((${detailsDontExist}) && (${mothersDetailsDontExistOnOtherPage})))`
}
]
},
},*/
{
// SPOUSE ADDRESS FIELDS
precedingFieldId: 'death.spouse.spouse-view-group.spouse-nid-seperator',
Expand All @@ -251,7 +255,7 @@ export const defaultAddressConfiguration: IAddressConfiguration[] = [
conditionalCase: `((${SPOUSE_DETAILS_DONT_EXIST} || ${primaryAddressSameAsOtherPrimaryAddress}) || (${detailsDontExist}))`
}
]
},*/
},
{
// PLACE OF MARRIAGE ADDRESS FIELDS
precedingFieldId:
Expand Down
46 changes: 30 additions & 16 deletions src/form/birth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
getFirstNameField,
getNationality,
otherInformantType,
getNationalID,
getDetailsExist,
getReasonNotExisting
} from '../common/common-required-fields'
Expand Down Expand Up @@ -60,11 +59,10 @@ import {
fatherFamilyNameConditionals,
informantNotMotherOrFather,
detailsExistConditional,
ageOfIndividualConditionals,
ageOfIndividualValidators,
ageOfParentsConditionals
} from '../common/default-validation-conditionals'
import {
getNationalIDValidators,
informantFirstNameConditionals,
informantFamilyNameConditionals,
informantBirthDateConditionals,
Expand All @@ -75,6 +73,7 @@ import { documentsSection, registrationSection } from './required-sections'
import { certificateHandlebars } from './certificate-handlebars'
import { getSectionMapping } from '@countryconfig/utils/mapping/section/birth/mapping-utils'
import { getCommonSectionMapping } from '@countryconfig/utils/mapping/field-mapping-utils'
import { getIDNumberFields, getIDType } from '../custom-fields'
// import { createCustomFieldExample } from '../custom-fields'

// ======================= FORM CONFIGURATION =======================
Expand Down Expand Up @@ -251,17 +250,22 @@ export const birthForm: ISerializedForm = {
exactDateOfBirthUnknownConditional.concat(
hideIfInformantMotherOrFather
),
ageOfIndividualConditionals
ageOfIndividualValidators
),
getNationality(
certificateHandlebars.informantNationality,
hideIfInformantMotherOrFather
), // Required field.
getNationalID(
'informantID',
getIDType(
'birth',
'informant',
hideIfNidIntegrationEnabled.concat(hideIfInformantMotherOrFather),
getNationalIDValidators('informant'),
certificateHandlebars.informantNID
true
),
...getIDNumberFields(
'informant',
hideIfNidIntegrationEnabled.concat(hideIfInformantMotherOrFather),
true
),
// preceding field of address fields
divider('informant-nid-seperator', [
Expand Down Expand Up @@ -331,11 +335,16 @@ export const birthForm: ISerializedForm = {
certificateHandlebars.motherNationality,
detailsExist
), // Required field.
getNationalID(
'iD',
getIDType(
'birth',
'mother',
hideIfNidIntegrationEnabled.concat(detailsExist),
true
),
...getIDNumberFields(
'mother',
hideIfNidIntegrationEnabled.concat(detailsExist),
getNationalIDValidators('mother'),
certificateHandlebars.motherNID
true
),
// preceding field of address fields
divider('mother-nid-seperator', detailsExist),
Expand Down Expand Up @@ -415,11 +424,16 @@ export const birthForm: ISerializedForm = {
certificateHandlebars.fatherNationality,
detailsExist
), // Required field.
getNationalID(
'iD',
getIDType(
'birth',
'father',
hideIfNidIntegrationEnabled.concat(detailsExist),
true
),
...getIDNumberFields(
'father',
hideIfNidIntegrationEnabled.concat(detailsExist),
getNationalIDValidators('father'),
certificateHandlebars.fatherNID
true
),
// preceding field of address fields
divider('father-nid-seperator', detailsExist),
Expand Down
14 changes: 12 additions & 2 deletions src/form/common/default-validation-conditionals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ export const hideIfInformantMotherOrFather = [
}
]

export const isInformantSpouse =
'!values.informantType || values.informantType==="SPOUSE"'

export const hideIfInformantSpouse = [
{
action: 'hide',
expression: isInformantSpouse
}
]

export const mothersDetailsExistConditionals = [
{
action: 'hide',
Expand Down Expand Up @@ -241,7 +251,7 @@ export const brideOrGroomAgeValidators = [
}
] satisfies Validator[]

export const ageOfIndividualConditionals: Validator[] = [
export const ageOfIndividualValidators: Validator[] = [
{
operation: 'range',
parameters: [12, 120]
Expand All @@ -253,7 +263,7 @@ export const ageOfIndividualConditionals: Validator[] = [
]

export const ageOfParentsConditionals = [
...ageOfIndividualConditionals,
...ageOfIndividualValidators,
{
operation: 'isValidParentsBirthDate',
parameters: [10, true]
Expand Down
141 changes: 140 additions & 1 deletion src/form/custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import { SerializedFormField } from './types/types'
import { formMessageDescriptors } from './common/messages'
import { Conditional, SerializedFormField } from './types/types'
import { getCustomFieldMapping } from '@countryconfig/utils/mapping/field-mapping-utils'
import { getNationalIDValidators } from './common/default-validation-conditionals'
import { camelCase } from 'lodash'
import { uppercaseFirstLetter } from '@countryconfig/utils'

// ======================= CUSTOM FIELD CONFIGURATION =======================

Expand Down Expand Up @@ -45,3 +49,138 @@ export function createCustomFieldExample(): SerializedFormField {
maxLength: 250
}
}

type ArrayElement<ArrayType> = ArrayType extends readonly (infer ElementType)[]
? ElementType
: never

const idTypeOptions = [
{
value: 'NATIONAL_ID' as const,
label: {
defaultMessage: 'National ID',
description: 'Option for form field: Type of ID',
id: 'form.field.label.iDTypeNationalID'
}
},
{
value: 'PASSPORT' as const,
label: {
defaultMessage: 'Passport',
description: 'Option for form field: Type of ID',
id: 'form.field.label.iDTypePassport'
}
},
{
value: 'BIRTH_REGISTRATION_NUMBER' as const,
label: {
defaultMessage: 'Birth Registration Number',
description: 'Option for form field: Type of ID',
id: 'form.field.label.iDTypeBRN'
}
},
{
value: 'NONE' as const,
label: {
defaultMessage: 'None',
description: 'Option for form field: Type of ID',
id: 'form.field.label.iDTypeNone'
}
}
]

type IDType = ArrayElement<typeof idTypeOptions>['value']

export function getIDType(
event: string,
sectionId: string,
conditionals: Conditional[] = [],
required: boolean
): SerializedFormField {
const fieldName: string = `${sectionId}IdType`
const fieldId: string = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`
return {
name: fieldName,
customQuestionMappingId: fieldId,
custom: true,
required,
type: 'SELECT_WITH_OPTIONS',
label: {
id: 'form.field.label.iDType',
description: 'A form field that asks for the type of ID.',
defaultMessage: 'Type of ID'
},
initialValue: '',
validator: [],
mapping: getCustomFieldMapping(fieldId),
placeholder: formMessageDescriptors.formSelectPlaceholder,
conditionals,
options: idTypeOptions
}
}

function getValidators(configCase: string, idValue: IDType) {
if (idValue === 'NATIONAL_ID') {
return getNationalIDValidators(configCase)
}
return []
}

export function getIDNumber(
sectionId: string,
idValue: IDType,
conditionals: Conditional[] = [],
required: boolean
): SerializedFormField {
const fieldName: string = `${sectionId}${uppercaseFirstLetter(
camelCase(idValue)
)}`
const validators = getValidators(sectionId, idValue)
// eslint-disable-next-line no-console
console.log('Custom field addded with handlebar: ', fieldName)
return {
name: fieldName,
required,
type: 'TEXT',
custom: true,
label: {
id: 'form.field.label.iD',
description: 'A form field that asks for the id number.',
defaultMessage: 'ID number'
},
initialValue: '',
validator: validators,
mapping: {
template: {
fieldName: fieldName,
operation: 'identityToFieldTransformer',
parameters: ['id', idValue]
},
mutation: {
operation: 'fieldToIdentityTransformer',
parameters: ['id', idValue]
},
query: {
operation: 'identityToFieldTransformer',
parameters: ['id', idValue]
}
},
conditionals: [
{
action: 'hide',
expression: `(values.${sectionId}IdType!=="${idValue}") || (values.${sectionId}IdType==="NONE")`
}
].concat(conditionals),
maxLength: 250
}
}

export function getIDNumberFields(
section: string,
conditionals: Conditional[] = [],
required: boolean
) {
return idTypeOptions
.filter((opt) => opt.value !== 'NONE')
.map((opt) => getIDNumber(section, opt.value, conditionals, required))
}
Loading
Loading