Patients
diff --git a/src/pages/Organization/components/OrganizationLayout.tsx b/src/pages/Organization/components/OrganizationLayout.tsx
index ab80cd485a1..1668a8c80f1 100644
--- a/src/pages/Organization/components/OrganizationLayout.tsx
+++ b/src/pages/Organization/components/OrganizationLayout.tsx
@@ -1,5 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import { Link, usePath } from "raviger";
+import { useEffect } from "react";
import CareIcon, { IconName } from "@/CAREUI/icons/CareIcon";
@@ -15,6 +16,7 @@ import { Menubar, MenubarMenu, MenubarTrigger } from "@/components/ui/menubar";
import Page from "@/components/Common/Page";
import query from "@/Utils/request/query";
+import { usePermissions } from "@/context/PermissionContext";
import {
Organization,
OrganizationParent,
@@ -26,63 +28,78 @@ interface Props {
navOrganizationId?: string;
id: string;
children: React.ReactNode;
+ setOrganization?: (org: Organization) => void;
}
interface NavItem {
path: string;
title: string;
icon: IconName;
+ visibility: boolean;
}
export default function OrganizationLayout({
id,
navOrganizationId,
children,
+ setOrganization,
}: Props) {
const path = usePath() || "";
+ const { hasPermission } = usePermissions();
const baseUrl = navOrganizationId
? `/organization/${navOrganizationId}/children`
: `/organization`;
+
+ const { data: org, isLoading } = useQuery
({
+ queryKey: ["organization", id],
+ queryFn: query(organizationApi.get, {
+ pathParams: { id },
+ }),
+ enabled: !!id,
+ });
+
+ useEffect(() => {
+ if (org) {
+ setOrganization?.(org);
+ }
+ }, [org, setOrganization]);
+
+ if (isLoading) {
+ return Loading...
;
+ }
+ // add loading state
+ if (!org) {
+ return Not found
;
+ }
+
const navItems: NavItem[] = [
{
path: `${baseUrl}/${id}`,
title: "Organizations",
icon: "d-hospital",
+ visibility: hasPermission("can_view_organization", org.permissions),
},
{
path: `${baseUrl}/${id}/users`,
title: "Users",
icon: "d-people",
+ visibility: hasPermission("can_list_organization_users", org.permissions),
},
{
path: `${baseUrl}/${id}/patients`,
title: "Patients",
icon: "d-patient",
+ visibility: hasPermission("can_list_patients", org.permissions),
},
{
path: `${baseUrl}/${id}/facilities`,
title: "Facilities",
icon: "d-hospital",
+ visibility: hasPermission("can_read_facility", org.permissions),
},
];
- const { data: org, isLoading } = useQuery({
- queryKey: ["organization", id],
- queryFn: query(organizationApi.get, {
- pathParams: { id },
- }),
- enabled: !!id,
- });
-
- if (isLoading) {
- return Loading...
;
- }
- // add loading state
- if (!org) {
- return Not found
;
- }
-
const orgParents: OrganizationParent[] = [];
let currentParent = org.parent;
while (currentParent) {
@@ -121,23 +138,25 @@ export default function OrganizationLayout({
{/* Navigation */}
- {navItems.map((item) => (
-
-
-
-
- {item.title}
-
-
-
- ))}
+ {navItems
+ .filter((item) => item.visibility)
+ .map((item) => (
+
+
+
+
+ {item.title}
+
+
+
+ ))}
{/* Page Content */}
diff --git a/src/types/organization/organization.ts b/src/types/organization/organization.ts
index 68a11895758..5b36828ed09 100644
--- a/src/types/organization/organization.ts
+++ b/src/types/organization/organization.ts
@@ -33,6 +33,7 @@ export interface Organization {
created_at: string;
updated_at: string;
metadata: Metadata | null;
+ permissions: string[];
}
export interface OrganizationUserRole {