Skip to content

Commit

Permalink
WIP! Use humanName for other screens
Browse files Browse the repository at this point in the history
  • Loading branch information
Siyasanga committed Dec 17, 2024
1 parent 948771b commit a2148db
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 57 deletions.
49 changes: 20 additions & 29 deletions packages/client/src/search/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@
import type {
GQLBirthEventSearchSet,
GQLDeathEventSearchSet,
GQLHumanName,
GQLMarriageEventSearchSet,
GQLRegStatus
} from '@client/utils/gateway-deprecated-do-not-use'
import { IntlShape } from 'react-intl'
import { createNamesMap } from '@client/utils/data-formatting'
import { getLocalisedName } from '@client/utils/data-formatting'
import { formatLongDate } from '@client/utils/date-formatting'
import {
HumanName,
EventSearchSet,
SearchEventsQuery,
Event
} from '@client/utils/gateway'
import { EMPTY_STRING, LANG_EN } from '@client/utils/constants'
import { EMPTY_STRING } from '@client/utils/constants'
import { ITaskHistory } from '@client/declarations'

export const isBirthEvent = (
Expand Down Expand Up @@ -60,42 +59,39 @@ export const transformData = (
let birthReg
let deathReg
let marriageReg
let names
let groomNames
let brideNames
let name
let groomName
let brideName
let dateOfEvent
let mergedMarriageName
const assignedReg = reg

if (reg.registration) {
if (isBirthEvent(reg)) {
birthReg = reg
names = (birthReg.childName as GQLHumanName[]) || []
name = birthReg.childName
? getLocalisedName(intl, birthReg.childName[0] as HumanName)
: EMPTY_STRING
dateOfEvent = birthReg.dateOfBirth
} else if (isDeathEvent(reg)) {
deathReg = reg
names = (deathReg.deceasedName as GQLHumanName[]) || []
name = deathReg.deceasedName
? getLocalisedName(intl, deathReg.deceasedName[0] as HumanName)
: EMPTY_STRING
dateOfEvent = deathReg && deathReg.dateOfDeath
} else if (isMarriageEvent(reg)) {
marriageReg = reg
groomNames =
(marriageReg && (marriageReg.groomName as GQLHumanName[])) || []
brideNames =
(marriageReg && (marriageReg.brideName as GQLHumanName[])) || []
groomName = reg.groomName
? getLocalisedName(intl, reg.groomName[0] as HumanName)
: EMPTY_STRING
brideName = reg.brideName
? getLocalisedName(intl, reg.brideName[0] as HumanName)
: EMPTY_STRING

const groomName =
(createNamesMap(groomNames as HumanName[])[locale] as string) ||
(createNamesMap(groomNames as HumanName[])[LANG_EN] as string)
const brideName =
(createNamesMap(brideNames as HumanName[])[locale] as string) ||
(createNamesMap(brideNames as HumanName[])[LANG_EN] as string)

mergedMarriageName =
name =
brideName && groomName
? `${groomName} & ${brideName}`
: brideName || groomName || EMPTY_STRING

dateOfEvent = marriageReg && marriageReg.dateOfMarriage
dateOfEvent = marriageReg && reg.dateOfMarriage
}
}
const status =
Expand All @@ -104,12 +100,7 @@ export const transformData = (

return {
id: assignedReg.id,
name:
assignedReg.type === Event.Marriage
? mergedMarriageName
: (createNamesMap(names as HumanName[])[locale] as string) ||
(createNamesMap(names as HumanName[])[LANG_EN] as string) ||
'',
name,
dob:
(birthReg?.dateOfBirth?.length &&
formatLongDate(birthReg.dateOfBirth, locale)) ||
Expand Down
85 changes: 57 additions & 28 deletions packages/client/src/views/RegisterForm/review/ReviewSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ class ReviewSectionComp extends React.Component<FullProps, State> {

constructor(props: FullProps) {
super(props)

this.state = {
displayEditDialog: false,
editClickedSectionGroupId: '',
Expand Down Expand Up @@ -1046,7 +1045,6 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
originalData?: IFormSectionData
) {
const { draft } = this.props

if (field.previewGroup && !visitedTags.includes(field.previewGroup)) {
visitedTags.push(field.previewGroup)

Expand Down Expand Up @@ -1309,6 +1307,7 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
field: IFormField,
sectionErrors: IErrorsBySection
) {
debugger
const { draft } = this.props
const visitedTags: string[] = []
const nestedItems: any[] = []
Expand All @@ -1328,6 +1327,7 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
[]
).forEach((nestedField) => {
if (nestedField.previewGroup) {
debugger
nestedItems.push(
this.getPreviewGroupsField(
section,
Expand All @@ -1343,6 +1343,7 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
)
)
} else {
debugger
nestedItems.push(
this.getRenderableField(
section,
Expand Down Expand Up @@ -1612,7 +1613,33 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
})

if (!overriddenFields.length) {
items = items.concat(tempItem)
debugger
if (tempItem && tempItem.label === 'Full name') {
const newName = getDeclarationFullName(declaration, intl)
const oldName = getDeclarationFullName(
{
...declaration,
data: declaration.originalData
} as IDeclaration,
intl
) // Constuct new declaration using the original data object
items = items.concat({
...tempItem,
value: (
<>
{getDeclarationFullName(declaration, intl)}
{newName !== oldName && (
<>
<br />
<Deleted>{oldName}</Deleted>
</>
)}
</>
)
})
} else {
items = items.concat(tempItem)
}
}
})
})
Expand Down Expand Up @@ -1699,7 +1726,7 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
'') as string
}

const informantName = getDeclarationFullName(declaration, intl)
const informantName = getDeclarationFullName(declaration, intl) + 'Hey test'
const draft = this.isDraft()
const transformedSectionData = this.transformSectionData(
formSections.filter(
Expand Down Expand Up @@ -1800,30 +1827,32 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
expand={true}
>
<ListReview id={'Section_' + sec.id}>
{sec.items.map((item) => (
<ListReview.Row
id={item.label.split(' ')[0]}
key={sec.id + '_' + item.label}
label={item.label}
value={item.value}
actions={
!item?.action?.disabled &&
declaration.registrationStatus !==
RegStatus.CorrectionRequested && (
<Link
key={item.action.id}
id={item.action.id}
disabled={item.action.disabled}
onClick={item.action.handler}
element="button"
font="reg16"
>
{item.action.label}
</Link>
)
}
/>
))}
{sec.items.map((item) => {
return (
<ListReview.Row
id={item.label.split(' ')[0]}
key={sec.id + '_' + item.label}
label={item.label}
value={item.value}
actions={
!item?.action?.disabled &&
declaration.registrationStatus !==
RegStatus.CorrectionRequested && (
<Link
key={item.action.id}
id={item.action.id}
disabled={item.action.disabled}
onClick={item.action.handler}
element="button"
font="reg16"
>
{item.action.label}
</Link>
)
}
/>
)
})}
</ListReview>
</Accordion>
</DeclarationDataContainer>
Expand Down

0 comments on commit a2148db

Please sign in to comment.