fix: unitId is now set for sensitive cms with default homeUnit - #195
fix: unitId is now set for sensitive cms with default homeUnit#195bridgesr wants to merge 2 commits into
Conversation
|
| return ( | ||
| state.formData.registeringUnitText?.id ?? | ||
| state.apiData.areasAndRegisteringUnits?.homeUnit?.id ?? | ||
| null | ||
| ); | ||
| }, [ | ||
| state.formData.registeringUnitText, | ||
| state.apiData.areasAndRegisteringUnits?.homeUnit?.id, | ||
| ]); |
There was a problem hiding this comment.
Duplicated registeringUnitId fallback — extract to a shared hook
The exact same useMemo block 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).
// Current (duplicated in both files)
const registeringUnitId = useMemo(() => {
return (
state.formData.registeringUnitText?.id ??
state.apiData.areasAndRegisteringUnits?.homeUnit?.id ??
null
);
}, [
state.formData.registeringUnitText,
state.apiData.areasAndRegisteringUnits?.homeUnit?.id,
]);// Suggested: src/ui-spa/src/common/hooks/useRegisteringUnitId.ts
import { useContext, useMemo } from "react";
import { CaseRegistrationFormContext } from "../providers/CaseRegistrationProvider";
export const useRegisteringUnitId = () => {
const { state } = useContext(CaseRegistrationFormContext);
return useMemo(
() =>
state.formData.registeringUnitText?.id ??
state.apiData.areasAndRegisteringUnits?.homeUnit?.id ??
null,
[
state.formData.registeringUnitText?.id,
state.apiData.areasAndRegisteringUnits?.homeUnit?.id,
],
);
};| description: areasData.homeUnit.areaDescription, | ||
| }, | ||
| // Home unit must be re-applied after RESET_FORM_DATA (apiData is kept, form is cleared). | ||
| useEffect(() => { |
There was a problem hiding this comment.
No unit/integration tests for the new fallback behaviour
Four components gain new branching logic (sensitive vs. non-sensitive) and a new useEffect with conditional dispatch. A regression here would silently re-break the defect. At minimum, add a test for:
CaseRegistrationPage: afterRESET_FORM_DATA, the home-unit effect re-appliesareaOrDivisionTextandregisteringUnitTextwhen the area is sensitive.CaseAssigneePage/FirstHearingPage:registeringUnitIdresolves tohomeUnit.idwhenregisteringUnitText.idis null.
| if ( | ||
| if (isAreaSensitive) { | ||
| // Field is hidden; use stored value or fall back to home unit. | ||
| const homeUnit = state.apiData.areasAndRegisteringUnits?.homeUnit; |
There was a problem hiding this comment.
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) {
dispatch({
type: "SET_FIELDS",
payload: {
data: {
areaOrDivisionText: {
id: areasData.homeUnit.areaId,
description: areasData.homeUnit.areaDescription,
},
// include the registering unit here if it is sensitive case
},
},
});



No description provided.