Skip to content

Commit

Permalink
Merge pull request #2182 from fahad-aot/bugfix/FWF-3560-Admin-Login-s…
Browse files Browse the repository at this point in the history
…howing-Forms

FWF:3560[Bugfix] Fixed Admin Login showing Forms page
  • Loading branch information
arun-s-aot authored Aug 16, 2024
2 parents 23755c6 + 9b3cf6e commit bfd0b49
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions forms-flow-web/src/components/PrivateRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -208,6 +214,23 @@ const PrivateRoute = React.memo((props) => {
),
[userRoles]
);
const FormRoute = useMemo(
() =>
({ component: Component, ...rest }) =>
(
<Route
{...rest}
render={(props) =>
createDesigns || viewDesigns || createSubmissions ? (
<Component {...props} />
) : (
<AccessDenied userRoles={userRoles} />
)
}
/>
),
[userRoles]
);

const ReviewerRoute = useMemo(
() =>
Expand Down Expand Up @@ -275,7 +298,7 @@ const PrivateRoute = React.memo((props) => {
<Suspense fallback={<Loading />}>
<Switch>
{ENABLE_FORMS_MODULE && (
<Route path={`${BASE_ROUTE}form`} component={Form} />
<FormRoute path={`${BASE_ROUTE}form`} component={Form} />
)}
{ENABLE_FORMS_MODULE && (
<DesignerRoute path={`${BASE_ROUTE}formflow`} component={Form} />
Expand Down Expand Up @@ -313,17 +336,21 @@ const PrivateRoute = React.memo((props) => {
component={ServiceFlow}
/>
)}

<Route exact path={`${redirecUrl}admin`} />
<Route exact path={BASE_ROUTE}>
{userRoles.length && (
<Redirect
to={
viewTasks || manageTasks
? `${redirecUrl}task`
: `${redirecUrl}form`
}
{userRoles.length && (
<Redirect
to={
(viewTasks || manageTasks)
? `${redirecUrl}task`
: ( createSubmissions || createDesigns || viewDesigns)
? `${redirecUrl}form`
: admin
? `${redirecUrl}admin`
: `${BASE_ROUTE}processes`
}
/>
)}
)}
</Route>
<Route path="/404" exact={true} component={NotFound} />
<Redirect from="*" to="/404" />
Expand Down

0 comments on commit bfd0b49

Please sign in to comment.