From 44ed9501348e7b31156aeecdb16b93f2e0293c13 Mon Sep 17 00:00:00 2001 From: garronej Date: Tue, 4 Apr 2023 02:59:26 +0200 Subject: [PATCH] Fix Terms #297 --- src/keycloak-theme/login/pages/Terms.tsx | 35 ++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/keycloak-theme/login/pages/Terms.tsx b/src/keycloak-theme/login/pages/Terms.tsx index 7b44f45..ce92a8a 100644 --- a/src/keycloak-theme/login/pages/Terms.tsx +++ b/src/keycloak-theme/login/pages/Terms.tsx @@ -1,4 +1,3 @@ -// ejected using 'npx eject-keycloak-page' import { clsx } from "keycloakify/tools/clsx"; import { useRerenderOnStateChange } from "evt/hooks"; import { Markdown } from "keycloakify/tools/Markdown"; @@ -7,6 +6,9 @@ import { useGetClassName } from "keycloakify/login/lib/useGetClassName"; import { evtTermMarkdown } from "keycloakify/login/lib/useDownloadTerms"; import type { KcContext } from "../kcContext"; import type { I18n } from "../i18n"; +import { useDownloadTerms } from "keycloakify/login"; +import tos_en_url from "../assets/tos_en.md"; +import tos_fr_url from "../assets/tos_fr.md"; export default function Terms(props: PageProps, I18n>) { const { kcContext, i18n, doUseDefaultCss, Template, classes } = props; @@ -18,17 +20,44 @@ export default function Terms(props: PageProps { + + const resource = (() => { + switch (currentLanguageTag) { + case "fr": + return tos_fr_url; + default: + return tos_en_url; + } + })(); + + // webpack5 (used via storybook) loads markdown as string, not url + if (resource.includes("\n")) return resource + + const response = await fetch(resource); + return response.text(); + }, + }); + useRerenderOnStateChange(evtTermMarkdown); const { url } = kcContext; - if (evtTermMarkdown.state === undefined) { + const termMarkdown = evtTermMarkdown.state; + + if (termMarkdown === undefined) { return null; } return (