-
Notifications
You must be signed in to change notification settings - Fork 295
/
TermsOfUseForm.tsx
110 lines (98 loc) · 3.15 KB
/
TermsOfUseForm.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
// @flow
import React, { Component } from 'react';
import classnames from 'classnames';
import { observer } from 'mobx-react';
import { Button } from 'react-polymorph/lib/components/Button';
import { Checkbox } from 'react-polymorph/lib/components/Checkbox';
import { ButtonSkin } from 'react-polymorph/lib/skins/simple/ButtonSkin';
import { CheckboxSkin } from 'react-polymorph/lib/skins/simple/CheckboxSkin';
import { defineMessages, intlShape } from 'react-intl';
import LocalizableError from '../../../i18n/LocalizableError';
import TermsOfUseText from './TermsOfUseText';
import styles from './TermsOfUseForm.scss';
const messages = defineMessages({
checkboxLabel: {
id: 'profile.termsOfUse.checkboxLabel',
defaultMessage: '!!!I agree with terms of service',
description: 'Label for the "I agree with terms of service" checkbox.',
},
checkboxLabelWithDisclaimer: {
id: 'profile.termsOfUse.checkboxLabelWithDisclaimer',
defaultMessage:
'!!!I understand that the terms of use are only available in English and agree to the terms of use',
description:
'Label for the "I agree with terms of service" checkbox when terms of use are not translated.',
},
submitLabel: {
id: 'profile.termsOfUse.submitLabel',
defaultMessage: '!!!Continue',
description: 'Label for the "Terms of service" form submit button.',
},
});
type Props = {
localizedTermsOfUse: string,
onSubmit: Function,
isSubmitting: boolean,
error?: ?LocalizableError,
onOpenExternalLink: Function,
};
type State = {
areTermsOfUseAccepted: boolean,
};
@observer
export default class TermsOfUseForm extends Component<Props, State> {
static contextTypes = {
intl: intlShape.isRequired,
};
state = {
areTermsOfUseAccepted: false,
};
toggleAcceptance = () => {
this.setState((prevState) => ({
areTermsOfUseAccepted: !prevState.areTermsOfUseAccepted,
}));
};
submit = () => {
this.props.onSubmit();
};
render() {
const { intl } = this.context;
const {
isSubmitting,
error,
localizedTermsOfUse,
onOpenExternalLink,
} = this.props;
const { areTermsOfUseAccepted } = this.state;
const buttonClasses = classnames([
'primary',
isSubmitting ? styles.submitButtonSpinning : styles.submitButton,
]);
return (
<div className={styles.component}>
<div className={styles.centeredBox}>
<TermsOfUseText
localizedTermsOfUse={localizedTermsOfUse}
onOpenExternalLink={onOpenExternalLink}
/>
<div className={styles.checkbox}>
<Checkbox
label={intl.formatMessage(messages.checkboxLabel)}
onChange={this.toggleAcceptance}
checked={areTermsOfUseAccepted}
skin={CheckboxSkin}
/>
</div>
{error && <p className={styles.error}>{intl.formatMessage(error)}</p>}
<Button
className={buttonClasses}
label={intl.formatMessage(messages.submitLabel)}
onClick={this.submit}
disabled={!areTermsOfUseAccepted}
skin={ButtonSkin}
/>
</div>
</div>
);
}
}