import React, { ReactNode, useEffect } from "react";
import { Page } from "@patternfly/react-core";
import {
BrowserRouter as Router,
Route,
Switch,
useParams,
} from "react-router-dom";
import { Header } from "./PageHeader";
import { PageNav } from "./PageNav";
import { Help } from "./components/help-enabler/HelpHeader";
import { ServerInfoProvider } from "./context/server-info/ServerInfoProvider";
import { AlertProvider } from "./components/alert/Alerts";
import { AccessContextProvider, useAccess } from "./context/access/Access";
import { routes, RouteDef } from "./route-config";
import { PageBreadCrumbs } from "./components/bread-crumb/PageBreadCrumbs";
import { ForbiddenSection } from "./ForbiddenSection";
import { SubGroups } from "./groups/GroupsSection";
import { useRealm } from "./context/realm-context/RealmContext";
import { useAdminClient, asyncStateFetch } from "./context/auth/AdminClient";
// This must match the id given as scrollableSelector in scroll-form
const mainPageContentId = "kc-main-content-page-container";
const AppContexts = ({ children }: { children: ReactNode }) => (
{children}
);
// set the realm form the path if it's one of the know realms
const RealmPathSelector = ({ children }: { children: ReactNode }) => {
const { setRealm } = useRealm();
const { realm } = useParams<{ realm: string }>();
const adminClient = useAdminClient();
useEffect(
() =>
asyncStateFetch(
() => adminClient.realms.find(),
(realms) => {
if (realms.findIndex((r) => r.realm == realm) !== -1) {
setRealm(realm);
}
}
),
[]
);
return <>{children}>;
};
// If someone tries to go directly to a route they don't
// have access to, show forbidden page.
type SecuredRouteProps = { route: RouteDef };
const SecuredRoute = ({ route }: SecuredRouteProps) => {
const { hasAccess } = useAccess();
if (hasAccess(route.access)) return ;
return ;
};
export const App = () => {
return (
}
isManagedSidebar
sidebar={}
breadcrumb={}
mainContainerId={mainPageContentId}
>
{routes(() => {}).map((route, i) => (
(
)}
/>
))}
);
};