2023-04-27 18:34:38 +08:00
|
|
|
import { AppInsightsBoundary } from '@logto/app-insights/react';
|
2022-09-17 13:35:10 +08:00
|
|
|
import { UserScope } from '@logto/core-kit';
|
2022-05-17 21:37:30 +08:00
|
|
|
import { LogtoProvider } from '@logto/react';
|
2023-02-28 16:04:12 +08:00
|
|
|
import { adminConsoleApplicationId, PredefinedScope } from '@logto/schemas';
|
2023-03-04 14:52:02 +08:00
|
|
|
import { conditionalArray, deduplicate } from '@silverhand/essentials';
|
2023-04-27 18:34:38 +08:00
|
|
|
import { useContext, useMemo } from 'react';
|
2023-03-29 01:51:14 +08:00
|
|
|
import { Helmet } from 'react-helmet';
|
2022-06-07 21:33:53 +08:00
|
|
|
|
2023-06-10 16:21:12 +08:00
|
|
|
import 'overlayscrollbars/overlayscrollbars.css';
|
2022-02-28 10:35:14 +08:00
|
|
|
import './scss/normalized.scss';
|
2023-01-31 11:47:30 +08:00
|
|
|
import './scss/overlayscrollbars.scss';
|
|
|
|
|
2022-05-14 20:51:55 +08:00
|
|
|
// eslint-disable-next-line import/no-unassigned-import
|
|
|
|
import '@fontsource/roboto-mono';
|
2023-03-01 23:46:30 +08:00
|
|
|
|
2023-02-24 00:27:51 +08:00
|
|
|
import CloudApp from '@/cloud/App';
|
2023-02-28 16:04:12 +08:00
|
|
|
import { cloudApi, getManagementApi, meApi } from '@/consts/resources';
|
2022-03-03 15:44:42 +08:00
|
|
|
|
2023-03-29 01:51:14 +08:00
|
|
|
import { adminTenantEndpoint, mainTitle } from './consts';
|
2023-06-08 10:57:02 +08:00
|
|
|
import { isCloud } from './consts/env';
|
2023-03-02 12:11:08 +08:00
|
|
|
import ErrorBoundary from './containers/ErrorBoundary';
|
2023-03-10 09:57:30 +08:00
|
|
|
import TenantAppContainer from './containers/TenantAppContainer';
|
2023-03-01 18:24:39 +08:00
|
|
|
import AppConfirmModalProvider from './contexts/AppConfirmModalProvider';
|
2023-02-28 16:04:12 +08:00
|
|
|
import AppEndpointsProvider from './contexts/AppEndpointsProvider';
|
2023-03-20 00:15:00 +08:00
|
|
|
import { AppThemeProvider } from './contexts/AppThemeProvider';
|
2023-02-28 16:04:12 +08:00
|
|
|
import TenantsProvider, { TenantsContext } from './contexts/TenantsProvider';
|
2023-06-24 17:23:41 +08:00
|
|
|
import initI18n from './i18n/init';
|
2022-09-17 13:35:10 +08:00
|
|
|
|
2022-02-28 22:18:01 +08:00
|
|
|
void initI18n();
|
2022-02-16 15:04:34 +08:00
|
|
|
|
2023-03-22 16:45:10 +08:00
|
|
|
function Content() {
|
2023-06-24 17:23:41 +08:00
|
|
|
const { tenants, currentTenantId } = useContext(TenantsContext);
|
2023-02-10 13:06:52 +08:00
|
|
|
|
2023-04-24 21:00:53 +08:00
|
|
|
const resources = useMemo(
|
|
|
|
() =>
|
|
|
|
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,
|
2023-06-22 15:13:49 +08:00
|
|
|
...tenants.map(({ id }) => getManagementApi(id).indicator),
|
2023-04-24 21:00:53 +08:00
|
|
|
isCloud && cloudApi.indicator,
|
|
|
|
meApi.indicator
|
|
|
|
)
|
|
|
|
),
|
|
|
|
[currentTenantId, tenants]
|
2023-03-04 14:52:02 +08:00
|
|
|
);
|
2023-03-10 09:57:30 +08:00
|
|
|
|
2023-04-24 21:00:53 +08:00
|
|
|
const scopes = useMemo(
|
|
|
|
() => [
|
|
|
|
UserScope.Email,
|
|
|
|
UserScope.Identities,
|
|
|
|
UserScope.CustomData,
|
|
|
|
PredefinedScope.All,
|
|
|
|
...conditionalArray(
|
|
|
|
isCloud && cloudApi.scopes.CreateTenant,
|
2023-05-26 17:38:09 +08:00
|
|
|
isCloud && cloudApi.scopes.ManageTenant,
|
|
|
|
isCloud && cloudApi.scopes.ManageTenantSelf
|
2023-04-24 21:00:53 +08:00
|
|
|
),
|
|
|
|
],
|
|
|
|
[]
|
|
|
|
);
|
2022-05-05 18:42:10 +08:00
|
|
|
|
2022-02-28 10:35:14 +08:00
|
|
|
return (
|
2023-02-28 16:04:12 +08:00
|
|
|
<LogtoProvider
|
2023-06-21 08:35:45 +08:00
|
|
|
unstable_enableCache
|
2023-02-28 16:04:12 +08:00
|
|
|
config={{
|
2023-03-07 12:38:26 +08:00
|
|
|
endpoint: adminTenantEndpoint.href,
|
2023-02-28 16:04:12 +08:00
|
|
|
appId: adminConsoleApplicationId,
|
|
|
|
resources,
|
|
|
|
scopes,
|
|
|
|
}}
|
|
|
|
>
|
2023-03-20 00:15:00 +08:00
|
|
|
<AppThemeProvider>
|
2023-04-29 12:02:52 +08:00
|
|
|
<AppInsightsBoundary cloudRole="console">
|
2023-04-27 18:34:38 +08:00
|
|
|
<Helmet titleTemplate={`%s - ${mainTitle}`} defaultTitle={mainTitle} />
|
|
|
|
<ErrorBoundary>
|
2023-06-22 15:13:49 +08:00
|
|
|
{/**
|
|
|
|
* If it's not Cloud (OSS), render the tenant app container directly since only default tenant is available;
|
|
|
|
* if it's Cloud, render the tenant app container only when init is complete and a tenant ID is available (in a tenant context).
|
|
|
|
*/}
|
2023-06-24 17:23:41 +08:00
|
|
|
{!isCloud || currentTenantId ? (
|
2023-04-27 18:34:38 +08:00
|
|
|
<AppEndpointsProvider>
|
|
|
|
<AppConfirmModalProvider>
|
|
|
|
<TenantAppContainer />
|
|
|
|
</AppConfirmModalProvider>
|
|
|
|
</AppEndpointsProvider>
|
|
|
|
) : (
|
|
|
|
<CloudApp />
|
|
|
|
)}
|
|
|
|
</ErrorBoundary>
|
|
|
|
</AppInsightsBoundary>
|
2023-03-20 00:15:00 +08:00
|
|
|
</AppThemeProvider>
|
2023-02-28 16:04:12 +08:00
|
|
|
</LogtoProvider>
|
2022-02-28 10:35:14 +08:00
|
|
|
);
|
2023-03-22 16:45:10 +08:00
|
|
|
}
|
2022-03-03 15:02:30 +08:00
|
|
|
|
2023-03-22 16:45:10 +08:00
|
|
|
function App() {
|
2023-02-22 22:35:17 +08:00
|
|
|
return (
|
2023-04-27 18:34:38 +08:00
|
|
|
<TenantsProvider>
|
|
|
|
<Content />
|
|
|
|
</TenantsProvider>
|
2023-02-22 22:35:17 +08:00
|
|
|
);
|
2023-03-22 16:45:10 +08:00
|
|
|
}
|
2023-03-10 09:57:30 +08:00
|
|
|
|
2022-03-03 15:02:30 +08:00
|
|
|
export default App;
|