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

Reason for delayed registration custom form field #894

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/api/content/client/client.json
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,8 @@
"form.field.label.docTypeMarriageNotice": "Notice of marriage",
"form.field.label.proofOfGroomsID": "Proof of groom's identity",
"form.field.label.proofOfBridesID": "Proof of bride's identity",
"form.customField.label.reasonForLateRegistrationBirth":"Reason for delayed registration",
"form.customField.label.reasonForLateRegistrationDeath":"Reason for late registration",
"misc.createDescription": "Choose a PIN that doesn't have 4 repeating digits or sequential numbers",
"misc.createTitle": "Create a PIN",
"misc.description.Complete": "The informant will receive an email with a registration number that they can use to collect their certificate.",
Expand Down Expand Up @@ -3329,6 +3331,8 @@
"form.field.select.placeholder": "Sélectionnez",
"form.field.tooltip.tooltipNationalID": "Il s'agit d'une info-bulle pour guider l'utilisateur dans la saisie de l'identifiant national.",
"form.field.dateRangepicker.checkbox.dateLabel": "{rangeStart} à {rangeEnd}",
"form.customField.label.reasonForLateRegistrationBirth":"Raison du retard d'inscription",
"form.customField.label.reasonForLateRegistrationDeath":"Raison de l'inscription tardive",
"form.group.reasonNotApplying.parents": "Pourquoi la mère et le père ne font-ils pas de demande ?",
"form.preview.group.label.english.name": "Nom anglais",
"form.preview.group.label.father.english.name": "Nom anglais du père",
Expand Down
2 changes: 1 addition & 1 deletion src/form/addresses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const defaultAddressConfiguration: IAddressConfiguration[] = [
// OPTIONS ARE THE FULL PLACE OF EVENT FIELDS, STANDARD ADDRESS FIELDS, ADDRESS SUBSECTION DIVIDERS, OR RADIO BUTTONS TO SIMPLIFY FORM ENTRY

// PLACE OF BIRTH ADDRESS FIELDS
precedingFieldId: 'birth.child.child-view-group.childBirthDate',
precedingFieldId: 'birth.child.child-view-group.reasonForLateRegistration',
configurations: [{ config: EventLocationAddressCases.PLACE_OF_BIRTH }]
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/form/birth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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 { createCustomFieldExample } from '../custom-fields'
import { getReasonForLateRegistration } from '../custom-fields'

// ======================= FORM CONFIGURATION =======================

Expand Down Expand Up @@ -189,6 +189,7 @@ export const birthForm: ISerializedForm = {
isValidChildBirthDate,
certificateHandlebars.eventDate
), // Required field.
getReasonForLateRegistration('birth'),
// PLACE OF BIRTH FIELDS WILL RENDER HERE
divider('place-of-birth-seperator'),
attendantAtBirth,
Expand Down
50 changes: 49 additions & 1 deletion src/form/custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import { MessageDescriptor } from 'react-intl'
import { SerializedFormField } from './types/types'
import { getCustomFieldMapping } from '@countryconfig/utils/mapping/field-mapping-utils'

Expand Down Expand Up @@ -41,7 +42,54 @@ export function createCustomFieldExample(): SerializedFormField {
initialValue: '',
validator: [], // EDIT VALIDATORS AS YOU SEE FIT
mapping: getCustomFieldMapping(fieldId), // ALL CUSTOM FIELDS MUST USE THIS MAPPING FUNCTION
conditionals: [], // EDIT VALIDATORS AS YOU SEE FIT
conditionals: [], // EDIT CONDITIONALS AS YOU SEE FIT
maxLength: 250
}
}

export function getReasonForLateRegistration(
event: string
): SerializedFormField {
const fieldName: string = 'reasonForLateRegistration'
const fieldId: string =
event === 'birth'
? `birth.child.child-view-group.${fieldName}`
: `death.deathEvent.death-event-details.${fieldName}`
const label: MessageDescriptor =
event === 'birth'
? {
id: 'form.customField.label.reasonForLateRegistrationBirth',
description:
'A form field that asks the reason for a late registration.',
defaultMessage: 'Reason for delayed registration'
}
: {
id: 'form.customField.label.reasonForLateRegistrationDeath',
description:
'A form field that asks the reason for a late registration.',
defaultMessage: 'Reason for late registration'
}
const expression: string =
event === 'birth'
? 'const pattern = /^\\d{4}-\\d{2}-\\d{2}$/; const today = new Date(); const eventDatePlusLateRegistrationTarget = new Date(values.childBirthDate); const lateRegistrationTarget = offlineCountryConfig && offlineCountryConfig.config.BIRTH.LATE_REGISTRATION_TARGET; eventDatePlusLateRegistrationTarget.setDate(eventDatePlusLateRegistrationTarget.getDate() + lateRegistrationTarget); !pattern.test(values.childBirthDate) || today < eventDatePlusLateRegistrationTarget;'
: 'const pattern = /^\\d{4}-\\d{2}-\\d{2}$/; const today = new Date(); const eventDatePlusLateRegistrationTarget = new Date(values.deathDate); const lateRegistrationTarget = offlineCountryConfig && offlineCountryConfig.config.DEATH.REGISTRATION_TARGET; eventDatePlusLateRegistrationTarget.setDate(eventDatePlusLateRegistrationTarget.getDate() + lateRegistrationTarget); !pattern.test(values.deathDate) || today < eventDatePlusLateRegistrationTarget;'

return {
name: fieldName,
customQuestionMappingId: fieldId,
custom: true,
required: true,
type: 'TEXT',
label,
initialValue: '',
validator: [],
mapping: getCustomFieldMapping(fieldId),
conditionals: [
{
action: 'hide',
expression
}
], // EDIT CONDITIONALS AS YOU SEE FIT
maxLength: 250
}
}
2 changes: 2 additions & 0 deletions src/form/death/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {
import { certificateHandlebars } from './certficate-handlebars'
import { getCommonSectionMapping } from '@countryconfig/utils/mapping/field-mapping-utils'
//import { getSectionMapping } from '@countryconfig/utils/mapping/section/death/mapping-utils'
import { getReasonForLateRegistration } from '../custom-fields'

// import { createCustomFieldExample } from '../custom-fields'

Expand Down Expand Up @@ -229,6 +230,7 @@ export const deathForm = {
}
]
),
getReasonForLateRegistration('death'),
getMannerOfDeath,
getCauseOfDeath,
getCauseOfDeathMethod,
Expand Down
Loading