2022-11-25 20:25:03 +00:00
|
|
|
import { Suspense } from 'react';
|
|
|
|
import { NavLink, Route, Routes, useLocation } from 'react-router-dom';
|
|
|
|
|
2019-06-26 04:28:56 +00:00
|
|
|
import NavigationBar from '@/components/NavigationBar';
|
|
|
|
import DashboardContainer from '@/components/dashboard/DashboardContainer';
|
2021-01-31 02:01:32 +00:00
|
|
|
import { NotFound } from '@/components/elements/ScreenBlock';
|
2022-06-11 18:04:09 +00:00
|
|
|
import Spinner from '@/components/elements/Spinner';
|
2022-11-25 20:25:03 +00:00
|
|
|
import SubNavigation from '@/components/elements/SubNavigation';
|
2022-06-12 17:33:25 +00:00
|
|
|
import routes from '@/routers/routes';
|
2019-06-26 04:28:56 +00:00
|
|
|
|
2022-11-25 20:25:03 +00:00
|
|
|
function DashboardRouter() {
|
2022-05-28 17:32:35 +00:00
|
|
|
const location = useLocation();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-06-26 19:13:52 +00:00
|
|
|
<NavigationBar />
|
2022-11-25 20:25:03 +00:00
|
|
|
|
2022-06-26 19:13:52 +00:00
|
|
|
{location.pathname.startsWith('/account') && (
|
2022-05-28 17:32:35 +00:00
|
|
|
<SubNavigation>
|
|
|
|
<div>
|
2022-06-26 19:13:52 +00:00
|
|
|
{routes.account
|
2022-11-25 20:25:03 +00:00
|
|
|
.filter(route => route.path !== undefined)
|
|
|
|
.map(({ path, name, end = false }) => (
|
2023-01-13 18:58:40 +00:00
|
|
|
<NavLink key={path} to={`/account/${path ?? ''}`.replace(/\/$/, '')} end={end}>
|
2022-06-26 19:13:52 +00:00
|
|
|
{name}
|
|
|
|
</NavLink>
|
|
|
|
))}
|
2022-05-28 17:32:35 +00:00
|
|
|
</div>
|
|
|
|
</SubNavigation>
|
2022-06-26 19:13:52 +00:00
|
|
|
)}
|
2022-11-25 20:25:03 +00:00
|
|
|
|
|
|
|
<Suspense fallback={<Spinner centered />}>
|
|
|
|
<Routes>
|
|
|
|
<Route path="" element={<DashboardContainer />} />
|
|
|
|
|
|
|
|
{routes.account.map(({ route, component: Component }) => (
|
2023-01-13 18:58:40 +00:00
|
|
|
<Route key={route} path={`/account/${route}`.replace(/\/$/, '')} element={<Component />} />
|
2022-11-25 20:25:03 +00:00
|
|
|
))}
|
|
|
|
|
|
|
|
<Route path="*" element={<NotFound />} />
|
|
|
|
</Routes>
|
|
|
|
</Suspense>
|
2022-05-28 17:32:35 +00:00
|
|
|
</>
|
|
|
|
);
|
2022-11-25 20:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default DashboardRouter;
|