This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
AmountSelection.js
148 lines (133 loc) · 4.07 KB
/
AmountSelection.js
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// @flow
import * as React from 'react';
import { FormattedMessage } from 'react-intl';
import DonationBands from '../DonationBands/DonationBands';
import Button from '../Button/Button';
import ee from '../../shared/pub_sub';
import Thermometer from '../Thermometer';
import CurrencyAmount from '../../components/CurrencyAmount';
export type Props = {
donationAmount?: number,
donationBands: { [id: string]: number[] },
donationFeaturedAmount?: number,
currency: string,
nextStepTitle?: React.Element<any>,
selectAmount: (amount: ?number) => void,
changeCurrency: (currency: string) => void,
proceed: () => void,
};
export type State = {
customAmount: ?number,
currencyDropdVisible: boolean,
};
export default class AmountSelection extends React.Component<Props, State> {
static title(amount: ?number, currency: string): any {
if (amount == null) {
return (
<FormattedMessage id="fundraiser.amount" defaultMessage="AMOUNT" />
);
}
return <CurrencyAmount amount={amount} currency={currency} />;
}
constructor(props: Props) {
super(props);
this.state = {
customAmount: null,
currencyDropdVisible: false,
};
}
componentDidUpdate() {
ee.emit('sidebar:height_change');
}
toggleCurrencyDropd() {
this.setState({
currencyDropdVisible: !this.state.currencyDropdVisible,
});
}
onSelectCurrency(currency: string): void {
this.props.changeCurrency(currency);
}
selectFeaturedAmount() {
if (this.props.donationFeaturedAmount) {
this.props.selectAmount(this.props.donationFeaturedAmount);
this.props.proceed();
}
}
proceed() {
if (!this.props.donationAmount && this.props.donationFeaturedAmount) {
this.props.selectAmount(this.props.donationFeaturedAmount);
}
this.props.proceed();
}
processSelection(e) {
this.props.proceed(e);
}
render() {
return (
<div className="AmountSelection-container section">
<Thermometer />
<DonationBands
ref="donationBands"
amounts={this.props.donationBands[this.props.currency]}
currency={this.props.currency}
proceed={this.processSelection.bind(this)}
featuredAmount={this.props.donationFeaturedAmount}
selectAmount={this.props.selectAmount}
selectCustomAmount={this.props.selectCustomAmount}
/>
<p>
<FormattedMessage
id="fundraiser.currency_in"
defaultMessage="Values shown in {currency}."
values={{ currency: this.props.currency }}
/>
.
<a
onClick={this.toggleCurrencyDropd.bind(this)}
className="AmountSelection__currency-toggle"
>
<FormattedMessage
id="fundraiser.switch_currency"
defaultMessage="Switch currency"
/>
</a>
</p>
{this.state.currencyDropdVisible && (
<select
value={this.props.currency}
className="AmountSelection__currency-selector"
onChange={(e: SyntheticEvent<HTMLSelectElement>) =>
this.onSelectCurrency(e.currentTarget.value)
}
>
{Object.keys(this.props.donationBands).map(currency => {
return (
<option key={currency} value={currency}>
{currency}
</option>
);
})}
</select>
)}
{(this.props.donationAmount || this.props.donationFeaturedAmount) && (
<Button
className="btn AmountSelection__proceed-button"
onClick={() => this.proceed()}
disabled={
!(this.props.donationAmount || this.props.donationFeaturedAmount)
}
>
{this.props.nextStepTitle ? (
this.props.nextStepTitle
) : (
<FormattedMessage
id="fundraiser.proceed_to_details"
defaultMessage="Proceed to details"
/>
)}
</Button>
)}
</div>
);
}
}