@@ -14,10 +14,11 @@ import Typography from "@material-ui/core/Typography";
1414import Box from "@material-ui/core/Box" ;
1515
1616import { postTeamPayment , postTeamRequest } from "services/teams" ;
17- import { clearSearchedRoles , setRequestLoading } from "../../../actions" ;
17+ import { clearSearchedRoles } from "../../../actions" ;
1818import StripeElement from "../StripeElement" ;
1919import FormField from "../FormField" ;
2020import SelectField from "../SelectField" ;
21+ import ConfirmationModal from "../../../components/ConfirmationModal" ;
2122
2223import "./styles.module.scss" ;
2324
@@ -49,6 +50,7 @@ const PaymentForm = ({ calculatedAmount }) => {
4950 const [ formValues , setFormValues ] = useState ( initialFormValues ) ;
5051 const [ dropdownValue , setDropdownValue ] = useState ( "" ) ;
5152 const [ processing , setProcessing ] = useState ( false ) ;
53+ const [ requestLoading , setRequestLoading ] = useState ( false ) ;
5254 const [ errors , setErrors ] = useState ( { } ) ;
5355 const stripe = useStripe ( ) ;
5456 const elements = useElements ( ) ;
@@ -114,10 +116,11 @@ const PaymentForm = ({ calculatedAmount }) => {
114116 }
115117 ) ;
116118 if ( payload . error ) {
117- toastr . error ( "Payment failed" , payload . error . message ) ;
118119 setProcessing ( false ) ;
120+ toastr . error ( "Payment failed" , payload . error . message ) ;
119121 } else if ( payload . paymentIntent . status === "succeeded" ) {
120122 toastr . success ( "Payment is successful" ) ;
123+ setRequestLoading ( true ) ;
121124 postTeamRequest ( teamObject )
122125 . then ( ( ) => {
123126 setTimeout ( ( ) => {
@@ -130,7 +133,6 @@ const PaymentForm = ({ calculatedAmount }) => {
130133 setRequestLoading ( false ) ;
131134 toastr . error ( "Error Requesting Team" , err . message ) ;
132135 } ) ;
133- setProcessing ( false ) ;
134136 }
135137 } )
136138 . catch ( ( err ) => {
@@ -153,51 +155,54 @@ const PaymentForm = ({ calculatedAmount }) => {
153155
154156 const classes = useStyles ( ) ;
155157 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 }
176196 />
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+ </ >
201206 ) ;
202207} ;
203208
0 commit comments