Skip to content

Commit

Permalink
Merge pull request #1218 from opencrvs/merge-cc-to-develop
Browse files Browse the repository at this point in the history
Merge cc to develop
  • Loading branch information
Zangetsu101 authored Jan 29, 2025
2 parents dffd951 + 9a1bbb1 commit d04b695
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 58 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@hapi/h2o2": "^9.1.0",
"@hapi/hapi": "^20.0.1",
"@hapi/inert": "^6.0.3",
"@opencrvs/toolkit": "0.0.31-rr",
"@opencrvs/toolkit": "0.0.32-jr",
"@types/chalk": "^2.2.0",
"@types/code": "^4.0.3",
"@types/csv2json": "^1.4.0",
Expand Down
24 changes: 21 additions & 3 deletions src/form/v2/birth/forms/child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

import { defineFormPage, TranslationConfig } from '@opencrvs/toolkit/events'
import { field } from '@opencrvs/toolkit/conditionals'
import { appendConditionalsToFields, createSelectOptions } from '../../utils'
import {
appendConditionalsToFields,
createSelectOptions,
emptyMessage
} from '../../utils'
import { AddressType, getAddressFields } from '../../person/address'

const GenderTypes = {
Expand Down Expand Up @@ -222,6 +226,11 @@ export const childPage = defineFormPage({
id: 'event.birth.action.declare.form.section.child.field.dob.label'
}
},
{
id: 'child.placeOfBirth.divider.start',
type: 'DIVIDER',
label: emptyMessage
},
{
id: 'child.placeOfBirth',
type: 'SELECT',
Expand All @@ -233,7 +242,6 @@ export const childPage = defineFormPage({
},
options: placeOfBirthOptions
},

{
id: 'child.birthLocation',
type: 'LOCATION',
Expand Down Expand Up @@ -278,6 +286,11 @@ export const childPage = defineFormPage({
}
]
}),
{
id: 'child.placeOfBirth.divider.end',
type: 'DIVIDER',
label: emptyMessage
},
{
id: 'child.attendantAtBirth',
type: 'SELECT',
Expand Down Expand Up @@ -310,7 +323,12 @@ export const childPage = defineFormPage({
id: 'event.birth.action.declare.form.section.child.field.weightAtBirth.label'
},
options: {
type: 'number'
type: 'number',
postfix: {
defaultMessage: 'Kilograms (kg)',
description: 'This is the postfix for the weight field',
id: 'event.birth.action.declare.form.section.child.field.weightAtBirth.postfix'
}
}
}
]
Expand Down
88 changes: 59 additions & 29 deletions src/form/v2/birth/forms/declare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
*/

import { defineForm } from '@opencrvs/toolkit/events'
import { and, field } from '@opencrvs/toolkit/conditionals'
import { and, field, or } from '@opencrvs/toolkit/conditionals'
import { childPage } from './child'
import { informantPage, InformantTypes } from './informant'
import { appendConditionalsToFields } from '../../utils'
import { appendConditionalsToFields, emptyMessage } from '../../utils'
import { getPersonInputFields, PersonType } from '../../person'

export const BIRTH_DECLARE_FORM = defineForm({
Expand Down Expand Up @@ -56,6 +56,7 @@ export const BIRTH_DECLARE_FORM = defineForm({
defaultMessage: 'Birth Information',
description: 'Label for the birth information bullet list'
},
hideLabel: true,
items: [
{
defaultMessage:
Expand Down Expand Up @@ -96,24 +97,34 @@ export const BIRTH_DECLARE_FORM = defineForm({
id: 'form.section.mother.title'
},
fields: [
{
id: 'mother.detailsNotAvailable',
type: 'CHECKBOX',
required: true,
label: {
defaultMessage: "Mother's details not available",
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.mother.field.detailsNotAvailable.label`
},
conditionals: [
...appendConditionalsToFields({
inputFields: [
{
id: 'mother.detailsNotAvailable',
type: 'CHECKBOX',
required: true,
label: {
defaultMessage: "Mother's details are not available",
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.mother.field.detailsNotAvailable.label`
}
},
{
id: 'mother.details.divider',
type: 'DIVIDER',
label: emptyMessage
}
],
newConditionals: [
{
type: 'HIDE',
conditional: field('informant.relation')
.inArray([InformantTypes.MOTHER])
.apply()
}
]
},
}),

{
id: 'mother.reason',
type: 'TEXT',
Expand All @@ -126,8 +137,13 @@ export const BIRTH_DECLARE_FORM = defineForm({
conditionals: [
{
type: 'HIDE',
conditional: field('mother.detailsNotAvailable').or((field) =>
field.isUndefined().inArray(['false'])
conditional: or(
field('mother.detailsNotAvailable')
.or((field) => field.isUndefined().inArray(['false']))
.apply(),
field('informant.relation')
.inArray([InformantTypes.MOTHER])
.apply()
)
}
]
Expand Down Expand Up @@ -171,24 +187,33 @@ export const BIRTH_DECLARE_FORM = defineForm({
id: 'form.section.father.title'
},
fields: [
{
id: 'father.detailsNotAvailable',
type: 'CHECKBOX',
required: true,
label: {
defaultMessage: "Father's details not available",
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.father.field.detailsNotAvailable.label`
},
conditionals: [
...appendConditionalsToFields({
inputFields: [
{
id: 'father.detailsNotAvailable',
type: 'CHECKBOX',
required: true,
label: {
defaultMessage: "Father's details are not available",
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.father.field.detailsNotAvailable.label`
}
},
{
id: 'father.details.divider',
type: 'DIVIDER',
label: emptyMessage
}
],
newConditionals: [
{
type: 'HIDE',
conditional: field('informant.relation')
.inArray([InformantTypes.FATHER])
.apply()
}
]
},
}),
{
id: 'father.reason',
type: 'TEXT',
Expand All @@ -201,9 +226,14 @@ export const BIRTH_DECLARE_FORM = defineForm({
conditionals: [
{
type: 'HIDE',
conditional: field('father.detailsNotAvailable')
.or((field) => field.isUndefined().inArray(['false']))
.apply()
conditional: or(
field('father.detailsNotAvailable')
.or((field) => field.isUndefined().inArray(['false']))
.apply(),
field('informant.relation')
.inArray([InformantTypes.FATHER])
.apply()
)
}
]
},
Expand Down
16 changes: 13 additions & 3 deletions src/form/v2/birth/forms/informant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

import { defineFormPage, TranslationConfig } from '@opencrvs/toolkit/events'
import { field } from '@opencrvs/toolkit/conditionals'
import { appendConditionalsToFields, createSelectOptions } from '../../utils'
import {
appendConditionalsToFields,
createSelectOptions,
emptyMessage
} from '../../utils'
import { getPersonInputCommonFields, PersonType } from '../../person'
import { getAddressFields } from '../../person/address'

Expand Down Expand Up @@ -116,7 +120,13 @@ export const informantPage = defineFormPage({
...appendConditionalsToFields({
inputFields: [
...getPersonInputCommonFields(PersonType.informant),
...getAddressFields(PersonType.informant)
...getAddressFields(PersonType.informant),

{
id: 'informant.address.divider.end',
type: 'DIVIDER',
label: emptyMessage
}
],
newConditionals: [
{
Expand All @@ -125,7 +135,7 @@ export const informantPage = defineFormPage({
.or((field) =>
field
.isUndefined()
.not.inArray([InformantTypes.MOTHER, InformantTypes.FATHER])
.inArray([InformantTypes.MOTHER, InformantTypes.FATHER])
)
.apply()
}
Expand Down
13 changes: 7 additions & 6 deletions src/form/v2/person/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ export const getAddressFields = (person: AddressType): FieldConfig[] => {
}
},
{
id: `${prefix}.village`,
id: `${prefix}.street`,
type: 'TEXT',
required: false,
label: {
defaultMessage: 'Area / Ward / Mouja / Village',
defaultMessage: 'Street',
description: 'This is the label for the field',
id: `event.action.declare.form.section.person.field.address.village.label`
id: `event.action.declare.form.section.person.field.address.street.label`
}
},
{
Expand Down Expand Up @@ -214,15 +214,16 @@ export const getAddressFields = (person: AddressType): FieldConfig[] => {
defaultMessage: 'Urban or Rural',
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.${person}.field.address.urbanOrRural.label`
}
},
hideLabel: true
},
...appendConditionalsToFields({
inputFields: urbanAddressFields,
newConditionals: [
{
type: 'HIDE',
conditional: field(`${prefix}.urbanOrRural`)
.or((field) => field.isUndefined().not.inArray(['RURAL']))
.or((field) => field.isUndefined().inArray(['RURAL']))
.apply()
}
]
Expand All @@ -240,7 +241,7 @@ export const getAddressFields = (person: AddressType): FieldConfig[] => {
{
type: 'HIDE',
conditional: field(`${prefix}.urbanOrRural`)
.or((field) => field.isUndefined().inArray(['RURAL']))
.or((field) => field.isUndefined().not.inArray(['RURAL']))
.apply()
}
]
Expand Down
35 changes: 23 additions & 12 deletions src/form/v2/person/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import { FieldConfig, TranslationConfig } from '@opencrvs/toolkit/events'
import { field } from '@opencrvs/toolkit/conditionals'
import { getAddressFields } from './address'
import { appendConditionalsToFields, createSelectOptions } from '../utils'
import {
appendConditionalsToFields,
createSelectOptions,
emptyMessage
} from '../utils'

export const PersonType = {
father: 'father',
Expand Down Expand Up @@ -297,6 +301,13 @@ export const getPersonInputCommonFields = (
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.${person}.field.age.label`
},
options: {
postfix: {
defaultMessage: 'years',
description: 'This is the postfix for age field',
id: `event.birth.action.declare.form.section.${person}.field.age.postfix`
}
},
conditionals: [
{
type: 'HIDE',
Expand All @@ -317,6 +328,11 @@ export const getPersonInputCommonFields = (
}
},
...getIdFields(person),
{
id: `${person}.address.divider.start`,
type: 'DIVIDER',
label: emptyMessage
},
{
id: `${person}.addressHelper`,
type: 'PARAGRAPH',
Expand All @@ -325,23 +341,13 @@ export const getPersonInputCommonFields = (
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.${person}.field.addressHelper.label`
},
options: { fontVariant: 'h2' }
options: { fontVariant: 'h3' }
}
]

const fatherAddressFields = [
...appendConditionalsToFields({
inputFields: [
{
id: `${PersonType.father}.addressSameAsHelper`,
type: 'PARAGRAPH',
label: {
defaultMessage: "Same as mother's usual place of residence?",
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.${PersonType.father}.field.addressSameAsHelper.label`
},
options: { fontVariant: 'reg16' }
},
{
id: `${PersonType.father}.addressSameAs`,
type: 'RADIO_GROUP',
Expand Down Expand Up @@ -381,6 +387,11 @@ export const getPersonInputFields = (person: PersonType): FieldConfig[] => {
return [
...getPersonInputCommonFields(person),
...(isFather ? fatherAddressFields : getAddressFields(person)),
{
id: `${person}.address.divider.end`,
type: 'DIVIDER',
label: emptyMessage
},
{
id: `${person}.maritalStatus`,
type: 'SELECT',
Expand Down
6 changes: 6 additions & 0 deletions src/form/v2/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ export const createSelectOptions = <
value,
label: messageDescriptors[key as keyof T]
}))

export const emptyMessage = {
defaultMessage: '',
description: 'empty string',
id: 'messages.emptyString'
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1712,10 +1712,10 @@
dependencies:
"@octokit/openapi-types" "^18.0.0"

"@opencrvs/[email protected].31-rr":
version "0.0.31-rr"
resolved "https://registry.yarnpkg.com/@opencrvs/toolkit/-/toolkit-0.0.31-rr.tgz#d7e5ca7dc19e205b7784134f9f43c471e1d94651"
integrity sha512-uldvtVncmuXAeC4/IGmCw1MWpiyxrxxny92GAnPLULKcJlQsRlYV6SFH8fd9NTm/W3el+hsyI5X/vbv1aoCbHA==
"@opencrvs/[email protected].32-jr":
version "0.0.32-jr"
resolved "https://registry.yarnpkg.com/@opencrvs/toolkit/-/toolkit-0.0.32-jr.tgz#69187597d01f67de7a0cd5d8d639b687df5f27c2"
integrity sha512-97heLb0mGJYoRIVCugaGiYxK+oi3bcggPZf2nLXu/0SHlcwZCgGCsRu+up3kvBN6QmOGZq05zNQrosvh0fa54w==
dependencies:
"@trpc/client" "^11.0.0-rc.648"
"@trpc/server" "^11.0.0-rc.532"
Expand Down

0 comments on commit d04b695

Please sign in to comment.