-
Notifications
You must be signed in to change notification settings - Fork 51
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
feat: create address input #362
Conversation
Oops! Looks like you forgot to update the changelog. When updating CHANGELOG.md, please consider the following:
|
…ryconfig into address-input-v2
src/form/v2/person/index.ts
Outdated
@@ -195,6 +218,55 @@ const getIdFields = (person: string): FieldConfig[] => [ | |||
} | |||
] | |||
|
|||
const getAddressOrSameAsMotherFields = (person: string): FieldConfig[] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we have a tighter type for person?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Some suggestions
src/form/v2/person/index.ts
Outdated
@@ -291,7 +363,7 @@ export const getInformantFields = (person: string): FieldConfig[] => [ | |||
}, | |||
options: { fontVariant: 'h2' } | |||
}, | |||
...getAddressFields(person) | |||
...getAddressOrSameAsMotherFields(person) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to separate this function to two different ones. Often it is perfectly fine to have condition nested inside a function.
When we need to name the function with "or" it might sometimes be better to bring that condition up a level, especially if the condition is "rare".
On high-level, it might be something like this:
const isFather = person === 'father';
// You know better how to name the function and the domain rules.
// Is father only one using the function? Is it always mother? Or can they be other way around? Would be cool if that is either reflected on function name or parameters.
const addressFields = isFather ? getAddressWithSharedResidenceFields(father) : getAddressFields(person)
src/form/v2/person/index.ts
Outdated
@@ -14,6 +14,8 @@ import { field } from '@opencrvs/toolkit/conditionals' | |||
import { getAddressFields } from './address' | |||
import { appendConditionalsToFields, createSelectOptions } from '../utils' | |||
|
|||
export type PersonTypes = 'father' | 'mother' | 'informant' | 'applicant' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use same pattern like this:
export const PersonType = {
father: 'father',
mother: 'mother'
} as const
export type PersonType = keyof typeof PersonType
and use the PersonType.father later in the file, so satisfy wouldn't be needed because they derive from the same source
src/form/v2/person/address.ts
Outdated
@@ -12,6 +12,12 @@ | |||
import { FieldConfig, TranslationConfig } from '@opencrvs/toolkit/events' | |||
import { field } from '@opencrvs/toolkit/conditionals' | |||
import { appendConditionalsToFields, createSelectOptions } from '../utils' | |||
import { PersonTypes } from '.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not matter most of the time if build works, but filename could be added
No description provided.