diff --git a/packages/client/src/search/transformer.ts b/packages/client/src/search/transformer.ts index 59b8c55f93f..6cf97b8ef81 100644 --- a/packages/client/src/search/transformer.ts +++ b/packages/client/src/search/transformer.ts @@ -11,12 +11,11 @@ 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, @@ -24,7 +23,7 @@ import { 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 = ( @@ -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 = @@ -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)) || diff --git a/packages/client/src/views/RegisterForm/review/ReviewSection.tsx b/packages/client/src/views/RegisterForm/review/ReviewSection.tsx index 467a90dff6c..79e179a9842 100644 --- a/packages/client/src/views/RegisterForm/review/ReviewSection.tsx +++ b/packages/client/src/views/RegisterForm/review/ReviewSection.tsx @@ -614,7 +614,6 @@ class ReviewSectionComp extends React.Component { constructor(props: FullProps) { super(props) - this.state = { displayEditDialog: false, editClickedSectionGroupId: '', @@ -1046,7 +1045,6 @@ class ReviewSectionComp extends React.Component { originalData?: IFormSectionData ) { const { draft } = this.props - if (field.previewGroup && !visitedTags.includes(field.previewGroup)) { visitedTags.push(field.previewGroup) @@ -1612,7 +1610,38 @@ class ReviewSectionComp extends React.Component { }) if (!overriddenFields.length) { - items = items.concat(tempItem) + if ( + tempItem && + tempItem.label === 'Full name' && + ['deceasedNameInEnglish', 'childNameInEnglish'].includes( + field.previewGroup || '' + ) + ) { + 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 && ( + <> +
+ {oldName} + + )} + + ) + }) + } else { + items = items.concat(tempItem) + } } }) }) @@ -1699,7 +1728,7 @@ class ReviewSectionComp extends React.Component { '') as string } - const informantName = getDeclarationFullName(declaration, intl) + const informantName = getDeclarationFullName(declaration, intl) + 'Hey test' const draft = this.isDraft() const transformedSectionData = this.transformSectionData( formSections.filter( @@ -1800,30 +1829,32 @@ class ReviewSectionComp extends React.Component { expand={true} > - {sec.items.map((item) => ( - - {item.action.label} - - ) - } - /> - ))} + {sec.items.map((item) => { + return ( + + {item.action.label} + + ) + } + /> + ) + })}