Skip to content

Commit

Permalink
Hide External Results tab and pages from Staff and Nurse
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Jan 11, 2024
1 parent 8a5df57 commit 3b448d2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
41 changes: 25 additions & 16 deletions src/Components/Common/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/Routers/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
"/": () => <Redirect to="/facility" />,

...AssetRoutes,
...ConsultationRoutes,
...ExternalResultRoutes,
...FacilityRoutes,
...PatientRoutes,
...ResourceRoutes,
Expand All @@ -49,6 +49,7 @@ const Routes = {
};

export default function AppRouter() {
const authUser = useAuthUser();
const { main_logo, enable_hcx } = useConfig();

let routes = Routes;
Expand All @@ -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) || <Error404 />;
const path = usePath();
Expand Down

0 comments on commit 3b448d2

Please sign in to comment.