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

fix: unify declare form flow #385

Merged
merged 9 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 8 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
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 @@
id: 'event.birth.action.declare.form.section.child.field.dob.label'
}
},
{
id: 'child.placeOfBirth.divider.start',
type: 'DIVIDER',

Check failure on line 231 in src/form/v2/birth/forms/child.ts

View workflow job for this annotation

GitHub Actions / test

Type '"DIVIDER"' is not assignable to type '"TEXT" | "DATE" | "PARAGRAPH" | "RADIO_GROUP" | "BULLET_LIST" | "PAGE_HEADER" | "SELECT" | "CHECKBOX" | "FILE" | "COUNTRY" | "LOCATION"'.
label: emptyMessage
},
{
id: 'child.placeOfBirth',
type: 'SELECT',
Expand All @@ -233,7 +242,6 @@
},
options: placeOfBirthOptions
},

{
id: 'child.birthLocation',
type: 'LOCATION',
Expand All @@ -256,7 +264,7 @@
}
]
},
...appendConditionalsToFields({

Check failure on line 267 in src/form/v2/birth/forms/child.ts

View workflow job for this annotation

GitHub Actions / test

Type '{ id: string; type: "DIVIDER"; label: { defaultMessage: string; description: string; id: string; }; }' is not assignable to type '{ id: string; type: "TEXT"; label: TranslationConfig; options?: { type?: "number" | "text" | "email" | "password" | undefined; maxLength?: number | undefined; } | undefined; ... 7 more ...; placeholder?: TranslationConfig | undefined; } | ... 9 more ... | { ...; }'.
inputFields: getAddressFields(AddressType.childResidentialAddress),
newConditionals: [
{
Expand All @@ -267,7 +275,7 @@
}
]
}),
...appendConditionalsToFields({

Check failure on line 278 in src/form/v2/birth/forms/child.ts

View workflow job for this annotation

GitHub Actions / test

Type '{ id: string; type: "TEXT"; label: TranslationConfig; options?: { type?: "number" | "text" | "email" | "password" | undefined; maxLength?: number | undefined; } | undefined; ... 7 more ...; placeholder?: TranslationConfig | undefined; } | ... 13 more ... | { ...; }' is not assignable to type '{ id: string; type: "TEXT"; label: TranslationConfig; options?: { type?: "number" | "text" | "email" | "password" | undefined; maxLength?: number | undefined; } | undefined; ... 7 more ...; placeholder?: TranslationConfig | undefined; } | ... 9 more ... | { ...; }'.
inputFields: getAddressFields(AddressType.childOther),
newConditionals: [
{
Expand All @@ -278,9 +286,14 @@
}
]
}),
{
id: 'child.placeOfBirth.divider.end',
type: 'DIVIDER',

Check failure on line 291 in src/form/v2/birth/forms/child.ts

View workflow job for this annotation

GitHub Actions / test

Type '"DIVIDER"' is not assignable to type '"TEXT" | "DATE" | "PARAGRAPH" | "RADIO_GROUP" | "BULLET_LIST" | "PAGE_HEADER" | "SELECT" | "CHECKBOX" | "FILE" | "COUNTRY" | "LOCATION"'.
label: emptyMessage
},
{
id: 'child.attendantAtBirth',
type: 'SELECT',

Check failure on line 296 in src/form/v2/birth/forms/child.ts

View workflow job for this annotation

GitHub Actions / test

Type '"TEXT" | "DATE" | "PARAGRAPH" | "RADIO_GROUP" | "BULLET_LIST" | "PAGE_HEADER" | "SELECT" | "CHECKBOX" | "FILE" | "COUNTRY" | "LOCATION" | "DIVIDER"' is not assignable to type '"TEXT" | "DATE" | "PARAGRAPH" | "RADIO_GROUP" | "BULLET_LIST" | "PAGE_HEADER" | "SELECT" | "CHECKBOX" | "FILE" | "COUNTRY" | "LOCATION"'.
required: false,
label: {
defaultMessage: 'Attendant at birth',
Expand All @@ -291,7 +304,7 @@
},
{
id: 'child.birthType',
type: 'SELECT',

Check failure on line 307 in src/form/v2/birth/forms/child.ts

View workflow job for this annotation

GitHub Actions / test

Type '"TEXT" | "DATE" | "PARAGRAPH" | "RADIO_GROUP" | "BULLET_LIST" | "PAGE_HEADER" | "SELECT" | "CHECKBOX" | "FILE" | "COUNTRY" | "LOCATION" | "DIVIDER"' is not assignable to type '"TEXT" | "DATE" | "PARAGRAPH" | "RADIO_GROUP" | "BULLET_LIST" | "PAGE_HEADER" | "SELECT" | "CHECKBOX" | "FILE" | "COUNTRY" | "LOCATION"'.
required: false,
label: {
defaultMessage: 'Type of birth',
Expand All @@ -302,7 +315,7 @@
},
{
id: 'child.weightAtBirth',
type: 'TEXT',

Check failure on line 318 in src/form/v2/birth/forms/child.ts

View workflow job for this annotation

GitHub Actions / test

Type '"TEXT" | "DATE" | "PARAGRAPH" | "RADIO_GROUP" | "BULLET_LIST" | "PAGE_HEADER" | "SELECT" | "CHECKBOX" | "FILE" | "COUNTRY" | "LOCATION" | "DIVIDER"' is not assignable to type '"TEXT" | "DATE" | "PARAGRAPH" | "RADIO_GROUP" | "BULLET_LIST" | "PAGE_HEADER" | "SELECT" | "CHECKBOX" | "FILE" | "COUNTRY" | "LOCATION"'.
required: false,
label: {
defaultMessage: 'Weight at birth',
Expand All @@ -310,7 +323,12 @@
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 @@
defaultMessage: 'Birth Information',
description: 'Label for the birth information bullet list'
},
hideLabel: true,

Check failure on line 59 in src/form/v2/birth/forms/declare.ts

View workflow job for this annotation

GitHub Actions / test

Type '{ type: "BULLET_LIST"; id: string; label: { id: string; defaultMessage: string; description: string; }; hideLabel: true; items: { defaultMessage: string; description: string; id: string; }[]; font: "reg16"; }' is not assignable to type '{ id: string; type: "TEXT"; label: TranslationConfig; options?: { type?: "number" | "text" | "email" | "password" | undefined; maxLength?: number | undefined; } | undefined; ... 7 more ...; placeholder?: TranslationConfig | undefined; } | ... 9 more ... | { ...; }'.
items: [
{
defaultMessage:
Expand Down Expand Up @@ -96,24 +97,34 @@
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',

Check failure on line 114 in src/form/v2/birth/forms/declare.ts

View workflow job for this annotation

GitHub Actions / test

Type '"DIVIDER"' is not assignable to type '"TEXT" | "DATE" | "PARAGRAPH" | "RADIO_GROUP" | "BULLET_LIST" | "PAGE_HEADER" | "SELECT" | "CHECKBOX" | "FILE" | "COUNTRY" | "LOCATION"'.
label: emptyMessage
}
],
newConditionals: [
{
type: 'HIDE',
conditional: field('informant.relation')
.inArray([InformantTypes.MOTHER])
.apply()
}
]
},
}),

{
id: 'mother.reason',
type: 'TEXT',
Expand All @@ -126,8 +137,13 @@
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 @@
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',

Check failure on line 204 in src/form/v2/birth/forms/declare.ts

View workflow job for this annotation

GitHub Actions / test

Type '"DIVIDER"' is not assignable to type '"TEXT" | "DATE" | "PARAGRAPH" | "RADIO_GROUP" | "BULLET_LIST" | "PAGE_HEADER" | "SELECT" | "CHECKBOX" | "FILE" | "COUNTRY" | "LOCATION"'.
label: emptyMessage
}
],
newConditionals: [
{
type: 'HIDE',
conditional: field('informant.relation')
.inArray([InformantTypes.FATHER])
.apply()
}
]
},
}),
{
id: 'father.reason',
type: 'TEXT',
Expand All @@ -201,9 +226,14 @@
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'
}