2023-08-31 16:11:47 +00:00
|
|
|
import { BrowserRouter, Route, Routes, Navigate } from 'react-router-dom';
|
|
|
|
import { Layout } from './pages/Layout';
|
|
|
|
import { Dashboard } from './pages/Dashboard';
|
|
|
|
import { Login } from './pages/Login';
|
|
|
|
import { Monitor } from './pages/Monitor';
|
|
|
|
import { Website } from './pages/Website';
|
2023-09-20 15:11:03 +00:00
|
|
|
import { SettingsPage } from './pages/Settings';
|
2023-08-31 16:11:47 +00:00
|
|
|
import { Servers } from './pages/Servers';
|
2023-09-03 13:05:22 +00:00
|
|
|
import { useUserStore } from './store/user';
|
|
|
|
import { Register } from './pages/Register';
|
2023-09-04 17:18:43 +00:00
|
|
|
import { QueryClientProvider } from '@tanstack/react-query';
|
|
|
|
import { queryClient } from './api/cache';
|
2023-09-05 07:32:16 +00:00
|
|
|
import { TokenLoginContainer } from './components/TokenLoginContainer';
|
|
|
|
import React from 'react';
|
2023-09-27 09:56:32 +00:00
|
|
|
import { trpc, trpcClient } from './api/trpc';
|
2023-09-05 07:32:16 +00:00
|
|
|
|
|
|
|
export const AppRoutes: React.FC = React.memo(() => {
|
2023-09-03 13:05:22 +00:00
|
|
|
const { info } = useUserStore();
|
|
|
|
|
2023-09-05 07:32:16 +00:00
|
|
|
return (
|
|
|
|
<Routes>
|
|
|
|
{info ? (
|
|
|
|
<Route element={<Layout />}>
|
|
|
|
<Route path="/dashboard" element={<Dashboard />} />
|
|
|
|
<Route path="/monitor" element={<Monitor />} />
|
|
|
|
<Route path="/website" element={<Website />} />
|
|
|
|
<Route path="/servers" element={<Servers />} />
|
2023-09-20 15:11:03 +00:00
|
|
|
<Route path="/settings/*" element={<SettingsPage />} />
|
2023-09-05 07:32:16 +00:00
|
|
|
</Route>
|
|
|
|
) : (
|
|
|
|
<Route>
|
|
|
|
<Route path="/login" element={<Login />} />
|
|
|
|
<Route path="/register" element={<Register />} />
|
|
|
|
</Route>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<Route
|
|
|
|
path="*"
|
|
|
|
element={
|
|
|
|
<Navigate to={info ? '/dashboard' : '/login'} replace={true} />
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Routes>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
AppRoutes.displayName = 'AppRoutes';
|
|
|
|
|
|
|
|
export const App: React.FC = React.memo(() => {
|
2023-08-31 13:17:57 +00:00
|
|
|
return (
|
|
|
|
<div className="App">
|
2023-09-27 09:56:32 +00:00
|
|
|
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<BrowserRouter>
|
|
|
|
<TokenLoginContainer>
|
|
|
|
<AppRoutes />
|
|
|
|
</TokenLoginContainer>
|
|
|
|
</BrowserRouter>
|
|
|
|
</QueryClientProvider>
|
|
|
|
</trpc.Provider>
|
2023-08-31 13:17:57 +00:00
|
|
|
</div>
|
|
|
|
);
|
2023-09-05 07:32:16 +00:00
|
|
|
});
|
|
|
|
App.displayName = 'App';
|