Skip to content

Commit

Permalink
Merge pull request #2190 from abilpraju-aot/bugfix/FWF-3579-dashboard
Browse files Browse the repository at this point in the history
dashboard seperete route
  • Loading branch information
arun-s-aot authored Aug 13, 2024
2 parents 4340e68 + a93ea48 commit 99058a6
Showing 1 changed file with 83 additions and 69 deletions.
152 changes: 83 additions & 69 deletions forms-flow-web/src/components/PrivateRoute.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
import React, { useEffect, Suspense, lazy, useMemo,useCallback } from "react";
import React, { useEffect, Suspense, lazy, useMemo, useCallback } from "react";
import { Route, Switch, Redirect, useParams } from "react-router-dom";
import { useDispatch, useSelector} from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import {
BASE_ROUTE,
DRAFT_ENABLED,
Expand Down Expand Up @@ -87,10 +87,7 @@ const PrivateRoute = React.memo((props) => {
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 viewDashboards = userRoles.includes("view_dashboards");

const authenticate = (instance, store) => {
setKcInstance(instance);
Expand Down Expand Up @@ -166,85 +163,103 @@ const PrivateRoute = React.memo((props) => {
}, [tenantId, props.store, dispatch]);

useEffect(() => {
if (kcInstance ) {
if (kcInstance) {
const lang =
kcInstance?.userData?.locale ||
tenant?.tenantData?.details?.locale ||
selectedLanguage ||
LANGUAGE;
dispatch(setLanguage(lang));
dispatch(setLanguage(lang));
}
}, [kcInstance, tenant?.tenantData]);

const DesignerRoute = useMemo(
() =>
({ component: Component, ...rest }) =>
(
<Route
{...rest}
render={(props) =>
createDesigns || viewDesigns ? (
<Component {...props} />
) : (
<AccessDenied userRoles={userRoles} />
)
}
/>
),
(
<Route
{...rest}
render={(props) =>
createDesigns || viewDesigns ? (
<Component {...props} />
) : (
<AccessDenied userRoles={userRoles} />
)
}
/>
),
[userRoles]
);

const DashBoardRoute = useMemo(
() =>
({ component: Component, ...rest }) =>
(
<Route
{...rest}
render={(props) =>
viewDashboards ? (
<Component {...props} />
) : (
<AccessDenied userRoles={userRoles} />
)
}
/>
),
[userRoles]
);

const ReviewerRoute = useMemo(
() =>
({ component: Component, ...rest }) =>
(
<Route
{...rest}
render={(props) =>
viewTasks || manageTasks || viewDashboards ? (
<Component {...props} />
) : (
<AccessDenied userRoles={userRoles} />
)
}
/>
),
(
<Route
{...rest}
render={(props) =>
viewTasks || manageTasks || viewDashboards ? (
<Component {...props} />
) : (
<AccessDenied userRoles={userRoles} />
)
}
/>
),
[userRoles]
);

const ClientReviewerRoute = useMemo(
() =>
({ component: Component, ...rest }) =>
(
<Route
{...rest}
render={(props) =>
viewSubmissions ? (
<Component {...props} />
) : (
<AccessDenied userRoles={userRoles} />
)
}
/>
),
(
<Route
{...rest}
render={(props) =>
viewSubmissions ? (
<Component {...props} />
) : (
<AccessDenied userRoles={userRoles} />
)
}
/>
),
[userRoles]
);

const DraftRoute = useMemo(
() =>
({ component: Component, ...rest }) =>
(
<Route
{...rest}
render={(props) =>
DRAFT_ENABLED && viewSubmissions ? (
<Component {...props} />
) : (
<AccessDenied userRoles={userRoles} />
)
}
/>
),
(
<Route
{...rest}
render={(props) =>
DRAFT_ENABLED && viewSubmissions ? (
<Component {...props} />
) : (
<AccessDenied userRoles={userRoles} />
)
}
/>
),
[userRoles]
);

Expand Down Expand Up @@ -281,13 +296,13 @@ const PrivateRoute = React.memo((props) => {
/>
)}
{ENABLE_DASHBOARDS_MODULE && (
<ReviewerRoute
<DashBoardRoute
path={`${BASE_ROUTE}metrics`}
component={DashboardPage}
/>
)}
{ENABLE_DASHBOARDS_MODULE && (
<ReviewerRoute
<DashBoardRoute
path={`${BASE_ROUTE}insights`}
component={InsightsPage}
/>
Expand All @@ -300,16 +315,15 @@ const PrivateRoute = React.memo((props) => {
)}

<Route exact path={BASE_ROUTE}>
{userRoles.length && (
<Redirect
to={
viewTasks || manageTasks
? `${redirecUrl}task`
: `${redirecUrl}form`
}
/>
)}

{userRoles.length && (
<Redirect
to={
viewTasks || manageTasks
? `${redirecUrl}task`
: `${redirecUrl}form`
}
/>
)}
</Route>
<Route path="/404" exact={true} component={NotFound} />
<Redirect from="*" to="/404" />
Expand All @@ -322,4 +336,4 @@ const PrivateRoute = React.memo((props) => {
);
});

export default PrivateRoute;
export default PrivateRoute;

0 comments on commit 99058a6

Please sign in to comment.