2022-02-13 17:55:02 +00:00
|
|
|
import React, { lazy, Suspense } from 'react';
|
2019-06-10 00:29:10 +00:00
|
|
|
import { hot } from 'react-hot-loader/root';
|
2022-02-05 17:08:43 +00:00
|
|
|
import { Route, Router, Switch } from 'react-router-dom';
|
2019-06-22 23:45:51 +00:00
|
|
|
import { StoreProvider } from 'easy-peasy';
|
|
|
|
import { store } from '@/state';
|
2019-06-26 04:28:56 +00:00
|
|
|
import DashboardRouter from '@/routers/DashboardRouter';
|
2019-06-29 05:17:29 +00:00
|
|
|
import ServerRouter from '@/routers/ServerRouter';
|
|
|
|
import AuthenticationRouter from '@/routers/AuthenticationRouter';
|
2019-12-16 02:05:44 +00:00
|
|
|
import { SiteSettings } from '@/state/settings';
|
2020-04-10 19:41:08 +00:00
|
|
|
import ProgressBar from '@/components/elements/ProgressBar';
|
2021-01-31 02:01:32 +00:00
|
|
|
import { NotFound } from '@/components/elements/ScreenBlock';
|
2021-01-29 16:07:15 +00:00
|
|
|
import tw from 'twin.macro';
|
2020-12-28 18:10:01 +00:00
|
|
|
import { history } from '@/components/history';
|
2020-12-28 04:57:31 +00:00
|
|
|
import { setupInterceptors } from '@/api/interceptors';
|
2021-07-13 21:58:44 +00:00
|
|
|
import GlobalStyles from '@/components/GlobalStyles';
|
2021-10-03 23:10:06 +00:00
|
|
|
import Spinner from '@/components/elements/Spinner';
|
2020-08-22 23:25:47 +00:00
|
|
|
|
2021-05-19 02:53:42 +00:00
|
|
|
const ChunkedAdminRouter = lazy(() => import(/* webpackChunkName: "admin" */'@/routers/AdminRouter'));
|
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;
|
2021-01-07 17:21:09 +00:00
|
|
|
avatar_url: string;
|
|
|
|
role_name: string;
|
2019-06-23 00:07:28 +00:00
|
|
|
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
|
|
|
|
2020-12-28 04:57:31 +00:00
|
|
|
setupInterceptors(history);
|
|
|
|
|
2019-06-23 00:07:28 +00:00
|
|
|
const App = () => {
|
2019-12-16 02:05:44 +00:00
|
|
|
const { PterodactylUser, SiteConfiguration } = (window as ExtendedWindow);
|
|
|
|
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,
|
2021-01-07 17:21:09 +00:00
|
|
|
avatarURL: PterodactylUser.avatar_url,
|
|
|
|
roleName: PterodactylUser.role_name,
|
2019-12-16 02:05:44 +00:00
|
|
|
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
|
|
|
<>
|
2021-07-13 21:58:44 +00:00
|
|
|
<GlobalStyles/>
|
2020-07-03 21:50:37 +00:00
|
|
|
<StoreProvider store={store}>
|
2020-12-28 04:57:31 +00:00
|
|
|
<ProgressBar/>
|
|
|
|
<div css={tw`mx-auto w-auto`}>
|
|
|
|
<Router history={history}>
|
2021-10-03 23:10:06 +00:00
|
|
|
<Suspense fallback={<Spinner centered/>}>
|
2020-12-28 04:57:31 +00:00
|
|
|
<Switch>
|
|
|
|
<Route path="/server/:id" component={ServerRouter}/>
|
|
|
|
<Route path="/auth" component={AuthenticationRouter}/>
|
2021-05-19 02:53:42 +00:00
|
|
|
<Route path="/admin" component={ChunkedAdminRouter}/>
|
2020-12-28 04:57:31 +00:00
|
|
|
<Route path="/" component={DashboardRouter}/>
|
|
|
|
<Route path={'*'} component={NotFound}/>
|
|
|
|
</Switch>
|
|
|
|
</Suspense>
|
|
|
|
</Router>
|
|
|
|
</div>
|
2020-07-03 21:50:37 +00:00
|
|
|
</StoreProvider>
|
|
|
|
</>
|
2019-06-23 00:07:28 +00:00
|
|
|
);
|
|
|
|
};
|
2019-06-10 00:29:10 +00:00
|
|
|
|
|
|
|
export default hot(App);
|