Skip to content

[ENG-551] Replace all other usages of GovtOrgSelector with the new picker#16451

Open
rithviknishad wants to merge 5 commits into
developfrom
ENG-551-replace-all-other-usages-of-govt-org-selector-with-the-new-picker
Open

[ENG-551] Replace all other usages of GovtOrgSelector with the new picker#16451
rithviknishad wants to merge 5 commits into
developfrom
ENG-551-replace-all-other-usages-of-govt-org-selector-with-the-new-picker

Conversation

@rithviknishad

@rithviknishad rithviknishad commented Jun 10, 2026

Copy link
Copy Markdown
Member

Proposed Changes

  • Replaces usages of deprecated GovtOrganizationSelector with GovtOrganizationPicker
  • ENG-551

Summary by CodeRabbit

  • Refactor
    • Switched the hierarchical govt-organization selector to a unified govt-organization picker across facility, user, and patient registration flows.
    • Updated form wiring to use controlled picker state and keep the stored geo_organization field synchronized on create and edit.
    • Ensured patient registration only submits leaf-level selections (no children).
    • Removed the legacy selector component and the related govt-organization level hook.

@rithviknishad rithviknishad requested review from a team and Copilot June 10, 2026 05:04
@netlify

netlify Bot commented Jun 10, 2026

Copy link
Copy Markdown

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 273ca03
🔍 Latest deploy log https://app.netlify.com/projects/care-ohc/deploys/6a3136ab4c00100008b38951
😎 Deploy Preview https://deploy-preview-16451.preview.ohc.network
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

Copy link
Copy Markdown

⚠️ Merge Checklist Incomplete

Thank you for your contribution! To help us review your PR efficiently, please complete the merge checklist in your PR description.

Your PR will be reviewed once you have marked the appropriate checklist items.

To update the checklist:

  • Change - [ ] to - [x] for completed items
  • Only check items that are relevant to your PR
  • Leave items unchecked if they don't apply

The checklist helps ensure code quality, testing coverage, and documentation are properly addressed.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR replaces the deprecated GovtOrganizationSelector component with GovtOrganizationPicker across three form components: FacilityForm, UserForm, and PatientRegistration. Each component updates state management from array-based selectedLevels to a single nullable selectedGeoOrg, and form field wiring now conditionally sets the geo_organization value only when the selected organization lacks children. The old GovtOrganizationSelector and useGovtOrganizationLevel hook are removed.

Changes

GovtOrganizationPicker Migration

Layer / File(s) Summary
FacilityForm picker migration
src/components/Facility/FacilityForm.tsx
Imports GovtOrganizationPicker, replaces selectedLevels state with selectedGeoOrg: Organization | null, initializes selection from org.org_type === "govt" on parent org load, derives selectedGeoOrg from facilityData.geo_organization on edit, and rewires the form field to set geo_organization ID only when the picked organization has no children.
UserForm picker migration
src/components/Users/UserForm.tsx
Switches from GovtOrganizationSelector to GovtOrganizationPicker, changes state from selectedLevels array to selectedGeoOrg: Organization | null, updates initialization logic to set selectedGeoOrg when org.org_type === "govt" or from userData.geo_organization in edit mode, and updates form field to use controlled picker with synchronized selectedGeoOrg and form value based on organization children status.
PatientRegistration picker migration
src/pages/PublicAppointments/PatientRegistration.tsx
Adds useState and Organization type imports, introduces selectedGeoOrg: Organization | null state, replaces selector with GovtOrganizationPicker in the form field, and updates the field to set geo_organization to organization ID only when selected organization has no children, otherwise clears the field.

Possibly related PRs

  • ohcnetwork/care_fe#16425: Introduces GovtOrganizationPicker implementation and establishes the picker integration pattern for geo_organization field handling with children/required-depth validation.

Suggested reviewers

  • abhimanyurajeesh
  • nihal467
  • amjithtitus09
  • gigincg
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is minimal and lacks required sections from the template (merge checklist is entirely absent, no detail on specs/tests/documentation). Add a completed merge checklist and elaborate on testing, documentation updates, and QA completion for the deprecated component replacement.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly matches the main objective: replacing GovtOrganizationSelector with GovtOrganizationPicker across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ENG-551-replace-all-other-usages-of-govt-org-selector-with-the-new-picker

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 10, 2026

Copy link
Copy Markdown

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: 273ca03
Status: ✅  Deploy successful!
Preview URL: https://653dcacc.care-preview-a7w.pages.dev
Branch Preview URL: https://eng-551-replace-all-other-us.care-preview-a7w.pages.dev

View logs

Copilot AI left a comment

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.

Pull request overview

This PR migrates remaining form flows away from the deprecated GovtOrganizationSelector to the newer GovtOrganizationPicker, and removes the old selector implementation from the codebase.

Changes:

  • Replaced GovtOrganizationSelector usages with GovtOrganizationPicker in public patient registration, user form, and facility form.
  • Updated these forms to manage the picker’s selected Organization object via local component state.
  • Deleted the deprecated GovtOrganizationSelector component file.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/pages/PublicAppointments/PatientRegistration.tsx Swaps the geo organization field to use GovtOrganizationPicker for public patient registration.
src/pages/Organization/components/GovtOrganizationSelector.tsx Removes the deprecated selector component implementation.
src/components/Users/UserForm.tsx Updates geo organization selection to use GovtOrganizationPicker with Organization state.
src/components/Facility/FacilityForm.tsx Updates geo organization selection to use GovtOrganizationPicker and new state wiring.
Comments suppressed due to low confidence (1)

src/components/Facility/FacilityForm.tsx:205

  • On edit, facilityData.geo_organization.id is always written into the form via form.reset, even if the loaded organization has children. With GovtOrganizationPicker, the UI can show a parent organization while the RHF field stays non-empty, so zod validation passes and the form can submit an intermediate geo org. Consider resetting geo_organization to "" unless the selected org is a leaf (and keep selectedGeoOrg set so the cascade remains visible).
  useEffect(() => {
    if (facilityData) {
      setSelectedGeoOrg(facilityData.geo_organization);
      form.reset({
        facility_type: facilityData.facility_type,
        name: facilityData.name,
        description: facilityData.description || "",
        features: facilityData.features || [],
        pincode: facilityData.pincode || undefined,
        geo_organization: facilityData.geo_organization.id,
        address: facilityData.address,

Comment thread src/components/Facility/FacilityForm.tsx Outdated
Comment thread src/pages/PublicAppointments/PatientRegistration.tsx
@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown

Greptile Summary

This PR replaces the deprecated GovtOrganizationSelector (and its useGovtOrganizationLevel hook) with the new GovtOrganizationPicker across the facility, user, and patient-registration forms, moving to a single controlled value prop instead of an array of levels.

  • PatientRegistration is cleanly migrated: it explicitly guards against intermediate org selections with !organization.has_children before writing the form value, matching the old required behaviour.
  • FacilityForm and UserForm are missing this leaf-level guard — their onChange handlers set geo_organization unconditionally, allowing an intermediate org to satisfy z.string().min(1) validation and be submitted.
  • UserForm additionally has a state-sync gap: the useEffect that pre-fills from a govt org context calls setSelectedGeoOrg but never form.setValue(\"geo_organization\", ...), so the picker appears pre-filled while the form value stays undefined and the geo org is silently dropped on submit.

Confidence Score: 4/5

Safe to merge after fixing the two onChange handlers in FacilityForm and UserForm, and the missing form.setValue call in UserForm's org-context effect.

FacilityForm and UserForm both allow an intermediate (non-leaf) org to pass form validation and reach the API, which was explicitly blocked by the old component's required prop. UserForm also silently drops the pre-filled geo org on first submit when the user is creating from a govt org context.

src/components/Users/UserForm.tsx and src/components/Facility/FacilityForm.tsx

Important Files Changed

Filename Overview
src/components/Facility/FacilityForm.tsx Replaces GovtOrganizationSelector with GovtOrganizationPicker and correctly syncs both visual state and form value in useEffect; however, the onChange handler sets geo_organization unconditionally for any selected org (including intermediate nodes with children), removing the leaf-level guard that the old required prop enforced.
src/components/Users/UserForm.tsx Replaces GovtOrganizationSelector with GovtOrganizationPicker; has two issues: (1) the useEffect that pre-fills from a govt org context updates selectedGeoOrg but never calls form.setValue, so the pre-fill is visual-only and the value is dropped on submit; (2) same missing leaf-level guard as FacilityForm.
src/pages/PublicAppointments/PatientRegistration.tsx Correctly migrates to GovtOrganizationPicker with a proper leaf-level guard (!!organization && !organization.has_children) before setting the form value, matching the old required behaviour.
src/hooks/useGovtOrganizationLevel.ts Deleted — logic was only used by the removed GovtOrganizationSelector; GovtOrganizationPicker handles its own data fetching internally.
src/pages/Organization/components/GovtOrganizationSelector.tsx Deleted deprecated component; all callers have been migrated to GovtOrganizationPicker.

Comments Outside Diff (3)

  1. src/components/Users/UserForm.tsx, line 380-382 (link)

    P1 Pre-filled geo org not synced to form value

    When org resolves to a govt org, setSelectedGeoOrg updates the picker's visual state but form.setValue("geo_organization", ...) is never called. If the user submits without touching the picker, form.getValues("geo_organization") remains undefined and the pre-filled org is silently dropped from the API payload. Compare with FacilityForm.tsx, which calls both setSelectedGeoOrg and form.setValue("geo_organization", govtOrg?.id ?? "") in the equivalent effect.

  2. src/components/Facility/FacilityForm.tsx, line 373-380 (link)

    P1 Intermediate org can be submitted — leaf-level guard removed

    The old GovtOrganizationSelector with required called onChange("") whenever the selected org had children (i.e., was not a leaf), keeping geo_organization empty and blocking form submission. The new picker always fires onChange(organization), so any intermediate selection now sets a valid non-empty form value and the form passes z.string().min(1) validation before the user finishes drilling down. PatientRegistration explicitly guards against this with !organization.has_children, but that check is missing here and in UserForm.

  3. src/components/Users/UserForm.tsx, line 806-811 (link)

    P1 Intermediate org can be submitted — leaf-level guard missing

    Same issue as in FacilityForm: the old selector with required=true prevented submitting an intermediate org by calling onChange("") for any org with children. This handler sets the form value unconditionally. PatientRegistration adds !organization.has_children to mirror the old behaviour; the same guard is needed here.

Reviews (4): Last reviewed commit: "allow selecting any level in facility an..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/Facility/FacilityForm.tsx`:
- Around line 105-107: The useEffect that sets selectedGeoOrg from the bootstrap
org is overwriting edit-mode state; update the effect in FacilityForm (the
useEffect that calls setSelectedGeoOrg with org/org_type) to only apply when the
form is not in edit-mode or when there is no existing selectedGeoOrg from the
entity backing the form (e.g., guard on an isEditMode flag or on the absence of
a preloaded selectedGeoOrg value), so that the bootstrap org does not replace
user/entity-backed selectedGeoOrg; keep references to org, organizationId,
selectedGeoOrg, and setSelectedGeoOrg when implementing this guard.

In `@src/components/Users/UserForm.tsx`:
- Around line 806-810: The onChange handler for the organization picker
currently writes whatever node ID is selected into geo_organization; change it
to persist only leaf organization IDs by checking the selected organization's
isLeaf (or equivalent) property or using a helper to get the leafId before
calling setSelectedGeoOrg and form.setValue; update the onChange in the
component that sets setSelectedGeoOrg and calls
form.setValue("geo_organization", ...) to pass the leaf id (or empty string when
a non-leaf is selected) so geo_organization mirrors the leaf-only behavior used
in other migrated forms.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c09d6a95-87c4-44d9-9a3c-69b4604166f8

📥 Commits

Reviewing files that changed from the base of the PR and between 5466816 and fa9a2c1.

📒 Files selected for processing (4)
  • src/components/Facility/FacilityForm.tsx
  • src/components/Users/UserForm.tsx
  • src/pages/Organization/components/GovtOrganizationSelector.tsx
  • src/pages/PublicAppointments/PatientRegistration.tsx
💤 Files with no reviewable changes (1)
  • src/pages/Organization/components/GovtOrganizationSelector.tsx

Comment thread src/components/Facility/FacilityForm.tsx Outdated
Comment thread src/components/Users/UserForm.tsx
@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

🎭 Playwright Test Results

Status: ❌ Failed
Test Shards: 3

Metric Count
Total Tests 321
✅ Passed 320
❌ Failed 1
⏭️ Skipped 0

📊 Detailed results are available in the playwright-final-report artifact.

Run: #9563

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/Facility/FacilityForm.tsx`:
- Around line 105-115: The effect in FacilityForm that sets selectedGeoOrg and
calls form.setValue("geo_organization") is overwriting edit-mode selections when
the parent org query resolves; guard the useEffect (the effect that depends on
org, organizationId, form) with an edit-mode check (e.g., only run when not
editing: !facilityId) so it skips setting selectedGeoOrg and form.setValue
during edits, preserving the entity-backed geo_organization value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f0425b4f-0aa8-493a-86dd-cfe8071d1252

📥 Commits

Reviewing files that changed from the base of the PR and between fa9a2c1 and f7bd2e7.

📒 Files selected for processing (3)
  • src/components/Facility/FacilityForm.tsx
  • src/components/Users/UserForm.tsx
  • src/hooks/useGovtOrganizationLevel.ts
💤 Files with no reviewable changes (1)
  • src/hooks/useGovtOrganizationLevel.ts

Comment thread src/components/Facility/FacilityForm.tsx Outdated

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Comment thread src/components/Facility/FacilityForm.tsx
Comment thread src/components/Facility/FacilityForm.tsx
Comment thread src/components/Users/UserForm.tsx Outdated
Comment thread src/components/Facility/FacilityForm.tsx Outdated
Comment thread src/components/Users/UserForm.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/Users/UserForm.tsx`:
- Around line 804-810: The selectedGeoOrg picker value shown in the component
(line 805) is not being synced into the form state when it is programmatically
set during the create flow. While the onChange handler in lines 808-810 updates
the form field when the user manually interacts with the picker, there is no
mechanism to sync the preselected value into the form's geo_organization field
when selectedGeoOrg is initially populated by the org bootstrap effect. Add an
effect that watches selectedGeoOrg and updates the form's geo_organization field
via form.setValue whenever selectedGeoOrg changes, ensuring the form state stays
in sync with the picker's displayed value during create mode.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d6bb76e1-e4b5-4bc5-b9a5-83cfd92b0fa9

📥 Commits

Reviewing files that changed from the base of the PR and between ca8e6ef and 273ca03.

📒 Files selected for processing (2)
  • src/components/Facility/FacilityForm.tsx
  • src/components/Users/UserForm.tsx

Comment on lines +804 to +810
requiredDepth={1}
value={selectedGeoOrg}
onChange={(organization) => {
setSelectedGeoOrg(organization);
form.setValue("geo_organization", organization?.id ?? "", {
shouldDirty: true,
})
}
required={false}
});

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Sync preselected picker value into the form state in create mode.

Line 805 renders selectedGeoOrg as selected, but Lines 808-810 update geo_organization only after user interaction. In create flow, the org bootstrap effect can prefill the picker while data.geo_organization stays empty on submit.

Suggested fix
 useEffect(() => {
-  setSelectedGeoOrg(org && org.org_type === "govt" ? org : null);
-}, [org, organizationId]);
+  const govtOrg = org && org.org_type === "govt" ? org : null;
+  setSelectedGeoOrg(govtOrg);
+  if (!isEditMode) {
+    form.setValue("geo_organization", govtOrg?.id ?? "", {
+      shouldDirty: false,
+    });
+  }
+}, [org, isEditMode, form]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/Users/UserForm.tsx` around lines 804 - 810, The selectedGeoOrg
picker value shown in the component (line 805) is not being synced into the form
state when it is programmatically set during the create flow. While the onChange
handler in lines 808-810 updates the form field when the user manually interacts
with the picker, there is no mechanism to sync the preselected value into the
form's geo_organization field when selectedGeoOrg is initially populated by the
org bootstrap effect. Add an effect that watches selectedGeoOrg and updates the
form's geo_organization field via form.setValue whenever selectedGeoOrg changes,
ensuring the form state stays in sync with the picker's displayed value during
create mode.

@nihal467 nihal467 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Image
  • revert the geo org condition in the facility creation form to have all the level to be mandatory as our current develop
Image
  • Keep the geo org optional in the user creation as our current develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants