Skip to content

Commit 4778cfb

Browse files
Added ability to search by payer.
Not fully functional. Currently broken due to an error with trying to have it work with refunds.
1 parent 62620dd commit 4778cfb

File tree

9 files changed

+199
-58
lines changed

9 files changed

+199
-58
lines changed

actions/checkouts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function fetchCheckout(email, account_id = null, checkout_id = null, start = nul
104104
}
105105

106106
function shouldFetchCheckout(state, account_id) {
107-
if (state.wepay_account && state.wepay_account.searchedAccount.account_id != null && !state.wepay_checkout.checkout.isFetching) {
107+
if (state.wepay_account && state.wepay_account.searchedAccount.account_id != null && !state.wepay_checkout.checkout.isFetching && !state.wepay_payer.payerInfo) {
108108
return true;
109109
}
110110
else if(state.wepay_user.isFetching){

actions/user.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ export const RECEIVE_USER = 'RECEIVE_USERS'
55
export const SEARCH_USER = 'SEARCH_USERS'
66
export const INVALIDATE_USER = 'INVALIDATE_USER'
77

8-
export function searchUser(email) {
8+
export function searchUser(email = null, account_id =null) {
99
return {
1010
type: SEARCH_USER,
11-
email:email
11+
info: {"email":email,
12+
"account_id": account_id
13+
}
1214
}
1315
}
1416

@@ -35,10 +37,10 @@ function receiveUser(email, json) {
3537
}
3638
}
3739

38-
function fetchUser(email, callback) {
40+
function fetchUser(email, account_id, callback) {
3941
return dispatch => {
4042
dispatch(requestUser(email))
41-
return $.post("/user", {"email":email})
43+
return $.post("/user", {"email":email, "account_id":account_id})
4244
.fail(function(data){
4345
console.log("ERROR: ", data);
4446
var error_data = data.responseJSON;
@@ -56,7 +58,7 @@ function fetchUser(email, callback) {
5658
}
5759

5860
function shouldFetchUser(state, email) {
59-
if (state.wepay_user && state.wepay_user.searchedUser != "") {
61+
if (state.wepay_user && state.wepay_user.searchedUser) {
6062
console.log("Should fetch user");
6163
return true;
6264
}
@@ -66,10 +68,10 @@ function shouldFetchUser(state, email) {
6668
return false;
6769
}
6870

69-
export function fetchUserIfNeeded(email, callback) {
71+
export function fetchUserIfNeeded(email=null, account_id = null, callback = null) {
7072
return (dispatch, getState) => {
7173
if (shouldFetchUser(getState(), email)) {
72-
return dispatch(fetchUser(email, callback))
74+
return dispatch(fetchUser(email, account_id, callback))
7375
}
7476
}
7577
}

components/Accounts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const mapStateToProps = (state) => {
112112
return {
113113
accountInfo:state.wepay_account.account.accountInfo,
114114
searchedAccount: state.wepay_account.searchedAccount,
115-
email: state.wepay_user.searchedUser,
115+
email: state.wepay_user.searchedUser.email,
116116
error: state.errors.global ? state.errors.global.info : {}
117117
}
118118
}

components/App.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ const App = () => (
1010
<Grid fluid={true}>
1111
<Row>
1212
<Col lg={6} sm={12}>
13-
<SearchBar />
13+
<SearchBar resource={"user"} />
1414
<UserInfo />
1515
<AccountBlock />
1616
<Withdrawals />
1717
</Col>
1818
<Col lg={6} sm={12}>
19+
<SearchBar resource={"payer"} />
1920
<Checkouts />
2021
</Col>
2122
</Row>

components/Checkouts.js

Lines changed: 90 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { connect } from 'react-redux'
1717
import {BootstrapTable} from "react-bootstrap-table"
1818

1919
import {fetchRefundIfNeeded, clearRefund, fetchCheckoutIfNeeded, searchCheckout} from "../actions/checkouts"
20+
import {searchUser, fetchUserIfNeeded} from "../actions/user"
21+
import {fetchAccountIfNeeded} from "../actions/accounts"
2022

2123
import Base from "./Base"
2224

@@ -28,9 +30,28 @@ var Checkouts = React.createClass({
2830
selectedCheckoutId: null,
2931
refundAmount: 0,
3032
refundReason: "",
33+
},
34+
selectRowProp: {
35+
mode: "radio",
36+
clickToSelect: true,
37+
bgColor: "rgb(249, 255, 172)",
38+
onSelect: this.handlePayerCheckoutSelect
3139
}
3240
}
3341
},
42+
handlePayerCheckoutSelect: function(event) {
43+
// set the account
44+
event.preventDefault();
45+
var account_id = event.target.id;
46+
var this2 = this;
47+
48+
// fetch the user info and after the user info is fetched, get the account error
49+
this.props.dispatch(fetchUserIfNeeded(null, account_id,
50+
function(){
51+
this2.props.dispatch(fetchAccountIfNeeded(account_id))
52+
}
53+
));
54+
},
3455
openModal: function(event) {
3556
this.setState({showModal:true, refund:{selectedCheckoutId: event.target.id}});
3657
this.props.dispatch(searchCheckout(this.props.email, null, this.state.refund.selectedCheckoutId));
@@ -41,9 +62,11 @@ var Checkouts = React.createClass({
4162
},
4263
buildModal: function() {
4364
var checkout = null;
44-
for (var i = 0; i < this.props.checkoutInfo.length; i++) {
45-
if(this.props.checkoutInfo[i].checkout_id == this.state.refund.selectedCheckoutId) {
46-
checkout = this.props.checkoutInfo[i];
65+
var checkout_list = this.props.payerInfo? this.props.payerInfo : this.props.checkoutInfo
66+
67+
for (var i = 0; i < checkout_list.length; i++) {
68+
if(checkout_list[i].checkout_id == this.state.refund.selectedCheckoutId) {
69+
checkout = checkout_list[i];
4770
break;
4871
}
4972
}
@@ -169,8 +192,8 @@ var Checkouts = React.createClass({
169192

170193
this.props.dispatch(fetchRefundIfNeeded(this.props.email, checkout_id, refundAmount, refundReason));
171194
},
172-
formatCheckoutID: function(cell,row) {
173-
return "<a href='#' id=" + cell + ">" + cell + "</a>";
195+
formatAccountID: function(cell,row) {
196+
return (<a href='#' id={cell} onClick={this.handlePayerCheckoutSelect}>{cell}</a>);
174197
},
175198
formatRefund: function(cell, row) {
176199
// cell is the refund_amount_refunded value. If this is less than the amount of the original checkout then we want to include a refund button
@@ -203,10 +226,59 @@ var Checkouts = React.createClass({
203226
return array;
204227
},
205228
render: function() {
206-
if (this.props.checkoutInfo == null || $.isEmptyObject(this.props.error) == false) {
207-
return (<div></div>);
229+
if(this.props.payerInfo != null) {
230+
var refund_column;
231+
232+
233+
refund_column = (<TableHeaderColumn
234+
dataField = "refund_amount_refunded"
235+
dataFormat = {(this.props.account_id) ? this.formatRefund : function(cell){return cell}}
236+
>
237+
Refund
238+
</TableHeaderColumn>);
239+
240+
return (<div>
241+
<Row>
242+
<h4>Payer Checkouts</h4>
243+
<BootstrapTable
244+
data={this.props.payerInfo}
245+
striped={true}
246+
hover={true}
247+
pagination={true}
248+
search={true}
249+
>
250+
<TableHeaderColumn
251+
dataField="checkout_id"
252+
isKey={true}
253+
dataFormat={this.formatCheckoutID}
254+
>
255+
Checkout ID
256+
</TableHeaderColumn>
257+
<TableHeaderColumn
258+
dataField = "create_time"
259+
dataFormat={Base.formatDate}
260+
dataSort={true}
261+
>
262+
Date
263+
</TableHeaderColumn>
264+
<TableHeaderColumn
265+
dataField = "amount"
266+
>
267+
Amount
268+
</TableHeaderColumn>
269+
<TableHeaderColumn
270+
dataField="account_id"
271+
dataFormat = {this.formatAccountID}
272+
>
273+
Account ID
274+
</TableHeaderColumn>
275+
{refund_column ? refund_column : null}
276+
</BootstrapTable>
277+
{this.buildModal()}
278+
</Row>
279+
</div>);
208280
}
209-
else {
281+
else if(this.props.checkoutInfo != null){
210282
var checkouts = this.serialize(this.props.checkoutInfo);
211283
return (
212284
<div>
@@ -279,24 +351,26 @@ var Checkouts = React.createClass({
279351
</div>
280352
);
281353
}
354+
355+
return (<div></div>);
282356
}
283357
});
284358

285359
const mapStateToProps = (state) => {
286360
return {
287-
checkoutInfo:state.wepay_checkout.checkout.checkoutInfo,
288-
email: state.wepay_user.searchedUser,
289-
account_id: state.wepay_account.searchedAccount.account_id,
290-
submitted_refund: state.wepay_checkout.checkout.submitted_refund,
291-
successful_refund: state.wepay_checkout.checkout.successful_refund,
292-
error: state.errors.global ? state.errors.global.info : {},
293-
refund_error: state.errors.refund ? state.errors.refund.info: {}
361+
checkoutInfo: state.wepay_checkout.checkout.checkoutInfo,
362+
email: state.wepay_user.searchedUser.email,
363+
account_id: state.wepay_account.searchedAccount.account_id,
364+
submitted_refund: state.wepay_checkout.checkout.submitted_refund,
365+
successful_refund: state.wepay_checkout.checkout.successful_refund,
366+
error: state.errors.global ? state.errors.global.info : {},
367+
refund_error: state.errors.refund ? state.errors.refund.info: {},
368+
payerInfo: state.wepay_payer.payer.payerInfo
294369

295370
}
296371
}
297372

298373
Checkouts = connect(mapStateToProps)(Checkouts);
299374

300375

301-
302376
export default Checkouts

containers/SearchBar.js

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,30 @@ import { connect } from 'react-redux'
1010
import React from 'react'
1111
import {FormGroup, FormControl} from "react-bootstrap"
1212
import UserInfo from "../components/User"
13-
import {addUser} from "../actions/user"
14-
import {addAccounts, clearAccounts} from "../actions/accounts"
15-
import {addError} from "../actions/errors"
13+
1614
import {searchUser, fetchUserIfNeeded} from "../actions/user"
17-
import {fetchAccountIfNeeded} from "../actions/accounts"
15+
import {searchPayer, fetchPayerIfNeeded} from "../actions/payer"
16+
import {fetchAccountIfNeeded, clearAccounts} from "../actions/accounts"
17+
1818
import {clearCheckouts} from "../actions/checkouts"
1919
import {clearWithdrawals} from "../actions/withdrawals"
2020

21-
var SearchBar = React.createClass({
21+
import {addPayer} from '../actions/payer'
22+
23+
import {addError} from "../actions/errors"
2224

25+
26+
var SearchBar = React.createClass({
27+
propTypes: {
28+
resource: React.PropTypes.string.isRequired // what we are searching for. Depending on what it is, it will do a different searchFunction
29+
},
2330
// sets initial state
2431
// states in react are just nested associative objects
2532
getInitialState: function(){
2633
return {
27-
searchString: '', // the search string we update on submit
28-
value:"", // the value of the input text box
29-
error:{"error_message":""}
34+
searchString: '', // the search string we update on submit
35+
value:"", // the value of the input text box
36+
error:{"error_message":""},
3037
};
3138
},
3239

@@ -42,6 +49,7 @@ var SearchBar = React.createClass({
4249
// prevent form default behavior to prevent page reload on submit
4350
// after this is complete, the form will re-render and only contain results that match or string
4451
event.preventDefault();
52+
4553
var this2 = this;
4654
this.setState({searchString: this.state.value});
4755

@@ -53,7 +61,7 @@ var SearchBar = React.createClass({
5361
this.props.dispatch(clearWithdrawals());
5462

5563
// fetch the user info and after the user info is fetched, get the account error
56-
this.props.dispatch(fetchUserIfNeeded(this.state.value,
64+
this.props.dispatch(fetchUserIfNeeded(this.state.value, null,
5765
function(){
5866
this2.props.dispatch(fetchAccountIfNeeded(this2.state.value))
5967
}
@@ -63,36 +71,71 @@ var SearchBar = React.createClass({
6371
// if the user search was successful then go get the account data
6472
//this.props.dispatch(fetchAccountIfNeeded(this.state.value));
6573
},
74+
searchPayer: function(event) {
75+
event.preventDefault();
76+
77+
var this2 = this;
78+
this.setState({searchString: this.state.value});
79+
80+
// change the state because now we've searched a user
81+
this.props.dispatch(searchPayer(this.state.value));
82+
83+
/*this.props.dispatch(clearAccounts());
84+
this.props.dispatch(clearCheckouts());
85+
this.props.dispatch(clearWithdrawals());*/
86+
87+
// fetch the user info and after the user info is fetched, get the account error
88+
this.props.dispatch(fetchPayerIfNeeded(this.state.value));
89+
},
6690
render: function(dispatch) {
6791
var searchString = this.state.searchString.trim().toLowerCase();
6892
//render the user search functionality
6993
var error_message ="";
7094
if(this.props.error) {
7195
error_message = this.props.error.error_message;
7296
}
73-
return (
74-
<div>
75-
<h4>Search User by Email </h4>
76-
<form onSubmit={this.searchUser}
77-
>
78-
<FormGroup controlId="userSearchForm">
79-
<FormControl
80-
type="text"
81-
value={this.state.value}
82-
placeholder="Search!"
83-
onChange={this.handleChange} />
84-
</FormGroup>
85-
<p>{error_message}</p>
86-
</form>
87-
</div>
88-
)
97+
if (this.props.resource == "user") {
98+
return (
99+
<div>
100+
<h4>Search User by Email </h4>
101+
<form onSubmit={this.searchUser}
102+
>
103+
<FormGroup controlId="userSearchForm">
104+
<FormControl
105+
type="text"
106+
value={this.state.value}
107+
placeholder="Search!"
108+
onChange={this.handleChange} />
109+
</FormGroup>
110+
<p>{error_message}</p>
111+
</form>
112+
</div>
113+
)
114+
}
115+
else if (this.props.resource == "payer") {
116+
return (
117+
<div>
118+
<h4>Search Payer by Email </h4>
119+
<form onSubmit={this.searchPayer}
120+
>
121+
<FormGroup controlId="payerSearchForm">
122+
<FormControl
123+
type="text"
124+
value={this.state.value}
125+
placeholder="Search!"
126+
onChange={this.handleChange} />
127+
</FormGroup>
128+
<p>{error_message}</p>
129+
</form>
130+
</div>
131+
)
132+
}
89133
}
90134
});
91135

92136
const mapStateToProps = (state) => {
93137
return {
94-
error: state.errors.global ? state.errors.global.info : {}
95-
138+
error: state.errors.global ? state.errors.global.info : {}
96139
}
97140
}
98141

0 commit comments

Comments
 (0)