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

Track custom field changes for correction #7023

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
- Fix Registrar of any location should be able to review a correction request [#6247](https://github.com/opencrvs/opencrvs-core/issues/6247)
- remove upload button when no supporting docs are configured [#5944](https://github.com/opencrvs/opencrvs-core/issues/5944)
- Fix issues of invisible inputs when navigating from can't login link in login page [#6163](https://github.com/opencrvs/opencrvs-core/issues/6163)
- Fix the "Continue" button being disabled when changes in correction form is made [#6780](https://github.com/opencrvs/opencrvs-core/issues/6780)
- Remove leading slash from `resendAuthenticationCode` in login to fix resend email button [#6987](https://github.com/opencrvs/opencrvs-core/issues/6987) [#7037](https://github.com/opencrvs/opencrvs-core/issues/7037)
- Fix dashboard cron jobs not working [#7016](https://github.com/opencrvs/opencrvs-core/issues/7016)
- Fix client modal glitches on integrations page [#7002] (https://github.com/opencrvs/opencrvs-core/issues/7002)
Expand Down
24 changes: 14 additions & 10 deletions packages/client/src/views/CorrectionForm/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,28 +564,32 @@ export const renderValue = (

export function hasFieldChanged(
field: IFormField,
data: IFormSectionData,
originalData?: IFormSectionData
sectionData: IFormSectionData,
originalSectionData?: IFormSectionData
) {
if (!originalData) return false
if (data[field.name] && (data[field.name] as IFormData).value) {
if (!originalSectionData) {
const isCustomSection = sectionData && sectionData[field.name]
if (isCustomSection) return true
return false
}
if (sectionData[field.name] && (sectionData[field.name] as IFormData).value) {
return hasNestedDataChanged(
data[field.name] as IFormData,
originalData[field.name] as IFormData
sectionData[field.name] as IFormData,
originalSectionData[field.name] as IFormData
)
}
/*
* data section might have some values as empty string
* whereas original data section have them as undefined
*/
if (!originalData[field.name] && data[field.name] === '') {
if (!originalSectionData[field.name] && sectionData[field.name] === '') {
return false
}

if (Array.isArray(data[field.name])) {
return !isEqual(data[field.name], originalData[field.name])
if (Array.isArray(sectionData[field.name])) {
return !isEqual(sectionData[field.name], originalSectionData[field.name])
}
return data[field.name] !== originalData[field.name]
return sectionData[field.name] !== originalSectionData[field.name]
}

function hasNestedDataChanged(
Expand Down
27 changes: 19 additions & 8 deletions packages/client/src/views/RegisterForm/review/ReviewSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1236,25 +1236,36 @@ class ReviewSectionComp extends React.Component<FullProps, State> {

hasFieldChanged(
field: IFormField,
data: IFormSectionData,
originalData?: IFormSectionData
sectionData: IFormSectionData,
originalSectionData?: IFormSectionData
) {
if (!originalData) return false
if (data[field.name] && (data[field.name] as IFormData).value) {
if (!originalSectionData) {
const isCustomSection = sectionData && sectionData[field.name]
if (isCustomSection) {
this.hasChangesBeenMade = true
return true
}
return false
}
if (
sectionData[field.name] &&
(sectionData[field.name] as IFormData).value
) {
return this.hasNestedDataChanged(
data[field.name] as IFormData,
originalData[field.name] as IFormData
sectionData[field.name] as IFormData,
originalSectionData[field.name] as IFormData
)
}
/*
* data section might have some values as empty string
* whereas original data section have them as undefined
*/
if (!originalData[field.name] && data[field.name] === '') {
if (!originalSectionData[field.name] && sectionData[field.name] === '') {
return false
}

const hasChanged = data[field.name] !== originalData[field.name]
const hasChanged =
sectionData[field.name] !== originalSectionData[field.name]
this.hasChangesBeenMade = this.hasChangesBeenMade || hasChanged
return hasChanged
}
Expand Down
Loading