Skip to content

Service nav permissions#16038

Open
Jacobjeevan wants to merge 3 commits intoohcnetwork:developfrom
Jacobjeevan:service-perms
Open

Service nav permissions#16038
Jacobjeevan wants to merge 3 commits intoohcnetwork:developfrom
Jacobjeevan:service-perms

Conversation

@Jacobjeevan
Copy link
Contributor

@Jacobjeevan Jacobjeevan commented Mar 6, 2026

Proposed Changes

Fixes #16037

  • added perms primarily for service and location nav bars, will be adding subsequent perms (write perm checks etc) in a later PR
  • BE PR

Tagging: @ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate the bug or test the new feature.
  • Update product documentation.
  • Ensure that UI text is placed in I18n files.
  • Prepare a screenshot or demo video for the changelog entry and attach it to the issue.
  • Request peer reviews.
  • Complete QA on mobile devices.
  • Complete QA on desktop devices.
  • Add or update Playwright tests for related changes

Summary by CodeRabbit

New Features

  • Enhanced role-based access control across the application with permission checks for inventory management, supply requests and deliveries, service scheduling, and pharmacy operations
  • Navigation items and features now dynamically show or hide based on user permissions
  • Added permission verification for accessing specific pages, with unauthorized users redirected appropriately

@Jacobjeevan Jacobjeevan requested review from a team and Copilot March 6, 2026 05:12
@Jacobjeevan Jacobjeevan requested a review from a team as a code owner March 6, 2026 05:12
@github-actions github-actions bot added the Type Changes Contains changes in typescript types label Mar 6, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

Walkthrough

This pull request introduces permission-based access control throughout the application by adding service, supply, and inventory permission constants to the core permissions system, extending type definitions to include permissions, and applying permission checks across navigation components and pages to conditionally render UI elements.

Changes

Cohort / File(s) Summary
Permission Infrastructure
src/common/Permissions.tsx
Adds seven new permission constants (PERMISSION_READ_SERVICE_REQUEST, PERMISSION_VIEW_AS_PHARMACIST, PERMISSION_READ_INVENTORY, PERMISSION_READ_SUPPLY_DELIVERY, PERMISSION_WRITE_SUPPLY_DELIVERY, PERMISSION_READ_SUPPLY_REQUEST, PERMISSION_WRITE_SUPPLY_REQUEST) and extends the Permissions interface and getPermissions function to include corresponding boolean fields populated from permission checks.
Type Definitions
src/types/healthcareService/healthcareService.ts, src/types/location/location.ts
Adds permissions: string[] field to HealthcareServiceReadSpec and LocationDetail interfaces to expose permission data at the type level.
Navigation Components
src/components/ui/sidebar/facility/location/location-nav.tsx, src/components/ui/sidebar/facility/service/service-nav.tsx, src/components/ui/sidebar/nav-main.tsx
Integrates permission-based visibility controls: LocationNav and ServiceNav compute derived permissions and conditionally render menu items; NavMain filters child items based on visibility flags, rendering parent links as standard items only when no visible children exist.
Service and Inventory Pages
src/pages/Facility/services/HealthcareServiceShow.tsx, src/pages/Facility/services/inventory/ToDispatch.tsx, src/pages/Facility/services/inventory/ToReceive.tsx
Applies permission-based visibility to workflow shortcuts, inventory tabs, and action buttons (e.g., delivery creation, stock requests) based on canRead/Write permission flags derived from location and service contexts.
Pharmacy Permission Guard
src/pages/Facility/services/pharmacy/MedicationRequestList.tsx
Introduces runtime permission check for canViewAsPharmacist with automatic redirect and error toast if permission is denied; does not alter data-fetch or core UI logic otherwise.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
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.
Title check ❓ Inconclusive The title 'Service nav permissions' is vague and overly generic, failing to convey the scope or primary change effectively. Consider a more descriptive title like 'Add permission-based rendering to service and location navigation' to better reflect the changeset scope.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description references issue #16037 and mentions adding permissions for service and location nav bars, but most merge checklist items remain unchecked without explanation.
Linked Issues check ✅ Passed The PR implements permission-based rendering for service and location navigation bars as required by issue #16037, adding permission checks and visibility controls throughout navigation components.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing permission-based rendering for navigation; no out-of-scope modifications were detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

🚀 Preview Deployment Ready!

🔗 Preview URL: https://pr-16038.care-preview-a7w.pages.dev

📱 Mobile Access:
Scan the QR code below to open the preview on your mobile device.

QR Code


This preview will be automatically updated when you push new commits to this PR.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds permission-aware rendering and access control for service/location navigation and related pages in the CARE frontend, aligning UI navigation with RBAC capabilities for inventory/pharmacy/service workflows.

Changes:

  • Extend LocationDetail and HealthcareServiceReadSpec types to include permissions.
  • Add new permission slugs + derived booleans via getPermissions.
  • Apply visibility-based filtering for sidebar/nav items and inventory tabs; add a pharmacist-only guard for the prescription queue page.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/types/location/location.ts Adds permissions: string[] to LocationDetail to support location-scoped permission checks.
src/types/healthcareService/healthcareService.ts Adds permissions: string[] to service read type for service-scoped permission checks.
src/pages/Facility/services/pharmacy/MedicationRequestList.tsx Adds pharmacist permission gating with toast + redirect.
src/pages/Facility/services/inventory/ToReceive.tsx Adds permission-gated “Raise stock request” action and tab visibility controls.
src/pages/Facility/services/inventory/ToDispatch.tsx Adds permission-gated tab visibility controls and “Create delivery” action.
src/pages/Facility/services/HealthcareServiceShow.tsx Filters service shortcuts based on derived permissions (service vs facility-root fallback).
src/components/ui/sidebar/nav-main.tsx Prevents rendering empty child menus by filtering children using visibility.
src/components/ui/sidebar/facility/service/service-nav.tsx Adds permission-based visibility for service sidebar links.
src/components/ui/sidebar/facility/location/location-nav.tsx Adds permission-based visibility for location sidebar links and nested items.
src/common/Permissions.tsx Introduces new permission constants and exposes them via getPermissions.

Comment on lines 72 to 97
<NavTabs
className="w-full mt-2"
tabContentClassName="mt-2"
tabs={{
orders: {
label: t("requests_to_dispatch"),
component: (
<IncomingOrdersTab
facilityId={facilityId}
locationId={locationId}
internal={internal}
/>
),
visible: canReadSupplyRequest,
},
deliveries: {
label: t("outgoing_deliveries"),
component: (
<OutgoingDeliveriesTab
facilityId={facilityId}
locationId={locationId}
internal={internal}
/>
),
visible: canReadSupplyDelivery,
},
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

Same issue as ToReceive: if both canReadSupplyRequest and canReadSupplyDelivery are false, NavTabs will have zero visible tabs (it falls back to allTabKeys[0]), which can lead to an undefined tab value and runtime issues. Add a guard/redirect/empty state for the “no readable tabs” scenario before rendering NavTabs.

Copilot uses AI. Check for mistakes.
Comment on lines +114 to +118
if (!canViewAsPharmacist) {
toast.error(t("no_permission_to_view_page"));
goBack(`/facility/${facilityId}/locations/${locationId}`);
}
}, [canViewAsPharmacist]);
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

The permission guard runs even while facility is still loading. Since facility is initially undefined, facility?.permissions ?? [] becomes [], making canViewAsPharmacist false and redirecting/toasting for users who actually have access. Gate this effect on facility being loaded (e.g., !isFacilityLoading / facility != null) before redirecting, and include the referenced values (t, goBack, facilityId, locationId) in the effect deps to avoid stale closures and hook-lint warnings.

Suggested change
if (!canViewAsPharmacist) {
toast.error(t("no_permission_to_view_page"));
goBack(`/facility/${facilityId}/locations/${locationId}`);
}
}, [canViewAsPharmacist]);
if (!facility) {
return;
}
if (!canViewAsPharmacist) {
toast.error(t("no_permission_to_view_page"));
goBack(`/facility/${facilityId}/locations/${locationId}`);
}
}, [canViewAsPharmacist, facility, t, goBack, facilityId, locationId]);

Copilot uses AI. Check for mistakes.
Comment on lines 93 to +117
<NavTabs
className="w-full mt-2"
tabContentClassName="mt-2"
tabs={{
orders: {
label: t("requests_raised"),
component: (
<OutgoingOrdersTab
facilityId={facilityId}
locationId={locationId}
internal={internal}
/>
),
visible: canReadSupplyRequest,
},
deliveries: {
label: t("incoming_deliveries"),
component: (
<IncomingDeliveriesTab
facilityId={facilityId}
locationId={locationId}
internal={internal}
/>
),
visible: canReadSupplyDelivery,
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

NavTabs assumes there is at least one visible tab (it uses allTabKeys[0] as a fallback). With the new visible flags, a user who lacks both canReadSupplyRequest and canReadSupplyDelivery will end up with zero visible tabs, which can produce an invalid/undefined Tabs value and break navigation/rendering. Add an explicit guard for the “no readable tabs” case (redirect, show a no-permission empty state, or ensure at least one tab remains visible).

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/ui/sidebar/facility/location/location-nav.tsx`:
- Line 61: The visibility flags currently allow pharmacy workflows to be shown
when either canViewAsPharmacist or canReadSupplyDelivery is true; tighten this
by changing those visibility conditions to depend only on canViewAsPharmacist.
Locate the visibility properties in the LocationNav sidebar items (where
visibility: canViewAsPharmacist || canReadSupplyDelivery is used) and remove the
canReadSupplyDelivery operand so the expression is just canViewAsPharmacist;
ensure the same change is applied to the other two occurrences that reference
canReadSupplyDelivery alongside canViewAsPharmacist.
- Around line 29-32: The navigation uses inconsistent permission fields: update
the call to getPermissions in location-nav (where canViewAsPharmacist is
derived) to use the same permission source as other nav components—prefer
facility?.permissions—so replace any use of facility?.root_org_permissions with
facility?.permissions (or ensure a canonical selector) when calling
getPermissions in the location-nav component (referencing getPermissions and
canViewAsPharmacist) so all sidebar/service/location/nav components check the
same permission array.

In `@src/pages/Facility/services/HealthcareServiceShow.tsx`:
- Line 136: The temporary facility-level visibility comes from computing
hasManagingOrganization before the service is resolved; change the logic so
hasManagingOrganization (and any permission fallbacks at the shortcut visibility
checks around the earlier conditional block) is only evaluated after the service
is loaded/defined—e.g., guard with service !== undefined or a serviceLoaded flag
and move the const hasManagingOrganization =
!!service?.managing_organization?.id to run only when service exists, then
update the visibility conditionals that currently fall back to facility-level
(the checks around lines 153-174) to first confirm service is resolved before
applying the fallback.

In `@src/pages/Facility/services/inventory/ToDispatch.tsx`:
- Around line 216-221: OutgoingDeliveriesTab is re-calling
useCurrentLocation/usePermissions/getPermissions to derive
canWriteSupplyDelivery even though ToDispatch already computes it; instead,
compute canWriteSupplyDelivery in ToDispatch (using useCurrentLocation,
usePermissions, getPermissions) and pass it into the OutgoingDeliveriesTab
component as a prop (e.g., canWriteSupplyDelivery={canWriteSupplyDelivery});
then remove the redundant hook calls and permission derivation from
OutgoingDeliveriesTab so it reads the prop and uses it directly.

In `@src/pages/Facility/services/pharmacy/MedicationRequestList.tsx`:
- Around line 113-118: The effect that redirects non-pharmacists in
MedicationRequestList.tsx is firing too early because canViewAsPharmacist is
derived from facility?.permissions and may be false while facility is still
loading; update the useEffect to first guard for facility presence (e.g., if
(facility === undefined) return) before showing toast or calling goBack, and
include all external dependencies in the dependency array (canViewAsPharmacist,
facility, t, goBack, facilityId, locationId) so the check runs again when
facility or translations change; ensure you reference the existing identifiers
canViewAsPharmacist, facility, toast, goBack, t, facilityId, and locationId when
making these changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ec2cbea0-eb7e-4180-800b-493f704d3aa9

📥 Commits

Reviewing files that changed from the base of the PR and between 0bbdb5c and 74d192c.

📒 Files selected for processing (10)
  • src/common/Permissions.tsx
  • src/components/ui/sidebar/facility/location/location-nav.tsx
  • src/components/ui/sidebar/facility/service/service-nav.tsx
  • src/components/ui/sidebar/nav-main.tsx
  • src/pages/Facility/services/HealthcareServiceShow.tsx
  • src/pages/Facility/services/inventory/ToDispatch.tsx
  • src/pages/Facility/services/inventory/ToReceive.tsx
  • src/pages/Facility/services/pharmacy/MedicationRequestList.tsx
  • src/types/healthcareService/healthcareService.ts
  • src/types/location/location.ts

Comment on lines +29 to +32
const { canViewAsPharmacist } = getPermissions(
hasPermission,
facility?.permissions ?? [],
);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Facility permission field usage across repo =="
rg -nP 'facility\?\.(permissions|root_org_permissions)|facility\.(permissions|root_org_permissions)' --type ts --type tsx src

echo
echo "== Facility model/type declarations =="
rg -nP 'interface\s+\w*Facility|type\s+\w*Facility' --type ts --type tsx src/types src/pages src/components

echo
echo "== Direct declarations of permission fields in type/model files =="
rg -nP '\b(permissions|root_org_permissions)\b' --type ts --type tsx src/types

Repository: ohcnetwork/care_fe

Length of output: 156


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Facility permission field usage across repo =="
rg -nP 'facility\?\.(permissions|root_org_permissions)|facility\.(permissions|root_org_permissions)' src --glob '*.ts' --glob '*.tsx'

echo
echo "== Facility model/type declarations =="
rg -nP 'interface\s+\w*Facility|type\s+\w*Facility' src/types src/pages src/components --glob '*.ts' --glob '*.tsx'

echo
echo "== Check location-nav.tsx file =="
cat -n src/components/ui/sidebar/facility/location/location-nav.tsx | head -40

echo
echo "== Check HealthcareServiceShow.tsx file =="
cat -n src/pages/Facility/services/HealthcareServiceShow.tsx | sed -n '125,145p'

echo
echo "== Facility type definition =="
rg -nP 'permissions|root_org_permissions' src/types --glob '*.ts' --glob '*.tsx' -B 2 -A 2

Repository: ohcnetwork/care_fe

Length of output: 10215


Use consistent facility.permissions across navigation components for uniform permission checking.

Line 31 uses facility?.permissions, but src/pages/Facility/services/HealthcareServiceShow.tsx Line 134 and src/components/ui/sidebar/facility/service/service-nav.tsx Line 29 use facility?.root_org_permissions. All other usages in the codebase (22+ locations) follow the facility?.permissions pattern. This inconsistency can cause permission-based navigation visibility to diverge if only one permission field is populated.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/ui/sidebar/facility/location/location-nav.tsx` around lines 29
- 32, The navigation uses inconsistent permission fields: update the call to
getPermissions in location-nav (where canViewAsPharmacist is derived) to use the
same permission source as other nav components—prefer facility?.permissions—so
replace any use of facility?.root_org_permissions with facility?.permissions (or
ensure a canonical selector) when calling getPermissions in the location-nav
component (referencing getPermissions and canViewAsPharmacist) so all
sidebar/service/location/nav components check the same permission array.

name: t("pharmacy"),
url: `${baseUrl}/pharmacy`,
icon: <CareIcon icon="l-medical-drip" />,
visibility: canViewAsPharmacist || canReadSupplyDelivery,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Tighten pharmacy workflow visibility to pharmacy-specific permission.

Lines 61, 71, and 76 allow canReadSupplyDelivery to expose pharmacy workflows. This broadens access beyond canViewAsPharmacist and can reveal medication-facing routes to non-pharmacy roles.

🔒 Proposed fix
-          visibility: canViewAsPharmacist || canReadSupplyDelivery,
+          visibility: canViewAsPharmacist,
@@
-              visibility: canViewAsPharmacist || canReadSupplyDelivery,
+              visibility: canViewAsPharmacist,
@@
-              visibility: canReadSupplyDelivery,
+              visibility: canViewAsPharmacist,

Also applies to: 71-71, 76-76

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/ui/sidebar/facility/location/location-nav.tsx` at line 61, The
visibility flags currently allow pharmacy workflows to be shown when either
canViewAsPharmacist or canReadSupplyDelivery is true; tighten this by changing
those visibility conditions to depend only on canViewAsPharmacist. Locate the
visibility properties in the LocationNav sidebar items (where visibility:
canViewAsPharmacist || canReadSupplyDelivery is used) and remove the
canReadSupplyDelivery operand so the expression is just canViewAsPharmacist;
ensure the same change is applied to the other two occurrences that reference
canReadSupplyDelivery alongside canViewAsPharmacist.

canListTokens: canListTokensForFacility,
} = getPermissions(hasPermission, facility?.root_org_permissions ?? []);

const hasManagingOrganization = !!service?.managing_organization?.id;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid evaluating fallback permissions before service scope is resolved.

On Line 136, hasManagingOrganization is false while service is still loading, so Lines 153-174 temporarily apply facility-level visibility. That can briefly render shortcuts under the wrong permission scope.

🔧 Proposed fix
-  const hasManagingOrganization = !!service?.managing_organization?.id;
+  const hasManagingOrganization = Boolean(service?.managing_organization?.id);
+  const isServiceResolved = !isLoading && Boolean(service);
+  const effectiveShortcutPermissions = isServiceResolved
+    ? hasManagingOrganization
+      ? {
+          canViewSchedule,
+          canViewAppointments,
+          canListTokens,
+        }
+      : {
+          canViewSchedule: canViewScheduleForFacility,
+          canViewAppointments: canViewAppointmentsForFacility,
+          canListTokens: canListTokensForFacility,
+        }
+    : {
+        canViewSchedule: false,
+        canViewAppointments: false,
+        canListTokens: false,
+      };
-              visibility: hasManagingOrganization
-                ? canViewSchedule
-                : canViewScheduleForFacility,
+              visibility: effectiveShortcutPermissions.canViewSchedule,
@@
-              visibility: hasManagingOrganization
-                ? canViewAppointments
-                : canViewAppointmentsForFacility,
+              visibility: effectiveShortcutPermissions.canViewAppointments,
@@
-              visibility: hasManagingOrganization
-                ? canListTokens
-                : canListTokensForFacility,
+              visibility: effectiveShortcutPermissions.canListTokens,

Also applies to: 153-155, 162-164, 171-173

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/Facility/services/HealthcareServiceShow.tsx` at line 136, The
temporary facility-level visibility comes from computing hasManagingOrganization
before the service is resolved; change the logic so hasManagingOrganization (and
any permission fallbacks at the shortcut visibility checks around the earlier
conditional block) is only evaluated after the service is loaded/defined—e.g.,
guard with service !== undefined or a serviceLoaded flag and move the const
hasManagingOrganization = !!service?.managing_organization?.id to run only when
service exists, then update the visibility conditionals that currently fall back
to facility-level (the checks around lines 153-174) to first confirm service is
resolved before applying the fallback.

Comment on lines +216 to +221
const { location } = useCurrentLocation();
const { hasPermission } = usePermissions();
const { canWriteSupplyDelivery } = getPermissions(
hasPermission,
location?.permissions ?? [],
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider passing canWriteSupplyDelivery as a prop to avoid redundant hook calls.

OutgoingDeliveriesTab calls useCurrentLocation() and derives permissions again, duplicating the work done in the parent ToDispatch component. This is functional but adds minor overhead.

♻️ Optional: Pass permission as prop
 function OutgoingDeliveriesTab({
   facilityId,
   locationId,
   internal,
+  canWriteSupplyDelivery,
 }: {
   facilityId: string;
   locationId: string;
   internal: boolean;
+  canWriteSupplyDelivery: boolean;
 }) {
   const { t } = useTranslation();
-  const { location } = useCurrentLocation();
-  const { hasPermission } = usePermissions();
-  const { canWriteSupplyDelivery } = getPermissions(
-    hasPermission,
-    location?.permissions ?? [],
-  );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/Facility/services/inventory/ToDispatch.tsx` around lines 216 - 221,
OutgoingDeliveriesTab is re-calling
useCurrentLocation/usePermissions/getPermissions to derive
canWriteSupplyDelivery even though ToDispatch already computes it; instead,
compute canWriteSupplyDelivery in ToDispatch (using useCurrentLocation,
usePermissions, getPermissions) and pass it into the OutgoingDeliveriesTab
component as a prop (e.g., canWriteSupplyDelivery={canWriteSupplyDelivery});
then remove the redundant hook calls and permission derivation from
OutgoingDeliveriesTab so it reads the prop and uses it directly.

Comment on lines +113 to +118
useEffect(() => {
if (!canViewAsPharmacist) {
toast.error(t("no_permission_to_view_page"));
goBack(`/facility/${facilityId}/locations/${locationId}`);
}
}, [canViewAsPharmacist]);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Race condition and incomplete dependency array in permission check.

Two issues:

  1. Premature redirect: When facility is still loading (undefined), facility?.permissions ?? [] yields an empty array, causing canViewAsPharmacist to be false. This triggers an immediate redirect before the facility data loads, even for users with proper permissions.

  2. Missing dependencies: The effect depends on t, goBack, facilityId, and locationId, but only canViewAsPharmacist is listed.

🐛 Proposed fix
+  const { facility, isFacilityLoading } = useCurrentFacility();
-  const { facility } = useCurrentFacility();
   // ...
   useEffect(() => {
+    if (isFacilityLoading) return;
     if (!canViewAsPharmacist) {
       toast.error(t("no_permission_to_view_page"));
       goBack(`/facility/${facilityId}/locations/${locationId}`);
     }
-  }, [canViewAsPharmacist]);
+  }, [canViewAsPharmacist, isFacilityLoading, t, goBack, facilityId, locationId]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/Facility/services/pharmacy/MedicationRequestList.tsx` around lines
113 - 118, The effect that redirects non-pharmacists in
MedicationRequestList.tsx is firing too early because canViewAsPharmacist is
derived from facility?.permissions and may be false while facility is still
loading; update the useEffect to first guard for facility presence (e.g., if
(facility === undefined) return) before showing toast or calling goBack, and
include all external dependencies in the dependency array (canViewAsPharmacist,
facility, t, goBack, facilityId, locationId) so the check runs again when
facility or translations change; ensure you reference the existing identifiers
canViewAsPharmacist, facility, toast, goBack, t, facilityId, and locationId when
making these changes.

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

🎭 Playwright Test Results

Status: ✅ Passed
Test Shards: 3

Metric Count
Total Tests 265
✅ Passed 265
❌ Failed 0
⏭️ Skipped 0

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

Run: #7024

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.

Service and location nav perms

2 participants