Add account related routes to router file

This commit is contained in:
DaneEveritt 2022-06-12 13:33:25 -04:00
parent 7197d28815
commit b50e722948
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 58 additions and 27 deletions

View File

@ -15,9 +15,9 @@ import { ServerContext } from '@/state/server';
import '@/assets/tailwind.css'; import '@/assets/tailwind.css';
import Spinner from '@/components/elements/Spinner'; import Spinner from '@/components/elements/Spinner';
const DashboardRouter = lazy(() => import(/* webpackChunkName: "dash" */'@/routers/DashboardRouter')); const DashboardRouter = lazy(() => import(/* webpackChunkName: "dashboard" */'@/routers/DashboardRouter'));
const ServerRouter = lazy(() => import('@/routers/ServerRouter')); const ServerRouter = lazy(() => import(/* webpackChunkName: "server" */'@/routers/ServerRouter'));
const AuthenticationRouter = lazy(() => import('@/routers/AuthenticationRouter')); const AuthenticationRouter = lazy(() => import(/* webpackChunkName: "auth" */'@/routers/AuthenticationRouter'));
interface ExtendedWindow extends Window { interface ExtendedWindow extends Window {
SiteConfiguration?: SiteSettings; SiteConfiguration?: SiteSettings;

View File

@ -1,16 +1,13 @@
import React from 'react'; import React from 'react';
import { NavLink, Route, Switch } from 'react-router-dom'; import { NavLink, Route, Switch } from 'react-router-dom';
import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer';
import NavigationBar from '@/components/NavigationBar'; import NavigationBar from '@/components/NavigationBar';
import DashboardContainer from '@/components/dashboard/DashboardContainer'; import DashboardContainer from '@/components/dashboard/DashboardContainer';
import AccountApiContainer from '@/components/dashboard/AccountApiContainer';
import { NotFound } from '@/components/elements/ScreenBlock'; import { NotFound } from '@/components/elements/ScreenBlock';
import TransitionRouter from '@/TransitionRouter'; import TransitionRouter from '@/TransitionRouter';
import SubNavigation from '@/components/elements/SubNavigation'; import SubNavigation from '@/components/elements/SubNavigation';
import AccountSSHContainer from '@/components/dashboard/ssh/AccountSSHContainer';
import { useLocation } from 'react-router'; import { useLocation } from 'react-router';
import ActivityLogContainer from '@/components/dashboard/activity/ActivityLogContainer';
import Spinner from '@/components/elements/Spinner'; import Spinner from '@/components/elements/Spinner';
import routes from '@/routers/routes';
export default () => { export default () => {
const location = useLocation(); const location = useLocation();
@ -21,10 +18,15 @@ export default () => {
{location.pathname.startsWith('/account') && {location.pathname.startsWith('/account') &&
<SubNavigation> <SubNavigation>
<div> <div>
<NavLink to={'/account'} exact>Settings</NavLink> {routes.account.filter((route) => !!route.name).map(({ path, name, exact = false }) => (
<NavLink to={'/account/api'}>API Credentials</NavLink> <NavLink
<NavLink to={'/account/ssh'}>SSH Keys</NavLink> key={path}
<NavLink to={'/account/activity'}>Activity</NavLink> to={`/account/${path}`.replace('//', '/')}
exact={exact}
>
{name}
</NavLink>
))}
</div> </div>
</SubNavigation> </SubNavigation>
} }
@ -34,18 +36,11 @@ export default () => {
<Route path={'/'} exact> <Route path={'/'} exact>
<DashboardContainer/> <DashboardContainer/>
</Route> </Route>
<Route path={'/account'} exact> {routes.account.map(({ path, component: Component }) => (
<AccountOverviewContainer/> <Route key={path} path={`/account/${path}`.replace('//', '/')} exact>
</Route> <Component/>
<Route path={'/account/api'} exact>
<AccountApiContainer/>
</Route>
<Route path={'/account/ssh'} exact>
<AccountSSHContainer/>
</Route>
<Route path={'/account/activity'} exact>
<ActivityLogContainer/>
</Route> </Route>
))}
<Route path={'*'}> <Route path={'*'}>
<NotFound/> <NotFound/>
</Route> </Route>

View File

@ -8,27 +8,63 @@ import NetworkContainer from '@/components/server/network/NetworkContainer';
import StartupContainer from '@/components/server/startup/StartupContainer'; import StartupContainer from '@/components/server/startup/StartupContainer';
import FileManagerContainer from '@/components/server/files/FileManagerContainer'; import FileManagerContainer from '@/components/server/files/FileManagerContainer';
import SettingsContainer from '@/components/server/settings/SettingsContainer'; import SettingsContainer from '@/components/server/settings/SettingsContainer';
import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer';
import AccountApiContainer from '@/components/dashboard/AccountApiContainer';
import AccountSSHContainer from '@/components/dashboard/ssh/AccountSSHContainer';
import ActivityLogContainer from '@/components/dashboard/activity/ActivityLogContainer';
// Each of the router files is already code split out appropriately — so
// all of the items above will only be loaded in when that router is loaded.
//
// These specific lazy loaded routes are to avoid loading in heavy screens
// for the server dashboard when they're only needed for specific instances.
const FileEditContainer = lazy(() => import('@/components/server/files/FileEditContainer')); const FileEditContainer = lazy(() => import('@/components/server/files/FileEditContainer'));
const ScheduleEditContainer = lazy(() => import('@/components/server/schedules/ScheduleEditContainer')); const ScheduleEditContainer = lazy(() => import('@/components/server/schedules/ScheduleEditContainer'));
interface ServerRouteDefinition { interface RouteDefinition {
path: string; path: string;
permission: string | string[] | null;
// If undefined is passed this route is still rendered into the router itself // If undefined is passed this route is still rendered into the router itself
// but no navigation link is displayed in the sub-navigation menu. // but no navigation link is displayed in the sub-navigation menu.
name: string | undefined; name: string | undefined;
component: React.ComponentType; component: React.ComponentType;
// The default for "exact" is assumed to be "true" unless you explicitly
// pass it as false.
exact?: boolean; exact?: boolean;
} }
interface ServerRouteDefinition extends RouteDefinition {
permission: string | string[] | null;
}
interface Routes { interface Routes {
// All of the routes available under "/account"
account: RouteDefinition[];
// All of the routes available under "/server/:id"
server: ServerRouteDefinition[]; server: ServerRouteDefinition[];
} }
export default { export default {
account: [
{
path: '/',
name: 'Account',
component: AccountOverviewContainer,
exact: true,
},
{
path: '/api',
name: 'API Credentials',
component: AccountApiContainer,
},
{
path: '/ssh',
name: 'SSH Keys',
component: AccountSSHContainer,
},
{
path: '/activity',
name: 'Activity',
component: ActivityLogContainer,
},
],
server: [ server: [
{ {
path: '/', path: '/',