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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
import { i18n } from "@gnu-taler/taler-util";
import { Fragment, h, VNode } from "preact";
import { CheckboxOutlined } from "../components/CheckboxOutlined";
import { ExchangeXmlTos } from "../components/ExchangeToS";
import {
ButtonSuccess,
ButtonWarning,
LinkSuccess,
TermsOfService,
WarningBox,
} from "../components/styled";
import { TermsState } from "../utils";
interface Props {
reviewing: boolean;
reviewed: boolean;
terms: TermsState;
onReview?: (b: boolean) => void;
onAccept: (b: boolean) => void;
}
export function TermsOfServiceSection({
reviewed,
reviewing,
terms,
onAccept,
onReview,
}: Props): VNode {
if (!reviewing) {
if (!reviewed) {
if (!onReview) {
return <section>Terms of service status: {terms.status}</section>;
}
return (
<Fragment>
{terms.status === "new" && (
<section>
<ButtonSuccess upperCased onClick={() => onReview(true)}>
{i18n.str`Review exchange terms of service`}
</ButtonSuccess>
</section>
)}
{terms.status === "changed" && (
<section>
<ButtonWarning upperCased onClick={() => onReview(true)}>
{i18n.str`Review new version of terms of service`}
</ButtonWarning>
</section>
)}
</Fragment>
);
}
return (
<Fragment>
{onReview && (
<section>
<LinkSuccess upperCased onClick={() => onReview(true)}>
{i18n.str`Show terms of service`}
</LinkSuccess>
</section>
)}
<section>
<CheckboxOutlined
name="terms"
enabled={reviewed}
label={i18n.str`I accept the exchange terms of service`}
onToggle={() => {
console.log("asdasd", reviewed);
onAccept(!reviewed);
if (onReview) onReview(false);
}}
/>
</section>
</Fragment>
);
}
return (
<Fragment>
{terms.status !== "notfound" && !terms.content && (
<section>
<WarningBox>
The exchange reply with a empty terms of service
</WarningBox>
</section>
)}
{terms.status !== "accepted" && terms.content && (
<section>
{terms.content.type === "xml" && (
<TermsOfService>
<ExchangeXmlTos doc={terms.content.document} />
</TermsOfService>
)}
{terms.content.type === "plain" && (
<div style={{ textAlign: "left" }}>
<pre>{terms.content.content}</pre>
</div>
)}
{terms.content.type === "html" && (
<iframe src={terms.content.href.toString()} />
)}
{terms.content.type === "pdf" && (
<a href={terms.content.location.toString()} download="tos.pdf">
Download Terms of Service
</a>
)}
</section>
)}
{reviewed && onReview && (
<section>
<LinkSuccess upperCased onClick={() => onReview(false)}>
{i18n.str`Hide terms of service`}
</LinkSuccess>
</section>
)}
{terms.status !== "notfound" && (
<section>
<CheckboxOutlined
name="terms"
enabled={reviewed}
label={i18n.str`I accept the exchange terms of service`}
onToggle={() => {
onAccept(!reviewed);
if (onReview) onReview(false);
}}
/>
</section>
)}
</Fragment>
);
}
|