asb_cloud_front/src/App.tsx

60 lines
2.5 KiB
TypeScript
Raw Normal View History

import { BrowserRouter as Router, Navigate, Route, Routes } from 'react-router-dom'
import { lazy, memo, Suspense } from 'react'
import locale from 'antd/lib/locale/ru_RU'
import { ConfigProvider } from 'antd'
import { RootPathContext } from '@asb/context'
import { UserOutlet } from '@components/outlets'
import SuspenseFallback from '@components/SuspenseFallback'
import { getUserToken, NoAccessComponent } from '@utils'
import { OpenAPI } from '@api'
import '@styles/include/antd_theme.less'
import '@styles/App.less'
const Login = lazy(() => import('@pages/public/Login'))
const Register = lazy(() => import('@pages/public/Register'))
const FileDownload = lazy(() => import('@pages/FileDownload'))
const AdminPanel = lazy(() => import('@pages/AdminPanel'))
const Deposit = lazy(() => import('@pages/Deposit'))
const Cluster = lazy(() => import('@pages/Cluster'))
const Well = lazy(() => import('@asb/pages/Well'))
2021-07-26 14:40:35 +05:00
//OpenAPI.BASE = 'http://localhost:3000'
OpenAPI.TOKEN = async () => getUserToken() ?? ''
OpenAPI.HEADERS = { 'Content-Type': 'application/json' }
2021-04-02 17:22:34 +05:00
export const App = memo(() => (
<ConfigProvider locale={locale}>
<RootPathContext.Provider value={''}>
<Suspense fallback={<SuspenseFallback style={{ minHeight: '100vh' }} />}>
<Router>
<Routes>
<Route index element={<Navigate to={'deposit'} replace />} />
<Route path={'*'} element={<NoAccessComponent />} />
{/* Public pages */}
<Route path={'/login'} element={<Login />} />
<Route path={'/register'} element={<Register />} />
{/* User pages */}
<Route element={<UserOutlet />}>
{/* Admin pages */}
<Route path={'/admin/*'} element={<AdminPanel />} />
{/* Client pages */}
<Route path={'/file_download/:idWell/:idFile/*'} element={<FileDownload />} />
<Route path={'/deposit/*'} element={<Deposit />} />
<Route path={'/cluster/:idCluster'} element={<Cluster />} />
<Route path={'/well/:idWell/*'} element={<Well />} />
</Route>
</Routes>
</Router>
</Suspense>
</RootPathContext.Provider>
</ConfigProvider>
))
export default App