2023-04-20 05:15:05 -05:00
|
|
|
import { AppInsightsProvider, getPrimaryDomain, useAppInsights } from '@logto/app-insights/react';
|
2022-09-17 00:35:10 -05:00
|
|
|
import { UserScope } from '@logto/core-kit';
|
2022-05-17 08:37:30 -05:00
|
|
|
import { LogtoProvider } from '@logto/react';
|
2023-02-28 03:04:12 -05:00
|
|
|
import { adminConsoleApplicationId, PredefinedScope } from '@logto/schemas';
|
2023-03-04 01:52:02 -05:00
|
|
|
import { conditionalArray, deduplicate } from '@silverhand/essentials';
|
2023-04-24 08:00:53 -05:00
|
|
|
import { useContext, useEffect, useMemo } from 'react';
|
2023-03-28 12:51:14 -05:00
|
|
|
import { Helmet } from 'react-helmet';
|
2022-06-07 08:33:53 -05:00
|
|
|
|
2023-01-30 22:47:30 -05:00
|
|
|
import 'overlayscrollbars/styles/overlayscrollbars.css';
|
2022-02-27 21:35:14 -05:00
|
|
|
import './scss/normalized.scss';
|
2023-01-30 22:47:30 -05:00
|
|
|
import './scss/overlayscrollbars.scss';
|
|
|
|
|
2022-05-14 07:51:55 -05:00
|
|
|
// eslint-disable-next-line import/no-unassigned-import
|
|
|
|
import '@fontsource/roboto-mono';
|
2023-03-01 10:46:30 -05:00
|
|
|
|
2023-02-23 11:27:51 -05:00
|
|
|
import CloudApp from '@/cloud/App';
|
2023-02-28 03:04:12 -05:00
|
|
|
import { cloudApi, getManagementApi, meApi } from '@/consts/resources';
|
2022-06-07 08:33:53 -05:00
|
|
|
import initI18n from '@/i18n/init';
|
2022-03-03 02:44:42 -05:00
|
|
|
|
2023-03-28 12:51:14 -05:00
|
|
|
import { adminTenantEndpoint, mainTitle } from './consts';
|
2023-02-28 03:04:12 -05:00
|
|
|
import { isCloud } from './consts/cloud';
|
2023-03-01 23:11:08 -05:00
|
|
|
import ErrorBoundary from './containers/ErrorBoundary';
|
2023-03-09 20:57:30 -05:00
|
|
|
import TenantAppContainer from './containers/TenantAppContainer';
|
2023-03-01 05:24:39 -05:00
|
|
|
import AppConfirmModalProvider from './contexts/AppConfirmModalProvider';
|
2023-02-28 03:04:12 -05:00
|
|
|
import AppEndpointsProvider from './contexts/AppEndpointsProvider';
|
2023-03-19 11:15:00 -05:00
|
|
|
import { AppThemeProvider } from './contexts/AppThemeProvider';
|
2023-02-28 03:04:12 -05:00
|
|
|
import TenantsProvider, { TenantsContext } from './contexts/TenantsProvider';
|
2022-09-17 00:35:10 -05:00
|
|
|
|
2022-02-28 09:18:01 -05:00
|
|
|
void initI18n();
|
2022-02-16 02:04:34 -05:00
|
|
|
|
2023-03-22 03:45:10 -05:00
|
|
|
function Content() {
|
2023-03-01 10:46:30 -05:00
|
|
|
const { tenants, isSettle, currentTenantId } = useContext(TenantsContext);
|
2023-04-20 05:15:05 -05:00
|
|
|
const { setup } = useAppInsights();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
void setup('console', { cookieDomain: getPrimaryDomain() });
|
|
|
|
}, [setup]);
|
2023-02-10 00:06:52 -05:00
|
|
|
|
2023-04-24 08:00:53 -05: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,
|
|
|
|
...(tenants ?? []).map(({ id }) => getManagementApi(id).indicator),
|
|
|
|
isCloud && cloudApi.indicator,
|
|
|
|
meApi.indicator
|
|
|
|
)
|
|
|
|
),
|
|
|
|
[currentTenantId, tenants]
|
2023-03-04 01:52:02 -05:00
|
|
|
);
|
2023-03-09 20:57:30 -05:00
|
|
|
|
2023-04-24 08:00:53 -05:00
|
|
|
const scopes = useMemo(
|
|
|
|
() => [
|
|
|
|
UserScope.Email,
|
|
|
|
UserScope.Identities,
|
|
|
|
UserScope.CustomData,
|
|
|
|
PredefinedScope.All,
|
|
|
|
...conditionalArray(
|
|
|
|
isCloud && cloudApi.scopes.CreateTenant,
|
|
|
|
isCloud && cloudApi.scopes.ManageTenant
|
|
|
|
),
|
|
|
|
],
|
|
|
|
[]
|
|
|
|
);
|
2022-05-05 05:42:10 -05:00
|
|
|
|
2022-02-27 21:35:14 -05:00
|
|
|
return (
|
2023-02-28 03:04:12 -05:00
|
|
|
<LogtoProvider
|
|
|
|
config={{
|
2023-03-06 23:38:26 -05:00
|
|
|
endpoint: adminTenantEndpoint.href,
|
2023-02-28 03:04:12 -05:00
|
|
|
appId: adminConsoleApplicationId,
|
|
|
|
resources,
|
|
|
|
scopes,
|
|
|
|
}}
|
|
|
|
>
|
2023-03-19 11:15:00 -05:00
|
|
|
<AppThemeProvider>
|
2023-03-28 12:51:14 -05:00
|
|
|
<Helmet titleTemplate={`%s - ${mainTitle}`} defaultTitle={mainTitle} />
|
2023-03-19 11:15:00 -05:00
|
|
|
<ErrorBoundary>
|
|
|
|
{!isCloud || isSettle ? (
|
|
|
|
<AppEndpointsProvider>
|
|
|
|
<AppConfirmModalProvider>
|
|
|
|
<TenantAppContainer />
|
|
|
|
</AppConfirmModalProvider>
|
|
|
|
</AppEndpointsProvider>
|
|
|
|
) : (
|
|
|
|
<CloudApp />
|
|
|
|
)}
|
|
|
|
</ErrorBoundary>
|
|
|
|
</AppThemeProvider>
|
2023-02-28 03:04:12 -05:00
|
|
|
</LogtoProvider>
|
2022-02-27 21:35:14 -05:00
|
|
|
);
|
2023-03-22 03:45:10 -05:00
|
|
|
}
|
2022-03-03 02:02:30 -05:00
|
|
|
|
2023-03-22 03:45:10 -05:00
|
|
|
function App() {
|
2023-02-22 09:35:17 -05:00
|
|
|
return (
|
2023-04-20 05:15:05 -05:00
|
|
|
<AppInsightsProvider>
|
|
|
|
<TenantsProvider>
|
|
|
|
<Content />
|
|
|
|
</TenantsProvider>
|
|
|
|
</AppInsightsProvider>
|
2023-02-22 09:35:17 -05:00
|
|
|
);
|
2023-03-22 03:45:10 -05:00
|
|
|
}
|
2023-03-09 20:57:30 -05:00
|
|
|
|
2022-03-03 02:02:30 -05:00
|
|
|
export default App;
|