From 87a89e1563a68bebd32ce6e621df08267feeb24b Mon Sep 17 00:00:00 2001 From: Arjun-Go Date: Mon, 4 Jul 2022 15:20:30 +0530 Subject: [PATCH] refactor. props in UserHasAccess component --- .../esm-react-utils/src/UserHasAccess.tsx | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/packages/framework/esm-react-utils/src/UserHasAccess.tsx b/packages/framework/esm-react-utils/src/UserHasAccess.tsx index 55912d392..a11874ef8 100644 --- a/packages/framework/esm-react-utils/src/UserHasAccess.tsx +++ b/packages/framework/esm-react-utils/src/UserHasAccess.tsx @@ -1,18 +1,15 @@ /** @module @category API */ import { getCurrentUser, LoggedInUser, userHasAccess } from "@openmrs/esm-api"; -import { InlineNotification } from "carbon-components-react"; import React, { useEffect, useState } from "react"; -export interface UserHasAccessProps { +interface UserHasAccessProps { privilege: string; - unauthorisedResponse?: string | undefined; - redirectUrl?: string | undefined; + unauthorisedResponse?: React.ReactNode | undefined; } export const UserHasAccess: React.FC = ({ privilege, unauthorisedResponse, - redirectUrl, children, }) => { const [user, setUser] = useState(null); @@ -26,23 +23,7 @@ export const UserHasAccess: React.FC = ({ if (user && userHasAccess(privilege, user)) { return <>{children}; + } else { + return unauthorisedResponse ? <>{unauthorisedResponse} : null; } - - if (unauthorisedResponse) { - return ( -
- -
- ); - } - - if (redirectUrl) { - window.location.replace(redirectUrl); - } - - return null; };