misc_pterodactyl-panel/resources/scripts/components/App.tsx

110 lines
3.9 KiB
TypeScript
Raw Normal View History

import { StoreProvider } from 'easy-peasy';
2022-11-25 20:25:03 +00:00
import { lazy } from 'react';
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import '@/assets/tailwind.css';
import GlobalStylesheet from '@/assets/css/GlobalStylesheet';
import AuthenticatedRoute from '@/components/elements/AuthenticatedRoute';
2022-11-25 20:25:03 +00:00
import ProgressBar from '@/components/elements/ProgressBar';
import { NotFound } from '@/components/elements/ScreenBlock';
import Spinner from '@/components/elements/Spinner';
2022-11-25 20:25:03 +00:00
import { store } from '@/state';
import { ServerContext } from '@/state/server';
import { SiteSettings } from '@/state/settings';
2022-11-25 20:25:03 +00:00
const DashboardRouter = lazy(() => import('@/routers/DashboardRouter'));
const ServerRouter = lazy(() => import('@/routers/ServerRouter'));
const AuthenticationRouter = lazy(() => import('@/routers/AuthenticationRouter'));
2019-12-16 02:05:44 +00:00
interface ExtendedWindow extends Window {
SiteConfiguration?: SiteSettings;
PterodactylUser?: {
uuid: string;
username: string;
email: string;
/* eslint-disable camelcase */
root_admin: boolean;
use_totp: boolean;
language: string;
updated_at: string;
created_at: string;
/* eslint-enable camelcase */
};
}
2022-11-25 20:25:03 +00:00
// setupInterceptors(history);
2022-11-25 20:25:03 +00:00
function App() {
const { PterodactylUser, SiteConfiguration } = window as ExtendedWindow;
2019-12-16 02:05:44 +00:00
if (PterodactylUser && !store.getState().user.data) {
store.getActions().user.setUserData({
2019-12-16 02:05:44 +00:00
uuid: PterodactylUser.uuid,
username: PterodactylUser.username,
email: PterodactylUser.email,
language: PterodactylUser.language,
rootAdmin: PterodactylUser.root_admin,
useTotp: PterodactylUser.use_totp,
createdAt: new Date(PterodactylUser.created_at),
updatedAt: new Date(PterodactylUser.updated_at),
});
}
2019-12-16 02:05:44 +00:00
if (!store.getState().settings.data) {
store.getActions().settings.setSettings(SiteConfiguration!);
}
return (
<>
2022-11-25 20:25:03 +00:00
{/* @ts-expect-error go away */}
<GlobalStylesheet />
2022-11-25 20:25:03 +00:00
<StoreProvider store={store}>
<ProgressBar />
2022-11-25 20:25:03 +00:00
<div className="mx-auto w-auto">
<BrowserRouter>
<Routes>
<Route
path="/auth/*"
element={
<Spinner.Suspense>
<AuthenticationRouter />
</Spinner.Suspense>
}
/>
<Route
path="/server/:id/*"
element={
<AuthenticatedRoute>
<Spinner.Suspense>
<ServerContext.Provider>
<ServerRouter />
</ServerContext.Provider>
</Spinner.Suspense>
</AuthenticatedRoute>
}
/>
<Route
path="/*"
element={
<AuthenticatedRoute>
<Spinner.Suspense>
<DashboardRouter />
</Spinner.Suspense>
</AuthenticatedRoute>
}
/>
<Route path="*" element={<NotFound />} />
</Routes>
</BrowserRouter>
2020-12-27 19:18:33 +00:00
</div>
</StoreProvider>
</>
);
2022-11-25 20:25:03 +00:00
}
2022-11-25 20:25:03 +00:00
export { App };