2024-05-08 08:23:43 +00:00
|
|
|
import KeycloakAdminClient from "@keycloak/keycloak-admin-client";
|
|
|
|
import {
|
|
|
|
mainPageContentId,
|
|
|
|
useEnvironment,
|
|
|
|
} from "@keycloak/keycloak-ui-shared";
|
2024-06-06 06:36:46 +00:00
|
|
|
import { Page } from "@patternfly/react-core";
|
|
|
|
import { PropsWithChildren, Suspense, useEffect, useState } from "react";
|
|
|
|
import { Outlet } from "react-router-dom";
|
|
|
|
|
2023-03-27 16:34:53 +00:00
|
|
|
import { Header } from "./PageHeader";
|
|
|
|
import { PageNav } from "./PageNav";
|
2024-05-08 08:23:43 +00:00
|
|
|
import { AdminClientContext, initAdminClient } from "./admin-client";
|
2020-10-06 19:25:05 +00:00
|
|
|
import { AlertProvider } from "./components/alert/Alerts";
|
2020-10-01 14:25:29 +00:00
|
|
|
import { PageBreadCrumbs } from "./components/bread-crumb/PageBreadCrumbs";
|
2021-02-17 21:12:25 +00:00
|
|
|
import { ErrorRenderer } from "./components/error/ErrorRenderer";
|
2023-01-18 12:09:49 +00:00
|
|
|
import { KeycloakSpinner } from "./components/keycloak-spinner/KeycloakSpinner";
|
2024-01-10 18:37:59 +00:00
|
|
|
import {
|
|
|
|
ErrorBoundaryFallback,
|
|
|
|
ErrorBoundaryProvider,
|
|
|
|
} from "./context/ErrorBoundary";
|
2023-02-09 08:05:38 +00:00
|
|
|
import { RecentRealmsProvider } from "./context/RecentRealms";
|
2023-03-27 16:34:53 +00:00
|
|
|
import { AccessContextProvider } from "./context/access/Access";
|
|
|
|
import { RealmContextProvider } from "./context/realm-context/RealmContext";
|
2023-01-18 12:09:49 +00:00
|
|
|
import { ServerInfoProvider } from "./context/server-info/ServerInfoProvider";
|
2021-08-11 11:23:59 +00:00
|
|
|
import { WhoAmIContextProvider } from "./context/whoami/WhoAmI";
|
2024-06-06 06:36:46 +00:00
|
|
|
import type { Environment } from "./environment";
|
2023-01-18 12:09:49 +00:00
|
|
|
import { SubGroups } from "./groups/SubGroupsContext";
|
2023-03-27 16:34:53 +00:00
|
|
|
import { AuthWall } from "./root/AuthWall";
|
2020-10-21 11:31:41 +00:00
|
|
|
|
2023-05-03 11:27:27 +00:00
|
|
|
const AppContexts = ({ children }: PropsWithChildren) => (
|
2024-01-10 18:37:59 +00:00
|
|
|
<ErrorBoundaryProvider>
|
2024-01-22 08:19:58 +00:00
|
|
|
<ServerInfoProvider>
|
2024-02-26 13:04:38 +00:00
|
|
|
<RealmContextProvider>
|
|
|
|
<WhoAmIContextProvider>
|
2024-06-13 09:29:57 +00:00
|
|
|
<RecentRealmsProvider>
|
|
|
|
<AccessContextProvider>
|
|
|
|
<AlertProvider>
|
|
|
|
<SubGroups>{children}</SubGroups>
|
|
|
|
</AlertProvider>
|
|
|
|
</AccessContextProvider>
|
|
|
|
</RecentRealmsProvider>
|
2024-02-26 13:04:38 +00:00
|
|
|
</WhoAmIContextProvider>
|
|
|
|
</RealmContextProvider>
|
2024-01-22 08:19:58 +00:00
|
|
|
</ServerInfoProvider>
|
2024-01-10 18:37:59 +00:00
|
|
|
</ErrorBoundaryProvider>
|
2021-08-11 11:23:59 +00:00
|
|
|
);
|
|
|
|
|
2023-05-03 11:27:27 +00:00
|
|
|
export const App = () => {
|
2024-06-06 06:36:46 +00:00
|
|
|
const { keycloak, environment } = useEnvironment<Environment>();
|
2024-05-08 08:23:43 +00:00
|
|
|
const [adminClient, setAdminClient] = useState<KeycloakAdminClient>();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const init = async () => {
|
|
|
|
const client = await initAdminClient(keycloak, environment);
|
|
|
|
setAdminClient(client);
|
|
|
|
};
|
|
|
|
init().catch(console.error);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (!adminClient) return <KeycloakSpinner />;
|
2020-08-04 12:59:41 +00:00
|
|
|
return (
|
2024-05-08 08:23:43 +00:00
|
|
|
<AdminClientContext.Provider value={{ keycloak, adminClient }}>
|
|
|
|
<AppContexts>
|
|
|
|
<Page
|
|
|
|
header={<Header />}
|
|
|
|
isManagedSidebar
|
|
|
|
sidebar={<PageNav />}
|
|
|
|
breadcrumb={<PageBreadCrumbs />}
|
|
|
|
mainContainerId={mainPageContentId}
|
|
|
|
>
|
|
|
|
<ErrorBoundaryFallback fallback={ErrorRenderer}>
|
|
|
|
<Suspense fallback={<KeycloakSpinner />}>
|
|
|
|
<AuthWall>
|
|
|
|
<Outlet />
|
|
|
|
</AuthWall>
|
|
|
|
</Suspense>
|
|
|
|
</ErrorBoundaryFallback>
|
|
|
|
</Page>
|
|
|
|
</AppContexts>
|
|
|
|
</AdminClientContext.Provider>
|
2020-08-04 12:59:41 +00:00
|
|
|
);
|
|
|
|
};
|