diff --git a/src/Routers/routes/FacilityLocationRoutes.tsx b/src/Routers/routes/FacilityLocationRoutes.tsx
index aa08661da8b..81896b48c98 100644
--- a/src/Routers/routes/FacilityLocationRoutes.tsx
+++ b/src/Routers/routes/FacilityLocationRoutes.tsx
@@ -4,6 +4,7 @@ import { AddLocationForm } from "../../Components/Facility/AddLocationForm";
import { BedManagement } from "../../Components/Facility/BedManagement";
import LocationManagement from "../../Components/Facility/LocationManagement";
import CentralLiveMonitoring from "../../Components/CameraFeed/CentralLiveMonitoring";
+import { AuthorizeUserRoute } from "../../Utils/AuthorizeFor";
export default {
"/facility/:facilityId/location": ({ facilityId }: any) => (
@@ -37,6 +38,8 @@ export default {
),
"/facility/:facilityId/live-monitoring": (props: any) => (
-
+
+
+
),
};
diff --git a/src/Utils/AuthorizeFor.tsx b/src/Utils/AuthorizeFor.tsx
index 0ba40755205..38ca5fb4165 100644
--- a/src/Utils/AuthorizeFor.tsx
+++ b/src/Utils/AuthorizeFor.tsx
@@ -1,6 +1,15 @@
import { UserRole } from "../Common/constants";
+import React from "react";
+import useAuthUser from "../Common/hooks/useAuthUser";
+import Error404 from "../Components/ErrorPages/404";
export type AuthorizedForCB = (userType: UserRole) => boolean;
+
+interface AuthorizeUserRouteProps {
+ userTypes: UserRole[];
+ children: React.ReactNode;
+}
+
export type AuthorizedElementProps = {
/**
* Restrict access of this button to specific roles.
@@ -26,3 +35,16 @@ export const Anyone = () => true;
export default function (userTypes: UserRole[]) {
return (userType: UserRole) => userTypes.includes(userType);
}
+
+export const AuthorizeUserRoute: React.FC = ({
+ userTypes,
+ children,
+}) => {
+ const userData = useAuthUser();
+
+ if (userData && userTypes.includes(userData.user_type)) {
+ return <>{children}>;
+ } else {
+ return ;
+ }
+};