@@ -14,10 +14,11 @@ import Typography from "@material-ui/core/Typography";
14
14
import Box from "@material-ui/core/Box" ;
15
15
16
16
import { postTeamPayment , postTeamRequest } from "services/teams" ;
17
- import { clearSearchedRoles , setRequestLoading } from "../../../actions" ;
17
+ import { clearSearchedRoles } from "../../../actions" ;
18
18
import StripeElement from "../StripeElement" ;
19
19
import FormField from "../FormField" ;
20
20
import SelectField from "../SelectField" ;
21
+ import ConfirmationModal from "../../../components/ConfirmationModal" ;
21
22
22
23
import "./styles.module.scss" ;
23
24
@@ -49,6 +50,7 @@ const PaymentForm = ({ calculatedAmount }) => {
49
50
const [ formValues , setFormValues ] = useState ( initialFormValues ) ;
50
51
const [ dropdownValue , setDropdownValue ] = useState ( "" ) ;
51
52
const [ processing , setProcessing ] = useState ( false ) ;
53
+ const [ requestLoading , setRequestLoading ] = useState ( false ) ;
52
54
const [ errors , setErrors ] = useState ( { } ) ;
53
55
const stripe = useStripe ( ) ;
54
56
const elements = useElements ( ) ;
@@ -114,10 +116,11 @@ const PaymentForm = ({ calculatedAmount }) => {
114
116
}
115
117
) ;
116
118
if ( payload . error ) {
117
- toastr . error ( "Payment failed" , payload . error . message ) ;
118
119
setProcessing ( false ) ;
120
+ toastr . error ( "Payment failed" , payload . error . message ) ;
119
121
} else if ( payload . paymentIntent . status === "succeeded" ) {
120
122
toastr . success ( "Payment is successful" ) ;
123
+ setRequestLoading ( true ) ;
121
124
postTeamRequest ( teamObject )
122
125
. then ( ( ) => {
123
126
setTimeout ( ( ) => {
@@ -130,7 +133,6 @@ const PaymentForm = ({ calculatedAmount }) => {
130
133
setRequestLoading ( false ) ;
131
134
toastr . error ( "Error Requesting Team" , err . message ) ;
132
135
} ) ;
133
- setProcessing ( false ) ;
134
136
}
135
137
} )
136
138
. catch ( ( err ) => {
@@ -153,51 +155,54 @@ const PaymentForm = ({ calculatedAmount }) => {
153
155
154
156
const classes = useStyles ( ) ;
155
157
return (
156
- < form onSubmit = { handleFormSubmit } >
157
- < FormField
158
- label = "Email"
159
- name = "email"
160
- handleInputValue = { handleInputValue }
161
- errors = { errors }
162
- />
163
- < Box m = { 1 } >
164
- < Typography classes = { { root : classes . typography } } >
165
- Card Information
166
- </ Typography >
167
- </ Box >
168
- < StripeElement element = { CardNumberElement } icon = "card" />
169
- < div styleName = "horizontal" >
170
- < StripeElement element = { CardExpiryElement } width = "150px" />
171
- < StripeElement
172
- className = { classes . cvc }
173
- element = { CardCvcElement }
174
- icon = "cvc"
175
- width = "112px"
158
+ < >
159
+ < form onSubmit = { handleFormSubmit } >
160
+ < FormField
161
+ label = "Email"
162
+ name = "email"
163
+ handleInputValue = { handleInputValue }
164
+ errors = { errors }
165
+ />
166
+ < Box m = { 1 } >
167
+ < Typography classes = { { root : classes . typography } } >
168
+ Card Information
169
+ </ Typography >
170
+ </ Box >
171
+ < StripeElement element = { CardNumberElement } icon = "card" />
172
+ < div styleName = "horizontal" >
173
+ < StripeElement element = { CardExpiryElement } width = "150px" />
174
+ < StripeElement
175
+ className = { classes . cvc }
176
+ element = { CardCvcElement }
177
+ icon = "cvc"
178
+ width = "112px"
179
+ />
180
+ </ div >
181
+ < FormField
182
+ label = "Name on the card"
183
+ name = "name"
184
+ handleInputValue = { handleInputValue }
185
+ errors = { errors }
186
+ />
187
+ < SelectField
188
+ handleDropdown = { handleDropdown }
189
+ dropdownValue = { dropdownValue }
190
+ />
191
+ < FormField
192
+ label = "Zip code"
193
+ name = "zipcode"
194
+ handleInputValue = { handleInputValue }
195
+ errors = { errors }
176
196
/>
177
- </ div >
178
- < FormField
179
- label = "Name on the card"
180
- name = "name"
181
- handleInputValue = { handleInputValue }
182
- errors = { errors }
183
- />
184
- < SelectField
185
- handleDropdown = { handleDropdown }
186
- dropdownValue = { dropdownValue }
187
- />
188
- < FormField
189
- label = "Zip code"
190
- name = "zipcode"
191
- handleInputValue = { handleInputValue }
192
- errors = { errors }
193
- />
194
- < button
195
- type = "submit"
196
- styleName = { `button ${ ! formIsValid ( ) ? "disabled" : "" } ` }
197
- >
198
- { processing ? "Payment Processing" : `Pay $${ calculatedAmount } ` }
199
- </ button >
200
- </ form >
197
+ < button
198
+ type = "submit"
199
+ styleName = { `button ${ ! formIsValid ( ) ? "disabled" : "" } ` }
200
+ >
201
+ { processing ? "Payment Processing" : `Pay $${ calculatedAmount } ` }
202
+ </ button >
203
+ </ form >
204
+ < ConfirmationModal open = { requestLoading } isLoading = { requestLoading } />
205
+ </ >
201
206
) ;
202
207
} ;
203
208
0 commit comments