diff --git a/src/Components/Common/Sidebar/Sidebar.tsx b/src/Components/Common/Sidebar/Sidebar.tsx index fa809571772..9d378df4267 100644 --- a/src/Components/Common/Sidebar/Sidebar.tsx +++ b/src/Components/Common/Sidebar/Sidebar.tsx @@ -8,6 +8,7 @@ import useConfig from "../../../Common/hooks/useConfig"; import SlideOver from "../../../CAREUI/interactive/SlideOver"; import { classNames } from "../../../Utils/utils"; import { Link } from "raviger"; +import useAuthUser from "../../../Common/hooks/useAuthUser"; export const SIDEBAR_SHRINK_PREFERENCE_KEY = "sidebarShrinkPreference"; @@ -27,28 +28,36 @@ type StatelessSidebarProps = onItemClick: (open: boolean) => void; }; -const NavItems = [ - { text: "Facilities", to: "/facility", icon: "care-l-hospital" }, - { text: "Patients", to: "/patients", icon: "care-l-user-injured" }, - { text: "Assets", to: "/assets", icon: "care-l-shopping-cart-alt" }, - { text: "Sample Test", to: "/sample", icon: "care-l-medkit" }, - { text: "Shifting", to: "/shifting", icon: "care-l-ambulance" }, - { text: "Resource", to: "/resource", icon: "care-l-heart-medical" }, - { - text: "External Results", - to: "/external_results", - icon: "care-l-clipboard-notes", - }, - { text: "Users", to: "/users", icon: "care-l-users-alt" }, - { text: "Notice Board", to: "/notice_board", icon: "care-l-meeting-board" }, -]; - const StatelessSidebar = ({ shrinkable = false, shrinked = false, setShrinked, onItemClick, }: StatelessSidebarProps) => { + const authUser = useAuthUser(); + + const NavItems = [ + { text: "Facilities", to: "/facility", icon: "care-l-hospital" }, + { text: "Patients", to: "/patients", icon: "care-l-user-injured" }, + { text: "Assets", to: "/assets", icon: "care-l-shopping-cart-alt" }, + { text: "Sample Test", to: "/sample", icon: "care-l-medkit" }, + { text: "Shifting", to: "/shifting", icon: "care-l-ambulance" }, + { text: "Resource", to: "/resource", icon: "care-l-heart-medical" }, + ...(!["Nurse", "NurseReadOnly", "Staff", "StaffReadOnly"].includes( + authUser.user_type + ) + ? [ + { + text: "External Results", + to: "/external_results", + icon: "care-l-clipboard-notes", + }, + ] + : []), + { text: "Users", to: "/users", icon: "care-l-users-alt" }, + { text: "Notice Board", to: "/notice_board", icon: "care-l-meeting-board" }, + ]; + const { main_logo } = useConfig(); const activeLink = useActiveLink(); const Item = shrinked ? ShrinkedSidebarItem : SidebarItem; diff --git a/src/Routers/AppRouter.tsx b/src/Routers/AppRouter.tsx index 5e238627bc8..56d8b31573b 100644 --- a/src/Routers/AppRouter.tsx +++ b/src/Routers/AppRouter.tsx @@ -25,13 +25,13 @@ import AssetRoutes from "./routes/AssetRoutes"; import ResourceRoutes from "./routes/ResourceRoutes"; import ExternalResultRoutes from "./routes/ExternalResultRoutes"; import { DetailRoute } from "./types"; +import useAuthUser from "../Common/hooks/useAuthUser"; const Routes = { "/": () => , ...AssetRoutes, ...ConsultationRoutes, - ...ExternalResultRoutes, ...FacilityRoutes, ...PatientRoutes, ...ResourceRoutes, @@ -49,6 +49,7 @@ const Routes = { }; export default function AppRouter() { + const authUser = useAuthUser(); const { main_logo, enable_hcx } = useConfig(); let routes = Routes; @@ -57,6 +58,14 @@ export default function AppRouter() { routes = { ...routes, ...HCXRoutes }; } + if ( + !["Nurse", "NurseReadOnly", "Staff", "StaffReadOnly"].includes( + authUser.user_type + ) + ) { + routes = { ...routes, ...ExternalResultRoutes }; + } + useRedirect("/user", "/users"); const pages = useRoutes(routes) || ; const path = usePath();