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-02-10 13:06:52 +08:00
|
|
|
import { useContext } from 'react';
|
2022-06-07 21:33:53 +08:00
|
|
|
|
2023-01-31 11:47:30 +08:00
|
|
|
import 'overlayscrollbars/styles/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-06-07 21:33:53 +08:00
|
|
|
import initI18n from '@/i18n/init';
|
2022-03-03 15:44:42 +08:00
|
|
|
|
2023-03-01 23:46:30 +08:00
|
|
|
import { adminTenantEndpoint } from './consts';
|
2023-02-28 16:04:12 +08:00
|
|
|
import { isCloud } from './consts/cloud';
|
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-03-20 15:28:58 +08:00
|
|
|
import setTitle from './utils/set-title';
|
2022-09-17 13:35:10 +08:00
|
|
|
|
2022-02-28 22:18:01 +08:00
|
|
|
void initI18n();
|
2023-03-20 15:28:58 +08:00
|
|
|
setTitle();
|
2022-02-16 15:04:34 +08:00
|
|
|
|
2023-02-28 16:04:12 +08:00
|
|
|
const Content = () => {
|
2023-03-01 23:46:30 +08:00
|
|
|
const { tenants, isSettle, currentTenantId } = useContext(TenantsContext);
|
2023-02-10 13:06:52 +08:00
|
|
|
|
2023-03-04 14:52:02 +08: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
|
|
|
|
)
|
|
|
|
);
|
2023-03-10 09:57:30 +08:00
|
|
|
|
2023-02-28 16:04:12 +08:00
|
|
|
const scopes = [
|
|
|
|
UserScope.Email,
|
|
|
|
UserScope.Identities,
|
|
|
|
UserScope.CustomData,
|
|
|
|
PredefinedScope.All,
|
2023-03-04 14:52:02 +08:00
|
|
|
...conditionalArray(
|
|
|
|
isCloud && cloudApi.scopes.CreateTenant,
|
|
|
|
isCloud && cloudApi.scopes.ManageTenant
|
|
|
|
),
|
2023-02-28 16:04:12 +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
|
|
|
|
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>
|
|
|
|
<ErrorBoundary>
|
|
|
|
{!isCloud || isSettle ? (
|
|
|
|
<AppEndpointsProvider>
|
|
|
|
<AppConfirmModalProvider>
|
|
|
|
<TenantAppContainer />
|
|
|
|
</AppConfirmModalProvider>
|
|
|
|
</AppEndpointsProvider>
|
|
|
|
) : (
|
|
|
|
<CloudApp />
|
|
|
|
)}
|
|
|
|
</ErrorBoundary>
|
|
|
|
</AppThemeProvider>
|
2023-02-28 16:04:12 +08:00
|
|
|
</LogtoProvider>
|
2022-02-28 10:35:14 +08:00
|
|
|
);
|
2022-02-16 15:04:34 +08:00
|
|
|
};
|
2022-03-03 15:02:30 +08:00
|
|
|
|
2023-02-22 22:35:17 +08:00
|
|
|
const App = () => {
|
|
|
|
return (
|
2023-03-04 14:52:02 +08:00
|
|
|
<TenantsProvider>
|
|
|
|
<Content />
|
|
|
|
</TenantsProvider>
|
2023-02-22 22:35:17 +08:00
|
|
|
);
|
|
|
|
};
|
2023-03-10 09:57:30 +08:00
|
|
|
|
2022-03-03 15:02:30 +08:00
|
|
|
export default App;
|