2022-07-31 18:57:30 +02:00
|
|
|
import React, { useEffect, memo } from "react";
|
2022-07-29 01:31:55 +02:00
|
|
|
import Template from "./Template";
|
2021-04-08 15:41:40 +02:00
|
|
|
import type { KcProps } from "./KcProps";
|
2021-06-23 08:16:51 +02:00
|
|
|
import type { KcContextBase } from "../getKcContext/KcContextBase";
|
2022-07-31 18:57:30 +02:00
|
|
|
import { useI18n } from "../i18n";
|
2021-08-20 17:03:50 +02:00
|
|
|
import { useCssAndCx } from "tss-react";
|
2022-07-31 18:57:30 +02:00
|
|
|
import { Evt } from "evt";
|
|
|
|
import { useRerenderOnStateChange } from "evt/hooks";
|
|
|
|
|
|
|
|
export const evtTermMarkdown = Evt.create<string | undefined>(undefined);
|
2022-04-27 21:02:10 +02:00
|
|
|
|
|
|
|
/** Allow to avoid bundling the terms and download it on demand*/
|
2022-07-31 18:57:30 +02:00
|
|
|
export function useDownloadTerms(params: { downloadTermMarkdown: (params: { currentLanguageTag: string }) => Promise<string> }) {
|
|
|
|
const { downloadTermMarkdown } = params;
|
2022-04-27 21:02:10 +02:00
|
|
|
|
2022-07-31 18:57:30 +02:00
|
|
|
const { currentLanguageTag } = useI18n();
|
2022-04-27 21:02:10 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-07-31 18:57:30 +02:00
|
|
|
let isMounted = true;
|
|
|
|
|
|
|
|
downloadTermMarkdown({ currentLanguageTag }).then(thermMarkdown => {
|
|
|
|
if (!isMounted) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-27 21:02:10 +02:00
|
|
|
|
2022-07-31 18:57:30 +02:00
|
|
|
evtTermMarkdown.state = thermMarkdown;
|
2022-04-27 21:02:10 +02:00
|
|
|
});
|
2022-07-31 18:57:30 +02:00
|
|
|
|
|
|
|
return () => {
|
|
|
|
isMounted = false;
|
|
|
|
};
|
2022-04-27 21:02:10 +02:00
|
|
|
}, []);
|
|
|
|
}
|
2021-04-08 15:41:40 +02:00
|
|
|
|
2022-07-29 01:31:55 +02:00
|
|
|
const Terms = memo(({ kcContext, ...props }: { kcContext: KcContextBase.Terms } & KcProps) => {
|
2022-07-31 18:57:30 +02:00
|
|
|
const { msg, msgStr } = useI18n();
|
|
|
|
|
|
|
|
useRerenderOnStateChange(evtTermMarkdown);
|
2021-04-08 15:41:40 +02:00
|
|
|
|
2021-10-12 00:26:29 +02:00
|
|
|
const { cx } = useCssAndCx();
|
2021-04-08 15:41:40 +02:00
|
|
|
|
2021-10-12 00:26:29 +02:00
|
|
|
const { url } = kcContext;
|
2021-04-08 15:41:40 +02:00
|
|
|
|
2022-07-31 18:57:30 +02:00
|
|
|
if (evtTermMarkdown.state === undefined) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-10-12 00:26:29 +02:00
|
|
|
return (
|
|
|
|
<Template
|
|
|
|
{...{ kcContext, ...props }}
|
|
|
|
doFetchDefaultThemeResources={true}
|
|
|
|
displayMessage={false}
|
|
|
|
headerNode={msg("termsTitle")}
|
|
|
|
formNode={
|
|
|
|
<>
|
2022-07-31 18:57:30 +02:00
|
|
|
<div id="kc-terms-text">{evtTermMarkdown.state}</div>
|
2021-10-12 00:26:29 +02:00
|
|
|
<form className="form-actions" action={url.loginAction} method="POST">
|
|
|
|
<input
|
|
|
|
className={cx(
|
|
|
|
props.kcButtonClass,
|
|
|
|
props.kcButtonClass,
|
|
|
|
props.kcButtonClass,
|
|
|
|
props.kcButtonPrimaryClass,
|
|
|
|
props.kcButtonLargeClass,
|
|
|
|
)}
|
|
|
|
name="accept"
|
|
|
|
id="kc-accept"
|
|
|
|
type="submit"
|
|
|
|
value={msgStr("doAccept")}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
className={cx(props.kcButtonClass, props.kcButtonDefaultClass, props.kcButtonLargeClass)}
|
|
|
|
name="cancel"
|
|
|
|
id="kc-decline"
|
|
|
|
type="submit"
|
|
|
|
value={msgStr("doDecline")}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
<div className="clearfix" />
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
2022-07-29 01:31:55 +02:00
|
|
|
|
|
|
|
export default Terms;
|