/
Donate.jsx
330 lines (310 loc) · 10.7 KB
/
Donate.jsx
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
import React, { Component } from 'react';
import { Link } from 'react-router';
import Form from 'react-bootstrap/esm/Form';
import FormControl from 'react-bootstrap/esm/FormControl';
import InputGroup from 'react-bootstrap/esm/InputGroup';
import Button from '@material-ui/core/esm/Button';
import styled from 'styled-components';
import { withStyles } from '@material-ui/core/esm/styles';
import Helmet from 'react-helmet';
import AnalyticsActions from '../../actions/AnalyticsActions';
import DonationForm from '../../components/Donation/DonationForm';
import DonationError from '../../components/Donation/DonationError';
import DonateStore from '../../stores/DonateStore';
import DonationListForm from '../../components/Donation/DonationListForm';
import OpenExternalWebSite from '../../components/Widgets/OpenExternalWebSite';
import { renderLog } from '../../utils/logging';
import VoterStore from '../../stores/VoterStore';
import WelcomeAppbar from '../../components/Navigation/WelcomeAppbar';
import Section from '../../components/Welcome/Section';
import Footer from '../../components/Welcome/Footer';
import DonateActions from '../../actions/DonateActions';
class Donate extends Component {
static getProps () {
return {};
}
static propTypes = {
};
constructor (props) {
super(props);
this.state = {
showCustomInput: false,
custom_amount: '',
donateMonthly: true,
donationErrorMessage: '',
radioSelected: 'monthly',
};
this.toggleCustomAmount = this.toggleCustomAmount.bind(this);
this.handleKeyPress = this.handleKeyPress.bind(this);
this.updateCustomAmount = this.updateCustomAmount.bind(this);
this.toggleDonateMonthly = this.toggleDonateMonthly.bind(this);
this.onDonateStoreChange = this.onDonateStoreChange.bind(this);
}
componentDidMount () {
this.onDonateStoreChange();
this.donateStoreListener = DonateStore.addListener(this.onDonateStoreChange);
AnalyticsActions.saveActionDonateVisit(VoterStore.electionId());
DonateActions.donationRefreshDonationList();
}
componentWillUnmount () {
this.donateStoreListener.remove();
}
onDonateStoreChange () {
if (!DonateStore.donationSuccess()) {
this.setState({ donationErrorMessage: DonateStore.donationError() });
}
}
/*
An enter keystroke in the react-bootstrap InputGroup, (or in the original react "input-group",)
causes a page reload, and you lose context. So swallow the 'Enter' keystroke event while in
the InputGroup.
*/
handleKeyPress = (event) => {
if (event.key === 'Enter') {
event.preventDefault();
}
};
toggleDonateMonthly (event) {
if (event.target.value === 'once') {
this.setState({
donateMonthly: false, radioSelected: 'once',
});
} else {
this.setState({
donateMonthly: true, radioSelected: 'monthly',
});
}
}
toggleCustomAmount () {
const { showCustomInput } = this.state;
this.setState({
showCustomInput: !showCustomInput,
});
}
updateCustomAmount (event) {
this.setState({ custom_amount: event.target.value });
}
render () {
renderLog('Donate'); // Set LOG_RENDER_EVENTS to log all renders
const donateMailtoUrl = "mailto:donate@WeVoteEducation.org?subject=Donate to We Vote's 501(c)(3)&body=I am interested in making at tax deductible donating to We Vote's 501(c)(3).";
return (
<Wrapper>
<Helmet title="Donate - We Vote" />
<WelcomeAppbar pathname="/more/pricing" />
<HeaderForDonate>
<DonateTitle>Donate</DonateTitle>
</HeaderForDonate>
<Section noTopMargin>
<DonateDescriptionContainer>
We Vote is a nonprofit technology startup,
{' '}
<Link to="/more/about" style={{ color: '#4371cc' }} onlyActiveOnIndex>
built by volunteers
</Link>
{' '}
to strengthen American democracy.
{' '}
<OpenExternalWebSite
url="https://projects.propublica.org/nonprofits/organizations/811052585"
target="_blank"
body={(
<span>
Our annual budgets are very small
<i className="fas fa-external-link-alt" />
</span>
)}
/>
, so every donation helps us pay for critical services. Over 50 awesome people like yourself have donated to make We Vote possible.
{' '}
{this.state.donationErrorMessage.length > 0 ?
<DonationError errorMessage={this.state.donationErrorMessage} /> :
<span>Please give what you can to help us reach more voters.</span>}
</DonateDescriptionContainer>
<DonateDescriptionContainer>
<Form className="donate-frequency">
<div className="donate-frequency__radio-button-div">
<Form.Check
type="radio"
label="Monthly"
bsPrefix="radio"
value="monthly"
// classes={{ root: classes.radioButtonMargins }}
onChange={this.toggleDonateMonthly}
checked={this.state.radioSelected === 'monthly'}
/>
</div>
<div className="donate-frequency__radio-button-div">
<Form.Check
type="radio"
label="One-Time"
name="radioGroup"
bsPrefix="radio"
value="once"
// classes={{ root: classes.radioButtonMargins }}
onChange={this.toggleDonateMonthly}
checked={this.state.radioSelected === 'once'}
/>
</div>
</Form>
<DonationForm
donationAmount={500}
donateButtonText="$5"
donateMonthly={this.state.donateMonthly}
/>
<DonationForm
donationAmount={1500}
donateButtonText="$15"
donateMonthly={this.state.donateMonthly}
/>
<DonationForm
donationAmount={2700}
donateButtonText="$27"
donateMonthly={this.state.donateMonthly}
/>
<DonationForm
donationAmount={5000}
donateButtonText="$50"
donateMonthly={this.state.donateMonthly}
/>
<DonationForm
donationAmount={10000}
donateButtonText="$100"
donateMonthly={this.state.donateMonthly}
/>
<Button
color="primary"
onClick={this.toggleCustomAmount}
style={{ margin: 5 }}
variant="contained"
>
<span className="u-no-break">Other Amount</span>
</Button>
{this.state.showCustomInput ? (
<span style={{ display: 'flex', marginTop: 10, marginLeft: 20 }}>
<InputGroup className="mb-3" style={{ width: '30%', marginTop: 4 }}>
<InputGroup.Prepend>
<InputGroup.Text>$</InputGroup.Text>
</InputGroup.Prepend>
{/* <FormControl aria-label="Amount" /> */}
<FormControl
type="text"
onKeyPress={this.handleKeyPress}
onChange={this.updateCustomAmount}
value={this.state.custom_amount}
placeholder="250.00"
style={{ left: 34, top: -38 }}
/>
</InputGroup>
<span style={{ paddingLeft: 40 }}>
<DonationForm
donationAmount={parseInt(parseFloat(this.state.custom_amount.replace(/[^0-9.]+/g, '')) * 100)}
donateMonthly={this.state.donateMonthly}
donateButtonText="Go"
donateOther
/>
</span>
</span>
) : null
}
{Number.isNaN(this.state.custom_amount) || this.state.custom_amount === '0' ? (
<span>
<p>Please enter a valid number</p>
</span>
) : null
}
</DonateDescriptionContainer>
<DonateDescriptionContainer>
Contributions or gifts made on this page are not tax deductible, and fund We Vote USA, a 501(c)(4) nonprofit.
We Vote also has a 501(c)(3) nonprofit that welcomes
{' '}
{/* This is a mailto! Shouldn't be visible in iPhone or Android apps. */}
<a href={donateMailtoUrl}
title="I would like to donate to We Vote's 501(c)(3)"
rel="noopener noreferrer"
target="_blank"
style={{ color: '#4371cc' }}
>
tax deductible donations
{' '}
<i className="fas fa-external-link-alt" />
.
</a>
</DonateDescriptionContainer>
<DonateDescriptionContainer>
<DonationListForm waitForWebhook={false} />
</DonateDescriptionContainer>
</Section>
<Footer />
</Wrapper>
);
}
}
const styles = theme => ({
buttonContained: {
borderRadius: 32,
height: 50,
[theme.breakpoints.down('md')]: {
height: 36,
},
},
});
const Wrapper = styled.div`
display: flex;
flex-flow: column nowrap;
align-items: center;
background: white;
overflow-x: hidden;
`;
const HeaderForDonate = styled.div`
position: relative;
height: 190px;
width: 110%;
color: white;
background-image: linear-gradient(to bottom, #415a99, #2d3b5e);
border-bottom-left-radius: 50% 25%;
border-bottom-right-radius: 50% 25%;
padding: 0 2em;
margin-top: -72px;
text-align: center;
@media (max-width: ${({ theme }) => theme.breakpoints.lg}) {
height: 190px;
}
@media (max-width: ${({ theme }) => theme.breakpoints.xs}) {
height: 150px;
}
`;
const DonateTitle = styled.h1`
font-weight: bold;
font-size: 36px;
text-align: center;
margin-top: 3em;
margin-bottom: 0;
padding-bottom: 0;
@media (max-width: ${({ theme }) => theme.breakpoints.md}) {
font-size: 28px;
margin-top: 3em;
}
@media (max-width: ${({ theme }) => theme.breakpoints.xs}) {
font-size: 18px;
margin-top: 5em;
}
`;
// }
const DonateDescriptionContainer = styled.div`
margin: 1em auto;
margin-bottom: 0;
width: 960px;
max-width: 90vw;
text-align: left;
@media (min-width: 960px) and (max-width: 991px) {
> * {
width: 90%;
margin: 0 auto;
}
max-width: 100%;
min-width: 100%;
width: 100%;
margin: 0 auto;
}
`;
export default withStyles(styles)(Donate);