@@ -15,15 +15,14 @@ import {
|
|||||||
import "../../styles/modals.scss";
|
import "../../styles/modals.scss";
|
||||||
|
|
||||||
const PaymentModal = ({
|
const PaymentModal = ({
|
||||||
onCancel,
|
|
||||||
buttonLabelText,
|
buttonLabelText,
|
||||||
modalText,
|
|
||||||
isBusy,
|
isBusy,
|
||||||
handleChangePaymentInput,
|
paymentData,
|
||||||
handleSignup,
|
|
||||||
paymentfields,
|
paymentfields,
|
||||||
paymentdata,
|
handleChangePaymentInput,
|
||||||
setPaymentdata,
|
modalText,
|
||||||
|
handleSignup,
|
||||||
|
setShowPaymentModal,
|
||||||
}) => {
|
}) => {
|
||||||
const fieldsChunkSize = 2;
|
const fieldsChunkSize = 2;
|
||||||
|
|
||||||
@@ -33,15 +32,15 @@ const PaymentModal = ({
|
|||||||
<Row key={`row${j}`}>
|
<Row key={`row${j}`}>
|
||||||
{names.map((name, i) => (
|
{names.map((name, i) => (
|
||||||
<Row key={`${name}${i + fieldsChunkSize * j}`} className="mb-3">
|
<Row key={`${name}${i + fieldsChunkSize * j}`} className="mb-3">
|
||||||
{console.log("paymentdata", paymentdata)}
|
{console.log("paymentdata", paymentData)}
|
||||||
<TextInput
|
<TextInput
|
||||||
name={name}
|
name={name}
|
||||||
value={paymentdata[name].value}
|
value={paymentData[name].value}
|
||||||
onChange={(e) => handleChangePaymentInput(e, name)}
|
onChange={(e) => handleChangePaymentInput(e, name)}
|
||||||
error={paymentdata[name].error}
|
error={paymentData[name].error}
|
||||||
message={paymentdata[name].message}
|
message={paymentData[name].message}
|
||||||
label={
|
label={
|
||||||
paymentdata[name].value.length === 0
|
paymentData[name].value.length === 0
|
||||||
? paymentfields[name].label
|
? paymentfields[name].label
|
||||||
: ""
|
: ""
|
||||||
}
|
}
|
||||||
@@ -57,7 +56,7 @@ const PaymentModal = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal show="true" onHide={onCancel} size="lg">
|
<Modal show="true" size="lg">
|
||||||
<Modal.Header closeButton>
|
<Modal.Header closeButton>
|
||||||
<Modal.Title>Enter Payment Card Information</Modal.Title>
|
<Modal.Title>Enter Payment Card Information</Modal.Title>
|
||||||
</Modal.Header>
|
</Modal.Header>
|
||||||
@@ -71,7 +70,7 @@ const PaymentModal = ({
|
|||||||
<Button
|
<Button
|
||||||
disabled={isBusy}
|
disabled={isBusy}
|
||||||
className="secondary-button"
|
className="secondary-button"
|
||||||
onClick={onCancel}
|
onClick={() => setShowPaymentModal(false)}
|
||||||
labelText="Cancel"
|
labelText="Cancel"
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
@@ -86,3 +85,7 @@ const PaymentModal = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default PaymentModal;
|
export default PaymentModal;
|
||||||
|
|
||||||
|
/*
|
||||||
|
onHide={onCancel}
|
||||||
|
*/
|
||||||
|
|||||||
@@ -17,17 +17,21 @@ import {
|
|||||||
isFormDataHasErrors,
|
isFormDataHasErrors,
|
||||||
} from "../../Utils/Form";
|
} from "../../Utils/Form";
|
||||||
import { objectMap } from "../../Utils/Object";
|
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";
|
import "../../styles/signup.scss";
|
||||||
|
|
||||||
const SignupPage = () => {
|
const SignupPage = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [notice, setNotice] = useState("");
|
const [notice, setNotice] = useState("");
|
||||||
|
|
||||||
const fieldsChunkSize = 2;
|
const fieldsChunkSize = 2;
|
||||||
|
|
||||||
const [isBusy, setIsBusy] = useState(false);
|
const [isBusy, setIsBusy] = useState(false);
|
||||||
const [data, setData] = useState(getFormDataDefaults(signupfields));
|
const [data, setData] = useState(getFormDataDefaults(signupfields));
|
||||||
|
const [paymentData, setPaymentData] = useState(
|
||||||
|
getFormDataDefaults(paymentfields)
|
||||||
|
);
|
||||||
|
const [showPaymentModal, setShowPaymentModal] = useState(false);
|
||||||
|
|
||||||
const handleChangeInput = (e, name) => {
|
const handleChangeInput = (e, name) => {
|
||||||
const newData = handleFormDataChange(e, name, data, signupfields);
|
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 validateData = () => {
|
||||||
const newData = getValidatedFormData(data, signupfields);
|
const newData = getValidatedFormData(data, signupfields);
|
||||||
const hasErrors = isFormDataHasErrors(newData);
|
const hasErrors = isFormDataHasErrors(newData);
|
||||||
@@ -43,6 +54,13 @@ const SignupPage = () => {
|
|||||||
return hasErrors ? null : objectMap(({ value }) => value, newData);
|
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) {
|
async function saveUserData(authId, dataValues) {
|
||||||
const appUserId = uuidv4();
|
const appUserId = uuidv4();
|
||||||
const firmId = uuidv4();
|
const firmId = uuidv4();
|
||||||
@@ -86,7 +104,7 @@ const SignupPage = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSignup = async (e) => {
|
const handleProceedToPayment = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (isBusy) {
|
if (isBusy) {
|
||||||
return;
|
return;
|
||||||
@@ -95,21 +113,43 @@ const SignupPage = () => {
|
|||||||
if (dataValues === null) {
|
if (dataValues === null) {
|
||||||
return;
|
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);
|
setIsBusy(true);
|
||||||
try {
|
const paymentSuccess = "true"; // handleStripeAuthorization(paymentDataValues)
|
||||||
const userCredential = await createUserWithEmailAndPassword(
|
if (paymentSuccess) {
|
||||||
auth,
|
try {
|
||||||
dataValues.email,
|
const userCredential = await createUserWithEmailAndPassword(
|
||||||
dataValues.password
|
auth,
|
||||||
);
|
dataValues.email,
|
||||||
const user = userCredential.user;
|
dataValues.password
|
||||||
await saveUserData(user.uid, dataValues);
|
);
|
||||||
navigate("/");
|
const user = userCredential.user;
|
||||||
} catch (error) {
|
await saveUserData(user.uid, dataValues);
|
||||||
setIsBusy(false);
|
navigate("/");
|
||||||
setNotice(
|
} catch (error) {
|
||||||
error.message || "Sorry, something went wrong. Please try again."
|
setIsBusy(false);
|
||||||
);
|
setNotice(
|
||||||
|
error.message || "Sorry, something went wrong. Please try again."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -188,9 +228,9 @@ const SignupPage = () => {
|
|||||||
className="primary-button"
|
className="primary-button"
|
||||||
type="button"
|
type="button"
|
||||||
size="lg"
|
size="lg"
|
||||||
onClick={handleSignup}
|
onClick={handleProceedToPayment}
|
||||||
disabled={isBusy}
|
disabled={isBusy}
|
||||||
labelText="Create Account"
|
labelText="Proceed to Payment"
|
||||||
/>
|
/>
|
||||||
<div className="mt-3">
|
<div className="mt-3">
|
||||||
<span>
|
<span>
|
||||||
@@ -208,6 +248,17 @@ const SignupPage = () => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
{showPaymentModal ? (
|
||||||
|
<PaymentModal
|
||||||
|
paymentData={paymentData}
|
||||||
|
paymentfields={paymentfields}
|
||||||
|
setShowPaymentModal={setShowPaymentModal}
|
||||||
|
handleChangePaymentInput={handleChangePaymentInput}
|
||||||
|
handleSignUp={handleSignUp}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
</div>
|
</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