keycloak-theme/src/login/KcApp.tsx

65 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-06-06 01:44:57 +02:00
import { Suspense, lazy } from "react";
2024-06-06 05:26:06 +02:00
import type { PageProps } 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"));
const classes = {} satisfies PageProps["classes"];
2024-06-06 01:44:57 +02:00
export default function KcApp(props: { kcContext: KcContext }) {
const { kcContext } = props;
const i18n = useI18n({ kcContext });
useDownloadTerms({
kcContext,
downloadTermMarkdown: async ({ currentLanguageTag }) => {
const termsFileName = (() => {
switch (currentLanguageTag) {
2024-06-06 05:26:06 +02:00
case "fr":
return "fr.md";
case "es":
return "es.md";
default:
return "en.md";
2024-06-06 01:44:57 +02:00
}
})();
2024-06-06 06:40:23 +02:00
// Dynamically downloading Markdown files from public/terms/[currentLanguage].md
// Replace theses files by your organization's terms of service.
const response = await fetch(`${import.meta.env.BASE_URL}terms/${termsFileName}`);
2024-06-06 01:44:57 +02:00
return response.text();
}
});
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>
);
}