1
1
import React , { PropTypes } from 'react'
2
- import { Grid , Label , FormGroup , FormControl , Row , Col , ControlLabel , Table , Button , Modal } from "react-bootstrap"
2
+ import { Grid , Form , Label , FormGroup , FormControl , Row , Col , ControlLabel , Table , Button , Modal } from "react-bootstrap"
3
3
import { connect } from 'react-redux'
4
4
import { BootstrapTable } from "react-bootstrap-table"
5
5
6
- import { fetchRefundIfNeeded , clearRefund } from "../actions/checkouts"
6
+ import { fetchRefundIfNeeded , clearRefund , fetchCheckoutIfNeeded } from "../actions/checkouts"
7
7
8
8
import Base from "./Base"
9
9
@@ -19,7 +19,6 @@ var Checkouts = React.createClass({
19
19
}
20
20
} ,
21
21
openModal : function ( event ) {
22
- console . log ( "OPENING MODAL" , event . target . id ) ;
23
22
this . setState ( { showModal :true , refund :{ selectedCheckoutId : event . target . id } } ) ;
24
23
} ,
25
24
closeModal : function ( ) {
@@ -46,7 +45,6 @@ var Checkouts = React.createClass({
46
45
if ( this . props . successful_refund ) {
47
46
successful_refund = ( < h3 > < Label bsStyle = "success" > Refund completed!</ Label > </ h3 > ) ;
48
47
}
49
- console . log ( successful_refund ) ;
50
48
return (
51
49
< div >
52
50
< Modal show = { this . state . showModal } onHide = { this . closeModal } >
@@ -55,48 +53,101 @@ var Checkouts = React.createClass({
55
53
</ Modal . Header >
56
54
< Modal . Body >
57
55
< p > < strong > Max Refundable Amount:</ strong > ${ maxRefundableAmount } </ p >
58
- < form onSubmit = { this . refundCheckout } >
56
+ < Form horizontal onSubmit = { this . refundCheckout } >
59
57
< FormGroup >
60
- < ControlLabel > Refund Amount</ ControlLabel >
61
- < FormControl
62
- type = "number"
63
- id = "refundAmount"
64
- max = { maxRefundableAmount }
65
- required
66
- />
58
+ < Col lg = { 6 } ms = { 12 } >
59
+ < ControlLabel > Refund Amount</ ControlLabel >
60
+ < FormControl
61
+ type = "number"
62
+ id = "refundAmount"
63
+ step = "0.01"
64
+ max = { maxRefundableAmount }
65
+ ref = "refundAmount"
66
+ onChange = { this . handleAmountChange }
67
+ required
68
+ />
69
+ </ Col >
70
+ < Col lg = { 6 } ms = { 12 } >
71
+ < ControlLabel > Refund Percentage</ ControlLabel >
72
+ < FormControl
73
+ type = "number"
74
+ id = "refundPercentage"
75
+ step = "0.01"
76
+ max = "100"
77
+ onChange = { this . handlePercentChange }
78
+ />
79
+ </ Col >
67
80
</ FormGroup >
68
81
< FormGroup >
69
- < ControlLabel > Refund Reason</ ControlLabel >
70
- < FormControl
71
- type = "text"
72
- id = "refundReason"
73
- required />
82
+ < Col lg = { 12 } >
83
+ < ControlLabel > Refund Reason</ ControlLabel >
84
+ < FormControl
85
+ type = "text"
86
+ id = "refundReason"
87
+ required />
88
+ </ Col >
74
89
</ FormGroup >
75
- { successful_refund }
76
- < Button type = "submit" bsStyle = "success" value = "Submit Refund" disabled = { this . props . submitted_refund } > Submit Refund</ Button >
77
- </ form >
90
+ < FormGroup >
91
+ < Col lg = { 12 } >
92
+ { successful_refund }
93
+ </ Col >
94
+ </ FormGroup >
95
+ < FormGroup >
96
+ < Col lg = { 12 } >
97
+ < Button type = "submit" bsStyle = "success" value = "Submit Refund" disabled = { this . props . submitted_refund } > Submit Refund</ Button >
98
+ </ Col >
99
+ </ FormGroup >
100
+ </ Form >
78
101
</ Modal . Body >
79
102
</ Modal >
80
103
</ div >
81
104
) ;
82
105
} ,
83
106
handleAmountChange : function ( event ) {
84
- var current = this . state . refund ;
85
- current . refundAmount = event . target . value ;
86
- this . setState ( { refund : current } )
107
+ var currentPercent = $ ( "#refundPercentage" ) ;
108
+ var refundAmount = event . target . value ;
109
+ var maxRefundableAmount = $ ( "#refundAmount" ) . prop ( "max" ) ;
110
+ currentPercent . val ( ( ( refundAmount * 100 ) / maxRefundableAmount ) . toFixed ( 2 ) ) ;
111
+
112
+ } ,
113
+ handlePercentChange : function ( event ) {
114
+ var currentAmount = $ ( "#refundAmount" ) ;
115
+ var currentPercent = event . target . value ;
116
+ var maxRefundableAmount = $ ( "#refundAmount" ) . prop ( "max" ) ;
117
+
118
+ // change the refund amount based on the percent value that the user has entered
119
+ // this is designed to make the refund easier. If their policy is to refund half, this takes away the guess work
120
+ currentAmount . val ( ( maxRefundableAmount * ( currentPercent / 100.0 ) ) . toFixed ( 2 ) ) ;
121
+
87
122
} ,
88
123
handleReasonChange : function ( event ) {
89
124
var current = this . state . refund ;
90
125
current . refundReason = event . target . value ;
91
126
this . setState ( { refund : current } )
92
127
} ,
128
+ fetchMoreCheckouts : function ( event ) {
129
+ console . log ( "Fetching more checkouts for: " , this . props . email , this . props . account_id ) ;
130
+ var start = this . props . checkoutInfo . length ;
131
+ this . props . dispatch ( fetchCheckoutIfNeeded ( this . props . email , this . props . account_id , null , start ) ) ;
132
+ } ,
93
133
refundCheckout : function ( e ) {
94
134
e . preventDefault ( ) ;
95
135
console . log ( "Performing refund for: " , this . state . refund . selectedCheckoutId ) ;
136
+
96
137
var checkout_id = this . state . refund . selectedCheckoutId ;
97
138
var refundAmount = $ ( "#refundAmount" ) . val ( ) ;
98
139
var refundReason = $ ( "#refundReason" ) . val ( ) ;
140
+ var maxRefundableAmount = $ ( "#refundAmount" ) . prop ( "max" ) ;
141
+
142
+ console . log ( refundAmount , maxRefundableAmount ) ;
143
+
144
+ if ( refundAmount - maxRefundableAmount == 0 ) {
145
+ console . log ( "Full refund!" ) ;
146
+ refundAmount = null ;
147
+ }
99
148
var current = this . state . refund ;
149
+ current [ 'refundAmount' ] = refundAmount ;
150
+ current [ 'refundReason' ] = refundReason ;
100
151
this . setState ( { refund :current } )
101
152
102
153
this . props . dispatch ( fetchRefundIfNeeded ( this . props . email , checkout_id , refundAmount , refundReason ) ) ;
@@ -114,7 +165,7 @@ var Checkouts = React.createClass({
114
165
var refundString = ( < p > < strong > Refunded</ strong > : ${ cell } < br > </ br > { row . refund_refund_reason } </ p > ) ;
115
166
var refundButton = ( < Button bsStyle = "primary" bsSize = "small" id = { row . checkout_id } onClick = { this . openModal } > Refund</ Button > )
116
167
if ( cell > 0 ) {
117
- if ( cell = = row . amount ) {
168
+ if ( cell > = row . amount ) {
118
169
return ( < div > { refundString } </ div > )
119
170
}
120
171
else {
@@ -183,7 +234,12 @@ var Checkouts = React.createClass({
183
234
dataField = "amount"
184
235
>
185
236
Amount
186
- </ TableHeaderColumn >
237
+ </ TableHeaderColumn >
238
+ < TableHeaderColumn
239
+ dataField = "gross"
240
+ >
241
+ Gross Amount
242
+ </ TableHeaderColumn >
187
243
< TableHeaderColumn
188
244
dataField = "payer_email"
189
245
>
@@ -202,6 +258,15 @@ var Checkouts = React.createClass({
202
258
</ TableHeaderColumn >
203
259
</ BootstrapTable >
204
260
</ Row >
261
+ < Row >
262
+ < div className = "pull-right" >
263
+ < Button
264
+ id = "fetchMoreCheckouts"
265
+ onClick = { this . fetchMoreCheckouts }
266
+ bsStyle = "primary"
267
+ > Get More Checkouts</ Button >
268
+ </ div >
269
+ </ Row >
205
270
{ this . buildModal ( ) }
206
271
</ div >
207
272
) ;
@@ -213,6 +278,7 @@ const mapStateToProps = (state) => {
213
278
return {
214
279
checkoutInfo :state . wepay_checkout . checkout . checkoutInfo ,
215
280
email : state . wepay_user . searchedUser ,
281
+ account_id : state . wepay_account . searchedAccount . account_id ,
216
282
error : state . errors . info ,
217
283
submitted_refund : state . wepay_checkout . checkout . submitted_refund ,
218
284
successful_refund : state . wepay_checkout . checkout . successful_refund ,
0 commit comments