0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00
logto/packages/console/src/App.tsx

72 lines
2.3 KiB
TypeScript
Raw Normal View History

import React, { useEffect } from 'react';
import { BrowserRouter, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
import { SWRConfig } from 'swr';
2022-02-27 21:35:14 -05:00
import './scss/normalized.scss';
import * as styles from './App.module.scss';
import AppContent from './components/AppContent';
2022-02-27 21:35:14 -05:00
import Content from './components/Content';
import Sidebar, { getPath, sections } from './components/Sidebar';
import Toast from './components/Toast';
2022-02-27 21:35:14 -05:00
import Topbar from './components/Topbar';
2022-02-28 09:18:01 -05:00
import initI18n from './i18n/init';
import ApiResourceDetails from './pages/ApiResourceDetails';
import ApiResources from './pages/ApiResources';
import ApplicationDetails from './pages/ApplicationDetails';
import Applications from './pages/Applications';
import ConnectorDetails from './pages/ConnectorDetails';
2022-03-07 22:10:46 -05:00
import Connectors from './pages/Connectors';
import { fetcher } from './swr';
2022-02-28 09:18:01 -05:00
const isBasenameNeeded = process.env.NODE_ENV !== 'development' || process.env.PORT === '5002';
2022-02-28 09:18:01 -05:00
void initI18n();
const Main = () => {
const location = useLocation();
const navigate = useNavigate();
useEffect(() => {
if (location.pathname === '/') {
navigate(getPath(sections[0]?.items[0]?.title ?? ''));
}
}, [location.pathname, navigate]);
2022-02-27 21:35:14 -05:00
return (
<SWRConfig value={{ fetcher }}>
<Toast />
<AppContent theme="light">
<Topbar />
<div className={styles.content}>
<Sidebar />
<Content>
<Routes>
<Route path="applications">
<Route index element={<Applications />} />
<Route path=":id" element={<ApplicationDetails />} />
</Route>
<Route path="api-resources">
<Route index element={<ApiResources />} />
<Route path=":id" element={<ApiResourceDetails />} />
</Route>
<Route path="connectors">
<Route index element={<Connectors />} />
<Route path="social" element={<Connectors />} />
<Route path=":connectorId" element={<ConnectorDetails />} />
</Route>
</Routes>
</Content>
</div>
</AppContent>
</SWRConfig>
2022-02-27 21:35:14 -05:00
);
};
const App = () => (
<BrowserRouter basename={isBasenameNeeded ? '/console' : ''}>
<Main />
</BrowserRouter>
);
export default App;