diff --git a/src/Components/Facility/FacilityHome.tsx b/src/Components/Facility/FacilityHome.tsx index 52a7cd24027..df5308f7faf 100644 --- a/src/Components/Facility/FacilityHome.tsx +++ b/src/Components/Facility/FacilityHome.tsx @@ -475,15 +475,21 @@ export const FacilityHome = (props: any) => { const LiveMonitoringButton = () => { const facilityId = useSlug("facility"); const [location, setLocation] = useState(); + const authUser = useAuthUser(); + + const permittedUserTypes = ["StateAdmin", "DistrictAdmin", "Doctor"]; return ( - - - - Live Monitoring - - + {permittedUserTypes.includes(authUser.user_type) && ( + + + + Live Monitoring + + + )} + ( @@ -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..614325ddd25 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,15 @@ export const Anyone = () => true; export default function (userTypes: UserRole[]) { return (userType: UserRole) => userTypes.includes(userType); } + +export const AuthorizeUserRoute: React.FC = ({ + userTypes, + children, +}) => { + const authUser = useAuthUser(); + if (userTypes.includes(authUser.user_type)) { + return <>{children}; + } else { + return ; + } +};