0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00
logto/packages/console/src/App.tsx

195 lines
7.7 KiB
TypeScript
Raw Normal View History

import { UserScope } from '@logto/core-kit';
2022-05-17 08:37:30 -05:00
import { LogtoProvider } from '@logto/react';
2023-02-10 00:06:52 -05:00
import { adminConsoleApplicationId } from '@logto/schemas';
import { useContext } from 'react';
2022-05-17 08:37:30 -05:00
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
import { SWRConfig } from 'swr';
import 'overlayscrollbars/styles/overlayscrollbars.css';
2022-02-27 21:35:14 -05:00
import './scss/normalized.scss';
import './scss/overlayscrollbars.scss';
// eslint-disable-next-line import/no-unassigned-import
import '@fontsource/roboto-mono';
import CloudApp from '@/cloud/App';
2023-02-10 00:06:52 -05:00
import AppLoading from '@/components/AppLoading';
import Toast from '@/components/Toast';
import { getManagementApi, meApi } from '@/consts/management-api';
import AppBoundary from '@/containers/AppBoundary';
import AppLayout from '@/containers/AppLayout';
import ErrorBoundary from '@/containers/ErrorBoundary';
import useSwrOptions from '@/hooks/use-swr-options';
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 AuditLogDetails from '@/pages/AuditLogDetails';
import AuditLogs from '@/pages/AuditLogs';
import Callback from '@/pages/Callback';
import ConnectorDetails from '@/pages/ConnectorDetails';
import Connectors from '@/pages/Connectors';
import Dashboard from '@/pages/Dashboard';
import GetStarted from '@/pages/GetStarted';
import NotFound from '@/pages/NotFound';
import RoleDetails from '@/pages/RoleDetails';
2023-01-05 03:22:45 -05:00
import Roles from '@/pages/Roles';
import Settings from '@/pages/Settings';
import SignInExperience from '@/pages/SignInExperience';
import UserDetails from '@/pages/UserDetails';
import Users from '@/pages/Users';
import Welcome from '@/pages/Welcome';
import {
ApiResourceDetailsTabs,
ConnectorsTabs,
RoleDetailsTabs,
SignInExperiencePage,
UserDetailsTabs,
adminTenantEndpoint,
2023-02-18 05:37:49 -05:00
getUserTenantId,
getBasename,
} from './consts';
import AppContent from './containers/AppContent';
import AppEndpointsProvider, { AppEndpointsContext } from './containers/AppEndpointsProvider';
import ApiResourcePermissions from './pages/ApiResourceDetails/ApiResourcePermissions';
import ApiResourceSettings from './pages/ApiResourceDetails/ApiResourceSettings';
import Profile from './pages/Profile';
import RolePermissions from './pages/RoleDetails/RolePermissions';
import RoleSettings from './pages/RoleDetails/RoleSettings';
2023-01-09 02:39:31 -05:00
import RoleUsers from './pages/RoleDetails/RoleUsers';
import UserLogs from './pages/UserDetails/UserLogs';
2023-01-09 02:34:22 -05:00
import UserRoles from './pages/UserDetails/UserRoles';
import UserSettings from './pages/UserDetails/UserSettings';
2022-02-28 09:18:01 -05:00
void initI18n();
const Main = () => {
const swrOptions = useSwrOptions();
const { userEndpoint } = useContext(AppEndpointsContext);
2023-02-10 00:06:52 -05:00
if (!userEndpoint) {
2023-02-10 00:06:52 -05:00
return <AppLoading />;
}
2022-02-27 21:35:14 -05:00
return (
<ErrorBoundary>
<SWRConfig value={swrOptions}>
<AppBoundary>
<Toast />
<Routes>
<Route path="callback" element={<Callback />} />
<Route path="welcome" element={<Welcome />} />
<Route element={<AppLayout />}>
<Route element={<AppContent />}>
<Route path="*" element={<NotFound />} />
<Route path="get-started" element={<GetStarted />} />
<Route path="dashboard" element={<Dashboard />} />
<Route path="applications">
<Route index element={<Applications />} />
<Route path="create" element={<Applications />} />
<Route path=":id" element={<ApplicationDetails />} />
</Route>
<Route path="api-resources">
<Route index element={<ApiResources />} />
<Route path="create" element={<ApiResources />} />
<Route path=":id" element={<ApiResourceDetails />}>
<Route
index
element={<Navigate replace to={ApiResourceDetailsTabs.Settings} />}
/>
<Route
path={ApiResourceDetailsTabs.Settings}
element={<ApiResourceSettings />}
/>
<Route
path={ApiResourceDetailsTabs.Permissions}
element={<ApiResourcePermissions />}
/>
</Route>
</Route>
<Route path="sign-in-experience">
<Route
index
element={<Navigate replace to={SignInExperiencePage.BrandingTab} />}
/>
<Route path=":tab" element={<SignInExperience />} />
</Route>
<Route path="connectors">
<Route index element={<Navigate replace to={ConnectorsTabs.Passwordless} />} />
<Route path=":tab" element={<Connectors />} />
<Route path=":tab/create/:createType" element={<Connectors />} />
<Route path=":tab/:connectorId" element={<ConnectorDetails />} />
</Route>
<Route path="users">
<Route index element={<Users />} />
<Route path="create" element={<Users />} />
<Route path=":id" element={<UserDetails />}>
<Route index element={<Navigate replace to={UserDetailsTabs.Settings} />} />
<Route path={UserDetailsTabs.Settings} element={<UserSettings />} />
<Route path={UserDetailsTabs.Roles} element={<UserRoles />} />
<Route path={UserDetailsTabs.Logs} element={<UserLogs />} />
</Route>
<Route
path={`:id/${UserDetailsTabs.Logs}/:logId`}
element={<AuditLogDetails />}
/>
</Route>
<Route path="audit-logs">
<Route index element={<AuditLogs />} />
<Route path=":logId" element={<AuditLogDetails />} />
</Route>
<Route path="roles">
<Route index element={<Roles />} />
<Route path="create" element={<Roles />} />
<Route path=":id" element={<RoleDetails />}>
<Route index element={<Navigate replace to={RoleDetailsTabs.Settings} />} />
<Route path={RoleDetailsTabs.Settings} element={<RoleSettings />} />
<Route path={RoleDetailsTabs.Permissions} element={<RolePermissions />} />
<Route path={RoleDetailsTabs.Users} element={<RoleUsers />} />
</Route>
</Route>
<Route path="settings" element={<Settings />} />
<Route path="profile" element={<Profile />} />
2023-01-05 03:22:45 -05:00
</Route>
</Route>
</Routes>
</AppBoundary>
</SWRConfig>
</ErrorBoundary>
2022-02-27 21:35:14 -05:00
);
};
const App = () => {
const tenantId = getUserTenantId();
if (!tenantId) {
return <CloudApp />;
}
const managementApi = getManagementApi(tenantId);
return (
<BrowserRouter basename={getBasename()}>
<AppEndpointsProvider>
<LogtoProvider
config={{
endpoint: adminTenantEndpoint,
appId: adminConsoleApplicationId,
resources: [managementApi.indicator, meApi.indicator],
scopes: [
UserScope.Email,
UserScope.Identities,
UserScope.CustomData,
managementApi.scopeAll,
],
}}
>
<Main />
</LogtoProvider>
</AppEndpointsProvider>
</BrowserRouter>
);
};
export default App;