diff --git a/src/Components/Modals/PaymentModal.js b/src/Components/Modals/PaymentModal.js index b538d50..46d58ba 100644 --- a/src/Components/Modals/PaymentModal.js +++ b/src/Components/Modals/PaymentModal.js @@ -23,10 +23,14 @@ const PaymentModal = ({ const ModalForm = () => { return splitEvery(Object.keys(paymentfields), fieldsChunkSize).map( (names, j) => ( - + {names.map((name, i) => ( - + handleChangePaymentInput(e, name)} diff --git a/src/Components/SignupPage/SignupPage.js b/src/Components/SignupPage/SignupPage.js index 97e3824..dd887b5 100644 --- a/src/Components/SignupPage/SignupPage.js +++ b/src/Components/SignupPage/SignupPage.js @@ -42,7 +42,6 @@ const SignupPage = () => { }; const handleChangePaymentInput = (e, name) => { - console.log("e, name", e, name); const newPaymentData = handleFormDataChange( e, name, @@ -62,7 +61,6 @@ const SignupPage = () => { }; const validatePaymentData = () => { - console.log("paymentData", paymentData); const newPaymentData = getValidatedFormData(paymentData, paymentfields); const hasErrors = isFormDataHasErrors(newPaymentData); setPaymentData(newPaymentData); @@ -114,7 +112,7 @@ const SignupPage = () => { const handleProceedToPayment = (e) => { e.preventDefault(); - /* + if (isBusy) { return; } @@ -122,7 +120,6 @@ const SignupPage = () => { if (dataValues === null) { return; } - */ setShowPaymentModal(true); }; @@ -139,7 +136,31 @@ const SignupPage = () => { if (paymentDataValues === null) { return; } - console.log("paymentDataValues", paymentDataValues); + const dataValues = validateData(); + if (dataValues === null) { + return; + } + setIsBusy(true); + const paymentSuccess = handleStripeAuthorization(paymentDataValues); + if (paymentSuccess) { + try { + const userCredential = await createUserWithEmailAndPassword( + auth, + dataValues.email, + dataValues.password + ); + const user = userCredential.user; + await saveUserData(user.uid, dataValues); + navigate("/"); + } catch (error) { + setIsBusy(false); + setNotice( + error.message || "Sorry, something went wrong. Please try again." + ); + } + } else { + //handle payment failure + } }; return ( @@ -240,6 +261,7 @@ const SignupPage = () => { {showPaymentModal ? (