Skip to content

Commit eb22a8f

Browse files
fix: revert react router upgrade (#2024)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent aafb149 commit eb22a8f

File tree

4 files changed

+83
-59
lines changed

4 files changed

+83
-59
lines changed

frontend/package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"react-beforeunload": "^2.6.0",
4141
"react-dom": "^18.2.0",
4242
"react-hash-string": "^1.0.0",
43-
"react-router": "^7.5.2",
43+
"react-router": "^7.1.1",
4444
"react-test-renderer": "^18.2.0",
4545
"react-toastify": "^11.0.0",
4646
"sass": "^1.77.7",

frontend/src/App.tsx

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { useContext, useEffect } from 'react';
1+
import React, { useContext, useEffect, useMemo } from 'react';
22
import {
3-
BrowserRouter
3+
createBrowserRouter, RouteObject, RouterProvider
44
} from 'react-router';
55
import { Amplify } from 'aws-amplify';
66
import { ClassPrefix } from '@carbon/react';
@@ -11,11 +11,19 @@ import awsconfig from './aws-exports';
1111
import prefix from './styles/classPrefix';
1212
import './styles/custom.scss';
1313
import 'react-toastify/dist/ReactToastify.css';
14+
15+
import Layout from './layout/PrivateLayout';
16+
import Landing from './views/Landing';
17+
import FourOhFour from './views/ErrorViews/FourOhFour';
18+
import LoginOrgSelection from './views/LoginOrgSelection';
19+
import ServiceStatus from './views/ServiceStatus';
1420
import { NavigateProvider } from './contexts/NavigationContext';
1521
import AuthContext from './contexts/AuthContext';
22+
import BrowserRoutes from './routes';
23+
import ROUTES from './routes/constants';
24+
import ProtectedRoute from './routes/ProtectedRoute';
1625
import { ThemePreference } from './utils/ThemePreference';
1726
import CustomQueryProvider from './components/CustomQueryProvider';
18-
import AppRoutes from './AppRoutes';
1927

2028
Amplify.configure(awsconfig);
2129

@@ -25,25 +33,82 @@ Amplify.configure(awsconfig);
2533
* @returns {JSX.Element} instance of the app ready to use.
2634
*/
2735
const App: React.FC = () => {
28-
const { isCurrentAuthUser } = useContext(AuthContext);
36+
const { signed, isCurrentAuthUser, selectedClientRoles } = useContext(AuthContext);
2937

3038
useEffect(() => {
3139
isCurrentAuthUser(window.location.pathname);
3240
}, []);
3341

42+
const roleSelectionRoutes: RouteObject[] = [
43+
{
44+
path: ROUTES.ALL_ROUTES,
45+
element: <LoginOrgSelection />
46+
}
47+
];
48+
49+
const signedRoutes: RouteObject[] = [
50+
{
51+
path: ROUTES.ROOT,
52+
element: <ProtectedRoute />,
53+
children: [
54+
{
55+
element: <Layout />,
56+
children: BrowserRoutes
57+
}
58+
]
59+
},
60+
{
61+
path: ROUTES.FOUR_OH_FOUR,
62+
element: <FourOhFour />
63+
},
64+
{
65+
path: ROUTES.ALL_ROUTES,
66+
element: <FourOhFour />
67+
}
68+
];
69+
70+
const notSignedRoutes: RouteObject[] = [
71+
{
72+
path: ROUTES.ALL_ROUTES,
73+
element: <Landing />
74+
}
75+
];
76+
77+
const sharedRoutes: RouteObject[] = [
78+
{
79+
path: ROUTES.SERVICE_STATUS,
80+
element: <ServiceStatus />
81+
}
82+
];
83+
84+
const browserRouter = useMemo(() => {
85+
const selectBrowserRoutes = () => {
86+
if (!signed) {
87+
return notSignedRoutes;
88+
}
89+
if (selectedClientRoles) {
90+
return signedRoutes;
91+
}
92+
return roleSelectionRoutes;
93+
};
94+
95+
const selectedRoutes = selectBrowserRoutes();
96+
selectedRoutes.push(...sharedRoutes);
97+
98+
return createBrowserRouter(selectedRoutes);
99+
}, [signed, selectedClientRoles]);
100+
101+
const handleRedirectTo403 = () => {
102+
browserRouter.navigate('/403');
103+
};
104+
34105
return (
35106
<ClassPrefix prefix={prefix}>
36107
<ThemePreference>
37-
<NavigateProvider onRedirect={() => {
38-
// go to 403 page
39-
window.location.href = '/403';
40-
}}
41-
>
108+
<NavigateProvider onRedirect={handleRedirectTo403}>
42109
<CustomQueryProvider>
43110
<ToastContainer />
44-
<BrowserRouter>
45-
<AppRoutes />
46-
</BrowserRouter>
111+
<RouterProvider router={browserRouter} />
47112
<ReactQueryDevtools initialIsOpen={false} />
48113
</CustomQueryProvider>
49114
</NavigateProvider>

frontend/src/AppRoutes.tsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)