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

100 lines
3.1 KiB
TypeScript
Raw Normal View History

import { AppInsightsProvider, getPrimaryDomain, useAppInsights } from '@logto/app-insights/react';
import { UserScope } from '@logto/core-kit';
2022-05-17 08:37:30 -05:00
import { LogtoProvider } from '@logto/react';
import { adminConsoleApplicationId, PredefinedScope } from '@logto/schemas';
import { conditionalArray, deduplicate } from '@silverhand/essentials';
import { useContext, useEffect } from 'react';
import { Helmet } from 'react-helmet';
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';
2023-03-01 10:46:30 -05:00
import CloudApp from '@/cloud/App';
import { cloudApi, getManagementApi, meApi } from '@/consts/resources';
import initI18n from '@/i18n/init';
import { adminTenantEndpoint, mainTitle } from './consts';
import { isCloud } from './consts/cloud';
import ErrorBoundary from './containers/ErrorBoundary';
import TenantAppContainer from './containers/TenantAppContainer';
import AppConfirmModalProvider from './contexts/AppConfirmModalProvider';
import AppEndpointsProvider from './contexts/AppEndpointsProvider';
import { AppThemeProvider } from './contexts/AppThemeProvider';
import TenantsProvider, { TenantsContext } from './contexts/TenantsProvider';
2022-02-28 09:18:01 -05:00
void initI18n();
function Content() {
2023-03-01 10:46:30 -05:00
const { tenants, isSettle, currentTenantId } = useContext(TenantsContext);
const { setup } = useAppInsights();
useEffect(() => {
void setup('console', { cookieDomain: getPrimaryDomain() });
}, [setup]);
2023-02-10 00:06:52 -05:00
const resources = deduplicate(
conditionalArray(
// Explicitly add `currentTenantId` and deduplicate since the user may directly
// access a URL with Tenant ID, adding the ID from the URL here can possibly remove one
// additional redirect.
currentTenantId && getManagementApi(currentTenantId).indicator,
...(tenants ?? []).map(({ id }) => getManagementApi(id).indicator),
isCloud && cloudApi.indicator,
meApi.indicator
)
);
const scopes = [
UserScope.Email,
UserScope.Identities,
UserScope.CustomData,
PredefinedScope.All,
...conditionalArray(
isCloud && cloudApi.scopes.CreateTenant,
isCloud && cloudApi.scopes.ManageTenant
),
];
2022-02-27 21:35:14 -05:00
return (
<LogtoProvider
config={{
2023-03-06 23:38:26 -05:00
endpoint: adminTenantEndpoint.href,
appId: adminConsoleApplicationId,
resources,
scopes,
}}
>
<AppThemeProvider>
<Helmet titleTemplate={`%s - ${mainTitle}`} defaultTitle={mainTitle} />
<ErrorBoundary>
{!isCloud || isSettle ? (
<AppEndpointsProvider>
<AppConfirmModalProvider>
<TenantAppContainer />
</AppConfirmModalProvider>
</AppEndpointsProvider>
) : (
<CloudApp />
)}
</ErrorBoundary>
</AppThemeProvider>
</LogtoProvider>
2022-02-27 21:35:14 -05:00
);
}
function App() {
return (
<AppInsightsProvider>
<TenantsProvider>
<Content />
</TenantsProvider>
</AppInsightsProvider>
);
}
export default App;