Skip to content

fix: unitId is now set for sensitive cms with default homeUnit - #195

Closed
bridgesr wants to merge 2 commits into
mainfrom
feature/fct2_21047_unit_id_sensitive
Closed

fix: unitId is now set for sensitive cms with default homeUnit#195
bridgesr wants to merge 2 commits into
mainfrom
feature/fct2_21047_unit_id_sensitive

Conversation

@bridgesr

@bridgesr bridgesr commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

Comment on lines +85 to +93
return (
state.formData.registeringUnitText?.id ??
state.apiData.areasAndRegisteringUnits?.homeUnit?.id ??
null
);
}, [
state.formData.registeringUnitText,
state.apiData.areasAndRegisteringUnits?.homeUnit?.id,
]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(() => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: after RESET_FORM_DATA, the home-unit effect re-applies areaOrDivisionText and registeringUnitText when the area is sensitive.
  • CaseAssigneePage / FirstHearingPage: registeringUnitId resolves to homeUnit.id when registeringUnitText.id is null.

if (
if (isAreaSensitive) {
// Field is hidden; use stored value or fall back to home unit.
const homeUnit = state.apiData.areasAndRegisteringUnits?.homeUnit;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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) {
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
},
},
});

@bridgesr bridgesr closed this Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants