Skip to content

Commit

Permalink
[Bug Fix] MCR Reports Access (#11557)
Browse files Browse the repository at this point in the history
  • Loading branch information
karla-vm authored Jan 9, 2024
1 parent 4792325 commit 297c2a4
Showing 1 changed file with 69 additions and 44 deletions.
113 changes: 69 additions & 44 deletions services/ui-src/src/components/app/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ import { Fragment, useContext } from "react";
import { Flex, Spinner } from "@chakra-ui/react";

export const AppRoutes = () => {
const { userIsAdmin } = useStore().user ?? {};
const { userIsAdmin, userIsEndUser } = useStore().user ?? {};
const { report, contextIsLoaded } = useContext(ReportContext);

// LaunchDarkly
const mlrReport = useFlags()?.mlrReport;

/*
* Verifying whether a user has the required roles / access to MCR reports
* NOTE: It is possible for a user to be authorized via IDM, but not have an end-user (state) role OR an admin-type role
* due to their role type being deprecated, for example, such as with the STATE REP role.
*/
const userHasAccess = userIsAdmin || userIsEndUser;

return (
<main id="main-content" tabIndex={-1}>
<ScrollToTopComponent />
Expand All @@ -41,48 +48,20 @@ export const AppRoutes = () => {
<Route path="/profile" element={<ProfilePage />} />
<Route path="*" element={<NotFoundPage />} />

{/* MCPAR ROUTES */}
<Route path="/mcpar" element={<DashboardPage reportType="MCPAR" />} />
<Route
path="/mcpar/get-started"
element={<ReportGetStartedPage reportType="MCPAR" />}
/>
{report?.reportType === ReportType.MCPAR && (
{!userHasAccess ? (
<Navigate to="/" />
) : (
<>
{(report.formTemplate.flatRoutes ?? []).map(
(route: ReportRoute) => (
<Route
key={route.path}
path={route.path}
element={<ReportPageWrapper />}
/>
)
)}
<Route path="/mcpar/export" element={<ExportedReportPage />} />
</>
)}
<Route
path="/mcpar/*"
element={
!contextIsLoaded ? (
<Flex sx={sx.spinnerContainer}>
<Spinner size="lg" />
</Flex>
) : (
<Navigate to="/mcpar" />
)
}
/>

{/* MLR ROUTES */}
{mlrReport && (
<Fragment>
<Route path="/mlr" element={<DashboardPage reportType="MLR" />} />
{/* MCPAR ROUTES */}
<Route
path="/mlr/get-started"
element={<ReportGetStartedPage reportType="MLR" />}
path="/mcpar"
element={<DashboardPage reportType="MCPAR" />}
/>
{report?.reportType === ReportType.MLR && (
<Route
path="/mcpar/get-started"
element={<ReportGetStartedPage reportType="MCPAR" />}
/>
{report?.reportType === ReportType.MCPAR && (
<>
{(report.formTemplate.flatRoutes ?? []).map(
(route: ReportRoute) => (
Expand All @@ -93,22 +72,68 @@ export const AppRoutes = () => {
/>
)
)}
<Route path="/mlr/export" element={<ExportedReportPage />} />
<Route
path="/mcpar/export"
element={<ExportedReportPage />}
/>
</>
)}
<Route
path="/mlr/*"
path="/mcpar/*"
element={
!contextIsLoaded ? (
<Flex sx={sx.spinnerContainer}>
<Spinner size="lg" />
</Flex>
) : (
<Navigate to="/mlr" />
<Navigate to="/mcpar" />
)
}
/>
</Fragment>

{/* MLR ROUTES */}
{mlrReport && (
<Fragment>
<Route
path="/mlr"
element={<DashboardPage reportType="MLR" />}
/>
<Route
path="/mlr/get-started"
element={<ReportGetStartedPage reportType="MLR" />}
/>
{report?.reportType === ReportType.MLR && (
<>
{(report.formTemplate.flatRoutes ?? []).map(
(route: ReportRoute) => (
<Route
key={route.path}
path={route.path}
element={<ReportPageWrapper />}
/>
)
)}
<Route
path="/mlr/export"
element={<ExportedReportPage />}
/>
</>
)}
<Route
path="/mlr/*"
element={
!contextIsLoaded ? (
<Flex sx={sx.spinnerContainer}>
<Spinner size="lg" />
</Flex>
) : (
<Navigate to="/mlr" />
)
}
/>
</Fragment>
)}
</>
)}
</Routes>
</AdminBannerProvider>
Expand Down

0 comments on commit 297c2a4

Please sign in to comment.