-
Notifications
You must be signed in to change notification settings - Fork 6
/
Terms.tsx
112 lines (102 loc) · 3.4 KB
/
Terms.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { useRerenderOnStateChange } from "evt/hooks";
import { Markdown } from "keycloakify/tools/Markdown";
import {
evtTermMarkdown,
useDownloadTerms
} from "keycloakify/login/lib/useDownloadTerms";
import tos_en_url from "../assets/tos_en.md";
import tos_fr_url from "../assets/tos_fr.md";
import type { PageProps } from "keycloakify/login/pages/PageProps";
import { makeStyles } from "@codegouvfr/react-dsfr/tss";
import { fr } from "@codegouvfr/react-dsfr";
import { useGetClassName } from "keycloakify/login/lib/useGetClassName";
import type { KcContext } from "../kcContext";
import type { I18n } from "../i18n";
export default function Terms(
props: PageProps<Extract<KcContext, { pageId: "terms.ftl" }>, I18n>
) {
const {
kcContext,
i18n,
doUseDefaultCss = true,
Template,
classes: classes_props
} = props;
const { msg, msgStr } = i18n;
const { classes, cx } = useStyles();
const { getClassName } = useGetClassName({
doUseDefaultCss,
"classes": classes_props
});
useDownloadTerms({
kcContext,
"downloadTermMarkdown": async ({ currentLanguageTag }) => {
const markdownString = await fetch(
(() => {
switch (currentLanguageTag) {
case "fr":
return tos_fr_url;
default:
return tos_en_url;
}
})()
).then(response => response.text());
return markdownString;
}
});
useRerenderOnStateChange(evtTermMarkdown);
const { url } = kcContext;
if (evtTermMarkdown.state === undefined) {
return null;
}
return (
<Template
{...{ kcContext, i18n, doUseDefaultCss, "classes": classes_props }}
displayMessage={false}
headerNode={msg("termsTitle")}
>
<div id="kc-terms-text">
{evtTermMarkdown.state && <Markdown>{evtTermMarkdown.state}</Markdown>}
</div>
<form
className={cx("form-actions", classes.formActions)}
action={url.loginAction}
method="POST"
>
<input
className={cx(
getClassName("kcButtonClass"),
getClassName("kcButtonClass"),
getClassName("kcButtonClass"),
getClassName("kcButtonPrimaryClass"),
getClassName("kcButtonLargeClass")
)}
name="accept"
id="kc-accept"
type="submit"
value={msgStr("doAccept")}
/>
<input
className={cx(
getClassName("kcButtonClass"),
getClassName("kcButtonDefaultClass"),
getClassName("kcButtonLargeClass")
)}
name="cancel"
id="kc-decline"
type="submit"
value={msgStr("doDecline")}
/>
</form>
<div className="clearfix" />
</Template>
);
}
const useStyles = makeStyles({
"name": { Terms }
})({
"formActions": {
"display": "flex",
"gap": fr.spacing("4v")
}
});