-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_out.jsx
161 lines (140 loc) · 4.82 KB
/
check_out.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
import React from 'react';
import { Link, withRouter, hashHistory } from 'react-router';
import CurrentUserDetails from './current_user_details';
import CheckOutTotal from './check_out_total';
class CheckOut extends React.Component {
constructor(props) {
super(props);
if (props.currentUser) {
this.state = {appearance: null, amount: this.props.amount || this.props.perk.price};
this.handleSubmit = this.handleSubmit.bind(this);
this.updateAmount = this.updateAmount.bind(this);
this.setState = this.setState.bind(this);
this.updateAppearance = this.updateAppearance.bind(this);
}
}
componentWillMount() {
if (!this.props.currentUser) {
hashHistory.push('/');
}
}
update(field) {
return e => this.setState({
[field]: e.currentTarget.value
});
}
handleSubmit(e) {
e.preventDefault();
if (this.state.appearance === null || this.state.amount === null) {
alert('Must fill in all fields!');
return;
}
let myContribution = this.createContributionObject();
return this.props.createContribution({ contribution: myContribution })
.then(() => hashHistory.push('/campaigns/' + this.props.campaign.id));
}
createContributionObject() {
let checkOutParams;
if (this.props.perk) {
checkOutParams = {
perk_id: this.props.perk.id,
campaign_id: this.props.campaign.id,
user_id: this.props.currentUser.id
};
} else {
checkOutParams = {
campaign_id: this.props.campaign.id,
user_id: this.props.currentUser.id
};
}
return Object.assign(this.state, checkOutParams);
}
updateAmount(e) {
(this.setState({amount: e.target.value}));
}
updateAppearance(e) {
(this.setState({appearance: e.target.value}));
}
checkOutTotal() {
if (this.props.perk) {
return (
<CheckOutTotal
perk={this.props.perk}
handleSubmit={this.handleSubmit} />
);
} else {
return (
<CheckOutTotal
handleSubmit={this.handleSubmit}
updateAmount={this.updateAmount}
campaign_id={this.props.campaign.id}
amount={this.state.amount} />
);
}
}
render() {
if (!this.props.currentUser) {
return(<div></div>);
}
let checkOutTotal = this.checkOutTotal();
return (
<div className="check-out-page">
<header>
<h2 className="check-out-h2">
You're contributing to {this.props.user.user.first_name} {this.props.user.user.last_name + '\''}s
</h2>
<h1 className="check-out-h1"> {this.props.campaign.title}</h1>
</header>
<div className="check-out-bottom">
<div className="check-out-form">
<CurrentUserDetails className="current-user-details" currentUser={this.props.currentUser} />
<text className="check-out-sub-title">Debit or Credit Card</text>
<br/>
<text>Fields have been disabled</text>
<form className="credit-card-deets">
<div className="credit-card-deets-top">
<input className="name-on-card" placeholder="Name on Card" disabled/>
<input className="card-num" placeholder="Debit or Credit Card Number" disabled/>
</div>
<div className="credit-card-deets-bottom">
<input className="exp-date" placeholder="Expiration Date (MM/YY)" disabled/>
<input className="sec-code" placeholder="Security Code" disabled/>
<input className="post-code" placeholder="Billing Postal Code" disabled/>
</div>
</form>
<text className="check-out-sub-title">Contribution Appearance</text>
<br/>
<text>Choose a name to be displayed publicly next to your contribution on the campaign page.</text>
<form className="appearance-form" onClick={this.updateAppearance}>
<label className={this.state.appearance == this.props.currentUser.first_name ? "appearance-radio appearance-radio-selected" : "appearance-radio"}>
<input type="radio"
name="appearance"
value={this.props.currentUser.first_name}
/>
<text className="radio-text">
{this.props.currentUser.first_name}
</text>
<br/>
</label>
<label className={this.state.appearance == "Anonymous" ? "appearance-radio appearance-radio-selected" : "appearance-radio"}>
<input
type="radio"
name="appearance"
value="Anonymous"
/>
<text className="radio-text">
Anonymous
</text>
<br/>
</label>
</form>
</div>
<div className="totaling-comp">
{checkOutTotal}
</div>
</div>
</div>
);
}
}
export default CheckOut;