Skip to content

Commit

Permalink
feat: create address input (#362)
Browse files Browse the repository at this point in the history
* chore: update yarn.lock

* feat: wip: birth event v2

* feat: use select option in gender, attendantAtBirth and birthType

* fix: use number for weight at birth

* feat: person input wip

* feat: show dob or age based on dobUnknown checkbox

* chore: rename directory

* amend: import from renamed directory

* feat: add informant relation to birth form

* feat: render informant fields based on relation to child

* feat: separate the logic for concatenating field id

* feat: complete informant details apart form person inputs

* feat: implement id and address

* refactor: create utils

* fix: handle undefined values in conditionals

* feat: implement father and mother details

* feat: implement upload supporting document

* fix: use simpler concat

* feat: use country field

* feat: add place of birth

* fix: typo

* fix: align label and required properties with legecy birth

* fix: font of bulletList

* feat: add helper texts

* chore: bump up @opencrvs/toolkit

* chore: update yarn.lock

* feat: use Location type in address

* feat: implement urbanOrRural

* feat: implement health_failities

* feat: add addressInput in tennis-club-membership

* fix: update ids of other country input fields

* rename: BirthEvent to birthEvent

* chore: remove the messages that are not in use

* chore: remove unused

* refactor: use informantType instead of hardcoding

* refactor: birth event

* chore: bump up toolkit

* feat: add relation to child for someone else

* feat: usual place of residence  same as mother

* refactor: make suggested changes

* fix: update types
  • Loading branch information
jamil314 authored and tareq89 committed Jan 21, 2025
1 parent b550f84 commit 1b6c7b8
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 72 deletions.
17 changes: 16 additions & 1 deletion src/form/tennis-club-membership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
field,
deduplication
} from '@opencrvs/toolkit/conditionals'
import { getAddressFields } from './v2/person/address'

const TENNIS_CLUB_FORM = defineForm({
label: {
Expand Down Expand Up @@ -112,7 +113,21 @@ const TENNIS_CLUB_FORM = defineForm({
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.who.field.image.label'
}
}
},
{
id: 'applicant.address.helper',
type: 'PARAGRAPH',
required: false,
label: {
defaultMessage: "Applicant's address",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.who.field.address.helper.label'
},
options: {
fontVariant: 'h3'
}
},
...getAddressFields('applicant')
]
},
{
Expand Down
11 changes: 7 additions & 4 deletions src/form/v2/birth/forms/child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { defineFormPage, TranslationConfig } from '@opencrvs/toolkit/events'
import { field } from '@opencrvs/toolkit/conditionals'
import { appendConditionalsToFields, createSelectOptions } from '../../utils'
import { getAddressFields } from '../../person/address'
import { AddressType, getAddressFields } from '../../person/address'

const GenderTypes = {
MALE: 'male',
Expand Down Expand Up @@ -235,13 +235,16 @@ export const childPage = defineFormPage({
},
{
id: 'child.birthLocation',
type: 'TEXT', // @ToDo: select
type: 'LOCATION',
required: true,
label: {
defaultMessage: 'Health Institution',
description: 'This is the label for the field',
id: 'event.birth.action.declare.form.section.child.field.birthLocation.label'
},
options: {
type: 'HEALTH_FACILITY'
},
conditionals: [
{
type: 'HIDE',
Expand All @@ -252,7 +255,7 @@ export const childPage = defineFormPage({
]
},
...appendConditionalsToFields({
inputFields: getAddressFields('child.privateHome'),
inputFields: getAddressFields(AddressType.childResidentialAddress),
newConditionals: [
{
type: 'HIDE',
Expand All @@ -263,7 +266,7 @@ export const childPage = defineFormPage({
]
}),
...appendConditionalsToFields({
inputFields: getAddressFields('child.other'),
inputFields: getAddressFields(AddressType.childOther),
newConditionals: [
{
type: 'HIDE',
Expand Down
6 changes: 3 additions & 3 deletions src/form/v2/birth/forms/declare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { field, and } from '@opencrvs/toolkit/conditionals'
import { childPage } from './child'
import { informantPage, InformantTypes } from './informant'
import { appendConditionalsToFields } from '../../utils'
import { getPersonInputFields } from '../../person'
import { getPersonInputFields, PersonType } from '../../person'

export const BIRTH_DECLARE_FORM = defineForm({
label: {
Expand Down Expand Up @@ -134,7 +134,7 @@ export const BIRTH_DECLARE_FORM = defineForm({
},
...appendConditionalsToFields({
inputFields: [
...getPersonInputFields('mother'),
...getPersonInputFields(PersonType.mother),
{
id: 'mother.previousBirths',
type: 'TEXT',
Expand Down Expand Up @@ -206,7 +206,7 @@ export const BIRTH_DECLARE_FORM = defineForm({
]
},
...appendConditionalsToFields({
inputFields: getPersonInputFields('father'),
inputFields: getPersonInputFields(PersonType.father),
newConditionals: [
{
type: 'HIDE',
Expand Down
26 changes: 24 additions & 2 deletions src/form/v2/birth/forms/informant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import { defineFormPage, TranslationConfig } from '@opencrvs/toolkit/events'
import { field } from '@opencrvs/toolkit/conditionals'
import { appendConditionalsToFields, createSelectOptions } from '../../utils'
import { getInformantFields } from '../../person'
import { getPersonInputCommonFields, PersonType } from '../../person'
import { getAddressFields } from '../../person/address'

export const InformantTypes = {
MOTHER: 'MOTHER',
Expand Down Expand Up @@ -92,8 +93,29 @@ export const informantPage = defineFormPage({
},
options: birthInformantTypeOptions
},
{
id: 'informant.other.relation',
type: 'TEXT',
required: true,
label: {
defaultMessage: 'Relationship to child',
description: 'This is the label for the field',
id: 'event.birth.action.declare.form.section.informant.field.other.relation.label'
},
conditionals: [
{
type: 'HIDE',
conditional: field('informant.relation').isUndefinedOrNotInArray([
InformantTypes.OTHER
])
}
]
},
...appendConditionalsToFields({
inputFields: getInformantFields('informant'),
inputFields: [
...getPersonInputCommonFields(PersonType.informant),
...getAddressFields(PersonType.informant)
],
newConditionals: [
{
type: 'HIDE',
Expand Down
132 changes: 107 additions & 25 deletions src/form/v2/person/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,42 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import { FieldConfig } from '@opencrvs/toolkit/events'
import { FieldConfig, TranslationConfig } from '@opencrvs/toolkit/events'
import { field } from '@opencrvs/toolkit/conditionals'
import { appendConditionalsToFields } from '../utils'
import { appendConditionalsToFields, createSelectOptions } from '../utils'
import { PersonType } from './index'

export const getAddressFields = (person: string): FieldConfig[] => {
// @Todo: Same as mother or deseased
export const AddressType = {
childResidentialAddress: 'childResidentialAddress',
childOther: 'childOther'
} as const

export type AddressType = keyof typeof AddressType | PersonType

const UrbanRuralTypes = {
URBAN: 'URBAN',
RURAL: 'RURAL'
} as const

const urbanRuralMessageDescriptors = {
URBAN: {
defaultMessage: 'Urban',
id: 'form.field.label.urban',
description: 'Label for form field checkbox option Urban'
},
RURAL: {
defaultMessage: 'Rural',
id: 'form.field.label.rural',
description: 'Label for form field checkbox option Rural'
}
} satisfies Record<keyof typeof UrbanRuralTypes, TranslationConfig>

const urbanRuralRadioOptions = createSelectOptions(
UrbanRuralTypes,
urbanRuralMessageDescriptors
)

export const getAddressFields = (person: AddressType): FieldConfig[] => {
const prefix = `${person}.address`

const genericAddressFields: FieldConfig[] = [
Expand Down Expand Up @@ -90,27 +120,7 @@ export const getAddressFields = (person: string): FieldConfig[] => {
}
]

const farajalandAddressFields: FieldConfig[] = [
{
id: `${prefix}.province`,
type: 'TEXT',
required: true,
label: {
defaultMessage: 'Province',
description: 'This is the label for the field',
id: `event.action.declare.form.section.person.field.address.province.label`
}
},
{
id: `${prefix}.district`,
type: 'TEXT',
required: true,
label: {
defaultMessage: 'District',
description: 'This is the label for the field',
id: `event.action.declare.form.section.person.field.address.district.label`
}
},
const urbanAddressFields: FieldConfig[] = [
{
id: `${prefix}.town`,
type: 'TEXT',
Expand Down Expand Up @@ -162,6 +172,78 @@ export const getAddressFields = (person: string): FieldConfig[] => {
}
}
]
const farajalandAddressFields: FieldConfig[] = [
{
id: `${prefix}.province`,
type: 'LOCATION',
required: true,
label: {
defaultMessage: 'Province',
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.${person}.field.address.province.label`
},
options: {
type: 'ADMIN_STRUCTURE'
}
},
{
id: `${prefix}.district`,
type: 'LOCATION',
required: true,
label: {
defaultMessage: 'District',
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.${person}.field.address.district.label`
},
options: {
partOf: {
$data: `${prefix}.province`
},
type: 'ADMIN_STRUCTURE'
}
},
{
id: `${prefix}.urbanOrRural`,
type: 'RADIO_GROUP',
options: urbanRuralRadioOptions,
flexDirection: 'row',
required: false,
label: {
defaultMessage: 'Urban or Rural',
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.${person}.field.address.urbanOrRural.label`
}
},
...appendConditionalsToFields({
inputFields: urbanAddressFields,
newConditionals: [
{
type: 'HIDE',
conditional: field(`${prefix}.urbanOrRural`).isUndefinedOrInArray([
'RURAL'
])
}
]
}),
{
id: `${prefix}.village`,
type: 'TEXT',
required: false,
label: {
defaultMessage: 'Village',
description: 'This is the label for the field',
id: `event.birth.action.declare.form.section.${person}.field.address.village.label`
},
conditionals: [
{
type: 'HIDE',
conditional: field(`${prefix}.urbanOrRural`).isUndefinedOrInArray([
'URBAN'
])
}
]
}
]

return [
{
Expand Down
Loading

0 comments on commit 1b6c7b8

Please sign in to comment.