-
Notifications
You must be signed in to change notification settings - Fork 2
fix: unitId is now set for sensitive cms with default homeUnit #195
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -344,7 +344,19 @@ | |
| "registering-unit-text", | ||
| ) as HTMLInputElement | null; | ||
| const registeringUnitInputValue = registeringUnitInput?.value ?? ""; | ||
| if ( | ||
| if (isAreaSensitive) { | ||
| // Field is hidden; use stored value or fall back to home unit. | ||
| const homeUnit = state.apiData.areasAndRegisteringUnits?.homeUnit; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think the changes in the case-assignee page , first hearing page , and this page can be removed if you add default registering unit just like default case area in caseRegistrationPage if is a sensitiveCase. CaseRegistrationPage line 185 if (!state.formData.areaOrDivisionText.id && areasData?.homeUnit) { // include the registering unit here if it is sensitive case |
||
| const registeringUnitText = state.formData.registeringUnitText.id | ||
| ? state.formData.registeringUnitText | ||
| : homeUnit | ||
| ? { id: homeUnit.id, description: homeUnit.description } | ||
| : state.formData.registeringUnitText; | ||
|
Check warning on line 354 in src/ui-spa/src/components/case-registration/case-details-page/index.tsx
|
||
| formValue = { | ||
| ...formValue, | ||
| registeringUnitText, | ||
| }; | ||
| } else if ( | ||
| formData.registeringUnitText?.description !== registeringUnitInputValue | ||
| ) { | ||
| const { id, description } = getSelectedUnit( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,26 +181,45 @@ const CaseRegistrationPage = () => { | |
| areasAndRegisteringUnits: areasData, | ||
| }, | ||
| }); | ||
| } | ||
| }, [areasData, dispatch, state.apiData.areasAndRegisteringUnits]); | ||
|
|
||
| if (!state.formData.areaOrDivisionText.id && areasData?.homeUnit) { | ||
| dispatch({ | ||
| type: "SET_FIELDS", | ||
| payload: { | ||
| data: { | ||
| areaOrDivisionText: { | ||
| id: areasData.homeUnit.areaId, | ||
| description: areasData.homeUnit.areaDescription, | ||
| }, | ||
| // Home unit must be re-applied after RESET_FORM_DATA (apiData is kept, form is cleared). | ||
| useEffect(() => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No unit/integration tests for the new fallback behaviourFour components gain new branching logic (sensitive vs. non-sensitive) and a new
|
||
| const homeUnit = state.apiData.areasAndRegisteringUnits?.homeUnit; | ||
| if (!homeUnit) return; | ||
|
|
||
| const needsArea = !state.formData.areaOrDivisionText.id; | ||
| const needsRegisteringUnit = | ||
| homeUnit.areaIsSensitive && !state.formData.registeringUnitText.id; | ||
|
|
||
| if (!needsArea && !needsRegisteringUnit) return; | ||
|
|
||
| dispatch({ | ||
| type: "SET_FIELDS", | ||
| payload: { | ||
| data: { | ||
| ...(needsArea && { | ||
| areaOrDivisionText: { | ||
| id: homeUnit.areaId, | ||
| description: homeUnit.areaDescription, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| }), | ||
| // Only auto-set RU for sensitive areas (field is hidden there). | ||
| ...(needsRegisteringUnit && { | ||
| registeringUnitText: { | ||
| id: homeUnit.id, | ||
| description: homeUnit.description, | ||
| }, | ||
| }), | ||
| }, | ||
| }, | ||
| }); | ||
| }, [ | ||
| areasData, | ||
| dispatch, | ||
| state.formData.areaOrDivisionText, | ||
| state.apiData.areasAndRegisteringUnits, | ||
| state.formData.areaOrDivisionText.id, | ||
| state.formData.registeringUnitText.id, | ||
| ]); | ||
|
|
||
| useEffect(() => { | ||
|
|
||
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.
Duplicated
registeringUnitIdfallback — extract to a shared hookThe exact same
useMemoblock now appears in two components. If the fallback priority ever changes (or a third page needs it), two places need updating (components/case-registration/first-hearing-page/index.tsx).