From 58a7e559af4d2a28ca13dbe48866fff5bab43d36 Mon Sep 17 00:00:00 2001 From: fahad-aot Date: Thu, 8 Aug 2024 01:18:11 -0700 Subject: [PATCH 1/2] FWF:3560[Bugfix] Fixed Admin Login showing Forms page --- .../src/components/PrivateRoute.jsx | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/forms-flow-web/src/components/PrivateRoute.jsx b/forms-flow-web/src/components/PrivateRoute.jsx index c26b3dda3b..ac4c27d965 100644 --- a/forms-flow-web/src/components/PrivateRoute.jsx +++ b/forms-flow-web/src/components/PrivateRoute.jsx @@ -88,9 +88,10 @@ const PrivateRoute = React.memo((props) => { const viewTasks = userRoles.includes("view_tasks"); const manageTasks = userRoles.includes("manage_tasks"); const viewDashboards = userRoles.includes("view_dashbaords"); - - - + const isAdmin = userRoles.includes("admin"); + const isCreateSubmissions = userRoles?.includes("create_submissions"); + const isViewDesigns = userRoles?.includes("view_designs"); + const isCreateDesigns = userRoles?.includes("create_designs"); const authenticate = (instance, store) => { setKcInstance(instance); @@ -298,18 +299,21 @@ const PrivateRoute = React.memo((props) => { component={ServiceFlow} /> )} - + {userRoles.length && ( - -)} - + + )} From 07e8d9d40bb22ac42d773cf8e13d81f75b3f1aac Mon Sep 17 00:00:00 2001 From: fahad-aot Date: Tue, 13 Aug 2024 21:38:10 -0700 Subject: [PATCH 2/2] Added FormRoute --- .../src/components/PrivateRoute.jsx | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/forms-flow-web/src/components/PrivateRoute.jsx b/forms-flow-web/src/components/PrivateRoute.jsx index ac4c27d965..ba3782d968 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,16 +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_dashbaords"); - const isAdmin = userRoles.includes("admin"); - const isCreateSubmissions = userRoles?.includes("create_submissions"); - const isViewDesigns = userRoles?.includes("view_designs"); - const isCreateDesigns = userRoles?.includes("create_designs"); + + const { + admin, + createDesigns , + createSubmissions , + viewDesigns , + viewSubmissions , + viewTasks, + manageTasks, + viewDashboards + } = useUserRoles(); const authenticate = (instance, store) => { setKcInstance(instance); @@ -194,6 +196,23 @@ const PrivateRoute = React.memo((props) => { ), [userRoles] ); + const FormRoute = useMemo( + () => + ({ component: Component, ...rest }) => + ( + + createDesigns || viewDesigns || createSubmissions ? ( + + ) : ( + + ) + } + /> + ), + [userRoles] + ); const ReviewerRoute = useMemo( () => @@ -261,7 +280,7 @@ const PrivateRoute = React.memo((props) => { }> {ENABLE_FORMS_MODULE && ( - + )} {ENABLE_FORMS_MODULE && ( @@ -306,9 +325,9 @@ const PrivateRoute = React.memo((props) => { to={ (viewTasks || manageTasks) ? `${redirecUrl}task` - : ( isCreateSubmissions || isCreateDesigns || isViewDesigns) + : ( createSubmissions || createDesigns || viewDesigns) ? `${redirecUrl}form` - : isAdmin + : admin ? `${redirecUrl}admin` : `${BASE_ROUTE}processes` }