diff --git a/forms-flow-web/src/components/PrivateRoute.jsx b/forms-flow-web/src/components/PrivateRoute.jsx index e28b0c65db..98577516be 100644 --- a/forms-flow-web/src/components/PrivateRoute.jsx +++ b/forms-flow-web/src/components/PrivateRoute.jsx @@ -52,6 +52,7 @@ import { AppConfig } from "../config"; import { getFormioRoleIds } from "../apiManager/services/userservices"; import AccessDenied from "./AccessDenied"; import { LANGUAGE } from "../constants/constants"; +import useUserRoles from "../constants/permissions"; export const kcServiceInstance = (tenantId = null) => { return KeycloakService.getInstance( @@ -82,12 +83,17 @@ const PrivateRoute = React.memo((props) => { const [authError, setAuthError] = React.useState(false); const [kcInstance, setKcInstance] = React.useState(getKcInstance()); const [tenantValid, setTenantValid] = React.useState(true); // State to track tenant validity - const createDesigns = userRoles.includes("create_designs"); - const viewDesigns = userRoles.includes("view_designs"); - const viewSubmissions = userRoles.includes("view_submissions"); - const viewTasks = userRoles.includes("view_tasks"); - const manageTasks = userRoles.includes("manage_tasks"); - const viewDashboards = userRoles.includes("view_dashboards"); + + const { + admin, + createDesigns , + createSubmissions , + viewDesigns , + viewSubmissions , + viewTasks, + manageTasks, + viewDashboards + } = useUserRoles(); const authenticate = (instance, store) => { setKcInstance(instance); @@ -208,6 +214,23 @@ const PrivateRoute = React.memo((props) => { ), [userRoles] ); + const FormRoute = useMemo( + () => + ({ component: Component, ...rest }) => + ( + + createDesigns || viewDesigns || createSubmissions ? ( + + ) : ( + + ) + } + /> + ), + [userRoles] + ); const ReviewerRoute = useMemo( () => @@ -275,7 +298,7 @@ const PrivateRoute = React.memo((props) => { }> {ENABLE_FORMS_MODULE && ( - + )} {ENABLE_FORMS_MODULE && ( @@ -313,17 +336,21 @@ const PrivateRoute = React.memo((props) => { component={ServiceFlow} /> )} - + - {userRoles.length && ( - - )} + )}