@@ -15,15 +15,14 @@ import {
|
||||
import "../../styles/modals.scss";
|
||||
|
||||
const PaymentModal = ({
|
||||
onCancel,
|
||||
buttonLabelText,
|
||||
modalText,
|
||||
isBusy,
|
||||
handleChangePaymentInput,
|
||||
handleSignup,
|
||||
paymentData,
|
||||
paymentfields,
|
||||
paymentdata,
|
||||
setPaymentdata,
|
||||
handleChangePaymentInput,
|
||||
modalText,
|
||||
handleSignup,
|
||||
setShowPaymentModal,
|
||||
}) => {
|
||||
const fieldsChunkSize = 2;
|
||||
|
||||
@@ -33,15 +32,15 @@ const PaymentModal = ({
|
||||
<Row key={`row${j}`}>
|
||||
{names.map((name, i) => (
|
||||
<Row key={`${name}${i + fieldsChunkSize * j}`} className="mb-3">
|
||||
{console.log("paymentdata", paymentdata)}
|
||||
{console.log("paymentdata", paymentData)}
|
||||
<TextInput
|
||||
name={name}
|
||||
value={paymentdata[name].value}
|
||||
value={paymentData[name].value}
|
||||
onChange={(e) => handleChangePaymentInput(e, name)}
|
||||
error={paymentdata[name].error}
|
||||
message={paymentdata[name].message}
|
||||
error={paymentData[name].error}
|
||||
message={paymentData[name].message}
|
||||
label={
|
||||
paymentdata[name].value.length === 0
|
||||
paymentData[name].value.length === 0
|
||||
? paymentfields[name].label
|
||||
: ""
|
||||
}
|
||||
@@ -57,7 +56,7 @@ const PaymentModal = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show="true" onHide={onCancel} size="lg">
|
||||
<Modal show="true" size="lg">
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>Enter Payment Card Information</Modal.Title>
|
||||
</Modal.Header>
|
||||
@@ -71,7 +70,7 @@ const PaymentModal = ({
|
||||
<Button
|
||||
disabled={isBusy}
|
||||
className="secondary-button"
|
||||
onClick={onCancel}
|
||||
onClick={() => setShowPaymentModal(false)}
|
||||
labelText="Cancel"
|
||||
/>
|
||||
<Button
|
||||
@@ -86,3 +85,7 @@ const PaymentModal = ({
|
||||
};
|
||||
|
||||
export default PaymentModal;
|
||||
|
||||
/*
|
||||
onHide={onCancel}
|
||||
*/
|
||||
|
||||
@@ -17,17 +17,21 @@ import {
|
||||
isFormDataHasErrors,
|
||||
} from "../../Utils/Form";
|
||||
import { objectMap } from "../../Utils/Object";
|
||||
import { signupfields } from "../../Constants/Fields/Signupfields";
|
||||
import { signupfields } from "../../Constants/Fields/SignupFields";
|
||||
import { paymentfields } from "../../Constants/Fields/PaymentFields";
|
||||
import PaymentModal from "../Modals/PaymentModal";
|
||||
import "../../styles/signup.scss";
|
||||
|
||||
const SignupPage = () => {
|
||||
const navigate = useNavigate();
|
||||
const [notice, setNotice] = useState("");
|
||||
|
||||
const fieldsChunkSize = 2;
|
||||
|
||||
const [isBusy, setIsBusy] = useState(false);
|
||||
const [data, setData] = useState(getFormDataDefaults(signupfields));
|
||||
const [paymentData, setPaymentData] = useState(
|
||||
getFormDataDefaults(paymentfields)
|
||||
);
|
||||
const [showPaymentModal, setShowPaymentModal] = useState(false);
|
||||
|
||||
const handleChangeInput = (e, name) => {
|
||||
const newData = handleFormDataChange(e, name, data, signupfields);
|
||||
@@ -36,6 +40,13 @@ const SignupPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleChangePaymentInput = (e, name) => {
|
||||
const newData = handleFormDataChange(e, name, data, paymentfields);
|
||||
if (newData !== null) {
|
||||
setPaymentData(newData);
|
||||
}
|
||||
};
|
||||
|
||||
const validateData = () => {
|
||||
const newData = getValidatedFormData(data, signupfields);
|
||||
const hasErrors = isFormDataHasErrors(newData);
|
||||
@@ -43,6 +54,13 @@ const SignupPage = () => {
|
||||
return hasErrors ? null : objectMap(({ value }) => value, newData);
|
||||
};
|
||||
|
||||
const validatePaymentData = () => {
|
||||
const newPaymentData = ""; // getValidatedFormData(data, signupfields);
|
||||
const hasErrors = isFormDataHasErrors(newPaymentData);
|
||||
setPaymentData(newPaymentData);
|
||||
return hasErrors ? null : objectMap(({ value }) => value, newPaymentData);
|
||||
};
|
||||
|
||||
async function saveUserData(authId, dataValues) {
|
||||
const appUserId = uuidv4();
|
||||
const firmId = uuidv4();
|
||||
@@ -86,7 +104,7 @@ const SignupPage = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleSignup = async (e) => {
|
||||
const handleProceedToPayment = (e) => {
|
||||
e.preventDefault();
|
||||
if (isBusy) {
|
||||
return;
|
||||
@@ -95,21 +113,43 @@ const SignupPage = () => {
|
||||
if (dataValues === null) {
|
||||
return;
|
||||
}
|
||||
setShowPaymentModal(true);
|
||||
};
|
||||
|
||||
async function handleStripeAuthorization(paymentDataValues) {
|
||||
//Do calls to Stripe API
|
||||
// if success, return some truthy value or
|
||||
// handleFailure()
|
||||
}
|
||||
|
||||
const handleSignUp = async (e) => {
|
||||
e.preventDefault();
|
||||
const paymentDataValues = validatePaymentData();
|
||||
if (paymentDataValues === null) {
|
||||
return;
|
||||
}
|
||||
const dataValues = validateData();
|
||||
if (dataValues === null) {
|
||||
return;
|
||||
}
|
||||
setIsBusy(true);
|
||||
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."
|
||||
);
|
||||
const paymentSuccess = "true"; // 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."
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -188,9 +228,9 @@ const SignupPage = () => {
|
||||
className="primary-button"
|
||||
type="button"
|
||||
size="lg"
|
||||
onClick={handleSignup}
|
||||
onClick={handleProceedToPayment}
|
||||
disabled={isBusy}
|
||||
labelText="Create Account"
|
||||
labelText="Proceed to Payment"
|
||||
/>
|
||||
<div className="mt-3">
|
||||
<span>
|
||||
@@ -208,6 +248,17 @@ const SignupPage = () => {
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{showPaymentModal ? (
|
||||
<PaymentModal
|
||||
paymentData={paymentData}
|
||||
paymentfields={paymentfields}
|
||||
setShowPaymentModal={setShowPaymentModal}
|
||||
handleChangePaymentInput={handleChangePaymentInput}
|
||||
handleSignUp={handleSignUp}
|
||||
/>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
16
src/Constants/Fields/PaymentFields.js
Normal file
16
src/Constants/Fields/PaymentFields.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export const paymentfields = {
|
||||
cardFirstName: { required: true, label: "Card First Name", maxLength: 45 },
|
||||
cardLastName: { required: true, label: "Card Last Name", maxLength: 45 },
|
||||
cardNumber: {
|
||||
required: true,
|
||||
label: "Card Number",
|
||||
minLength: 16,
|
||||
maxLength: 16,
|
||||
},
|
||||
cardCvvCode: {
|
||||
required: true,
|
||||
label: "Card CVV Number",
|
||||
maxLength: 5,
|
||||
type: "cvv",
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user