keycloak-theme/src/login/KcApp.tsx

68 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-06-06 01:44:57 +02:00
import { Suspense, lazy } from "react";
2024-06-08 09:03:17 +02:00
import type { ClassKey } from "keycloakify/login";
2024-06-06 01:44:57 +02:00
import type { KcContext } from "./KcContext";
import { useI18n } from "./i18n";
import { useDownloadTerms } from "keycloakify/login";
2024-06-06 05:26:06 +02:00
import Template from "keycloakify/login/Template";
2024-06-06 01:44:57 +02:00
const Fallback = lazy(() => import("keycloakify/login/Fallback"));
2024-06-06 05:26:06 +02:00
const UserProfileFormFields = lazy(() => import("keycloakify/login/UserProfileFormFields"));
2024-06-08 09:03:17 +02:00
const classes = {} satisfies { [key in ClassKey]?: string };
2024-06-06 01:44:57 +02:00
export default function KcApp(props: { kcContext: KcContext }) {
const { kcContext } = props;
const i18n = useI18n({ kcContext });
useDownloadTerms({
kcContext,
2024-06-07 05:20:57 +02:00
downloadTermsMarkdown: async ({ currentLanguageTag }) => {
let termsLanguageTag = currentLanguageTag;
let termsFileName: string;
switch (currentLanguageTag) {
case "fr":
termsFileName = "fr.md";
break;
case "es":
termsFileName = "es.md";
break;
default:
termsFileName = "en.md";
termsLanguageTag = "en";
break;
}
2024-06-06 01:44:57 +02:00
2024-06-07 05:20:57 +02:00
const termsMarkdown = await fetch(`${import.meta.env.BASE_URL}terms/${termsFileName}`).then(r => r.text());
2024-06-06 01:44:57 +02:00
2024-06-07 05:20:57 +02:00
return { termsMarkdown, termsLanguageTag };
2024-06-06 01:44:57 +02:00
}
});
if (i18n === null) {
return null;
}
return (
<Suspense>
{(() => {
switch (kcContext.pageId) {
default:
2024-06-06 05:26:06 +02:00
return (
<Fallback
{...{
kcContext,
i18n,
classes,
Template,
UserProfileFormFields
}}
doUseDefaultCss={true}
/>
);
2024-06-06 01:44:57 +02:00
}
})()}
</Suspense>
);
}