keycloak-theme/src/KcApp/KcApp.tsx

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-09-07 12:30:14 +02:00
import { lazy, Suspense } from "react";
2022-09-06 19:22:23 +02:00
import type { KcContext } from "./kcContext";
2022-09-07 12:30:14 +02:00
import KcAppBase, { defaultKcProps } from "keycloakify";
import { useI18n } from "./i18n";
2022-09-07 13:27:27 +02:00
const Register = lazy(() => import("./Register"));
2022-09-07 12:30:14 +02:00
const Terms = lazy(() => import("./Terms"));
2022-09-07 13:27:27 +02:00
const MyExtraPage1 = lazy(() => import("./MyExtraPage1"));
const MyExtraPage2 = lazy(() => import("./MyExtraPage2"));
2022-09-06 19:22:23 +02:00
export type Props = {
kcContext: KcContext;
};
2022-09-07 12:30:14 +02:00
export default function KcApp({ kcContext }: Props) {
const i18n = useI18n({ kcContext });
2022-09-06 19:22:23 +02:00
2022-09-07 12:30:14 +02:00
//NOTE: Locales not yet downloaded
2022-09-06 19:22:23 +02:00
if (i18n === null) {
return null;
}
2022-09-07 12:30:14 +02:00
const props = {
i18n,
...defaultKcProps,
// NOTE: The classes are defined in ./KcApp.css
"kcHeaderWrapperClass": "my-color my-font",
};
2022-09-06 19:22:23 +02:00
return (
2022-09-07 12:30:14 +02:00
<Suspense>
{(() => {
switch (kcContext.pageId) {
case "register.ftl": return <Register {...{ kcContext, ...props }} />;
case "terms.ftl": return <Terms {...{ kcContext, ...props }} />;
case "my-extra-page-1.ftl": return <MyExtraPage1 {...{ kcContext, ...props }} />;
case "my-extra-page-2.ftl": return <MyExtraPage2 {...{ kcContext, ...props }} />;
default: return <KcAppBase {...{ kcContext, ...props }} />;
}
})()}
</Suspense>
2022-09-06 19:22:23 +02:00
);
2022-09-07 12:30:14 +02:00
2022-09-06 19:22:23 +02:00
}