2019-06-22 23:45:51 +00:00
|
|
|
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';
|
2020-07-03 21:50:37 +00:00
|
|
|
import GlobalStylesheet from '@/assets/css/GlobalStylesheet';
|
2022-05-28 17:32:35 +00:00
|
|
|
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';
|
2022-06-12 15:56:00 +00:00
|
|
|
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-12-16 02:06:14 +00:00
|
|
|
import { AdminContext } from '@/state/admin';
|
2022-06-12 15:56:00 +00:00
|
|
|
|
2022-12-16 02:06:14 +00:00
|
|
|
const AdminRouter = lazy(() => import('@/routers/AdminRouter'));
|
|
|
|
const AuthenticationRouter = lazy(() => import('@/routers/AuthenticationRouter'));
|
2022-11-25 20:25:03 +00:00
|
|
|
const DashboardRouter = lazy(() => import('@/routers/DashboardRouter'));
|
|
|
|
const ServerRouter = lazy(() => import('@/routers/ServerRouter'));
|
2019-06-10 00:29:10 +00:00
|
|
|
|
2019-12-16 02:05:44 +00:00
|
|
|
interface ExtendedWindow extends Window {
|
|
|
|
SiteConfiguration?: SiteSettings;
|
2019-06-23 00:07:28 +00:00
|
|
|
PterodactylUser?: {
|
|
|
|
uuid: string;
|
|
|
|
username: string;
|
|
|
|
email: string;
|
2020-07-03 20:55:33 +00:00
|
|
|
/* eslint-disable camelcase */
|
2019-06-23 00:07:28 +00:00
|
|
|
root_admin: boolean;
|
|
|
|
use_totp: boolean;
|
|
|
|
language: string;
|
|
|
|
updated_at: string;
|
|
|
|
created_at: string;
|
2020-07-03 20:55:33 +00:00
|
|
|
/* eslint-enable camelcase */
|
2019-06-23 00:07:28 +00:00
|
|
|
};
|
|
|
|
}
|
2019-06-22 23:45:51 +00:00
|
|
|
|
2022-11-25 20:25:03 +00:00
|
|
|
// setupInterceptors(history);
|
2020-12-06 21:56:14 +00:00
|
|
|
|
2022-11-25 20:25:03 +00:00
|
|
|
function App() {
|
2022-06-26 19:13:52 +00:00
|
|
|
const { PterodactylUser, SiteConfiguration } = window as ExtendedWindow;
|
2019-12-16 02:05:44 +00:00
|
|
|
if (PterodactylUser && !store.getState().user.data) {
|
2019-06-23 00:07:28 +00:00
|
|
|
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-06-23 00:07:28 +00:00
|
|
|
});
|
2019-06-12 06:12:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-16 02:05:44 +00:00
|
|
|
if (!store.getState().settings.data) {
|
|
|
|
store.getActions().settings.setSettings(SiteConfiguration!);
|
|
|
|
}
|
|
|
|
|
2019-06-23 00:07:28 +00:00
|
|
|
return (
|
2020-07-03 21:50:37 +00:00
|
|
|
<>
|
2022-11-25 20:25:03 +00:00
|
|
|
{/* @ts-expect-error go away */}
|
2022-06-26 19:13:52 +00:00
|
|
|
<GlobalStylesheet />
|
2022-11-25 20:25:03 +00:00
|
|
|
|
2020-07-03 21:50:37 +00:00
|
|
|
<StoreProvider store={store}>
|
2022-06-26 19:13:52 +00:00
|
|
|
<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>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
|
2022-12-16 02:06:14 +00:00
|
|
|
<Route
|
|
|
|
path="/admin/*"
|
|
|
|
element={
|
|
|
|
<Spinner.Suspense>
|
|
|
|
<AdminContext.Provider>
|
|
|
|
<AdminRouter />
|
|
|
|
</AdminContext.Provider>
|
|
|
|
</Spinner.Suspense>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
|
2022-11-25 20:25:03 +00:00
|
|
|
<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>
|
2020-07-03 21:50:37 +00:00
|
|
|
</StoreProvider>
|
|
|
|
</>
|
2019-06-23 00:07:28 +00:00
|
|
|
);
|
2022-11-25 20:25:03 +00:00
|
|
|
}
|
2019-06-10 00:29:10 +00:00
|
|
|
|
2022-11-25 20:25:03 +00:00
|
|
|
export { App };
|