BIN
src/.DS_Store
vendored
BIN
src/.DS_Store
vendored
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState } from "react";
|
||||||
import Col from "react-bootstrap/Col";
|
import Col from "react-bootstrap/Col";
|
||||||
import Form from "react-bootstrap/Form";
|
import Form from "react-bootstrap/Form";
|
||||||
import Row from "react-bootstrap/Row";
|
import Row from "react-bootstrap/Row";
|
||||||
@@ -10,7 +10,6 @@ import TextInput from "../../pageElements/TextInput";
|
|||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import { collection, setDoc, doc } from "firebase/firestore";
|
import { collection, setDoc, doc } from "firebase/firestore";
|
||||||
import { splitEvery } from "../../Utils/Array";
|
import { splitEvery } from "../../Utils/Array";
|
||||||
import PaymentModal from "../Modals/PaymentModal";
|
|
||||||
import {
|
import {
|
||||||
getFormDataDefaults,
|
getFormDataDefaults,
|
||||||
getValidatedFormData,
|
getValidatedFormData,
|
||||||
@@ -19,26 +18,17 @@ import {
|
|||||||
} 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 "../../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 [isMobile, setIsMobile] = useState(window.innerWidth < 440);
|
|
||||||
useEffect(() => {
|
|
||||||
setIsMobile(window.innerWidth < 440);
|
|
||||||
});
|
|
||||||
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);
|
||||||
if (newData !== null) {
|
if (newData !== null) {
|
||||||
@@ -46,13 +36,6 @@ 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);
|
||||||
@@ -60,13 +43,6 @@ const SignupPage = () => {
|
|||||||
return hasErrors ? null : objectMap(({ value }) => value, newData);
|
return hasErrors ? null : objectMap(({ value }) => value, newData);
|
||||||
};
|
};
|
||||||
|
|
||||||
const validatePaymentData = () => {
|
|
||||||
const newData = getValidatedFormData(data, signupfields);
|
|
||||||
const hasErrors = isFormDataHasErrors(newData);
|
|
||||||
setPaymentdata(newData);
|
|
||||||
return hasErrors ? null : objectMap(({ value }) => value, newData);
|
|
||||||
};
|
|
||||||
|
|
||||||
async function saveUserData(authId, dataValues) {
|
async function saveUserData(authId, dataValues) {
|
||||||
const appUserId = uuidv4();
|
const appUserId = uuidv4();
|
||||||
const firmId = uuidv4();
|
const firmId = uuidv4();
|
||||||
@@ -110,25 +86,15 @@ const SignupPage = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleStripePaymentAuthorization(paymentDataValues) {
|
|
||||||
console.log(paymentDataValues);
|
|
||||||
// Stripe API calls, etc
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSignup = async (e) => {
|
const handleSignup = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const paymentDataValues = validatePaymentData();
|
|
||||||
if (paymentDataValues === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
const paymentSuccess = handleStripePaymentAuthorization(paymentDataValues);
|
|
||||||
|
|
||||||
if (paymentSuccess) {
|
|
||||||
if (isBusy) {
|
if (isBusy) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const dataValues = validateData();
|
||||||
|
if (dataValues === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
setIsBusy(true);
|
setIsBusy(true);
|
||||||
try {
|
try {
|
||||||
const userCredential = await createUserWithEmailAndPassword(
|
const userCredential = await createUserWithEmailAndPassword(
|
||||||
@@ -145,80 +111,6 @@ const SignupPage = () => {
|
|||||||
error.message || "Sorry, something went wrong. Please try again."
|
error.message || "Sorry, something went wrong. Please try again."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleProceedToPayment = () => {
|
|
||||||
/*
|
|
||||||
const dataValues = validateData();
|
|
||||||
if (dataValues === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
setShowPaymentModal(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCancel = () => {
|
|
||||||
setShowPaymentModal(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const MobileForm = () => {
|
|
||||||
return splitEvery(
|
|
||||||
Object.keys(signupfields).slice(0, -2),
|
|
||||||
fieldsChunkSize
|
|
||||||
).map((names, j) => (
|
|
||||||
<Col key={`row${j}`}>
|
|
||||||
{names.map((name, i) => (
|
|
||||||
<Col
|
|
||||||
key={`${name}${i + fieldsChunkSize * j}`}
|
|
||||||
className="signup-mobile-column"
|
|
||||||
>
|
|
||||||
<TextInput
|
|
||||||
name={name}
|
|
||||||
value={data[name].value}
|
|
||||||
onChange={(e) => handleChangeInput(e, name)}
|
|
||||||
error={data[name].error}
|
|
||||||
message={data[name].message}
|
|
||||||
label={
|
|
||||||
data[name].value.length === 0 ? signupfields[name].label : ""
|
|
||||||
}
|
|
||||||
type={signupfields[name].type}
|
|
||||||
values={signupfields[name].values}
|
|
||||||
disabled={isBusy}
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
))}
|
|
||||||
</Col>
|
|
||||||
));
|
|
||||||
};
|
|
||||||
|
|
||||||
const DesktopForm = () => {
|
|
||||||
return splitEvery(
|
|
||||||
Object.keys(signupfields).slice(0, -2),
|
|
||||||
fieldsChunkSize
|
|
||||||
).map((names, j) => (
|
|
||||||
<Row key={`row${j}`}>
|
|
||||||
{names.map((name, i) => (
|
|
||||||
<Col key={`${name}${i + fieldsChunkSize * j}`} className="mb-3">
|
|
||||||
{console.log("data", data)}
|
|
||||||
<TextInput
|
|
||||||
name={name}
|
|
||||||
value={data[name].value}
|
|
||||||
onChange={(e) => handleChangeInput(e, name)}
|
|
||||||
error={data[name].error}
|
|
||||||
message={data[name].message}
|
|
||||||
label={
|
|
||||||
data[name].value.length === 0 ? signupfields[name].label : ""
|
|
||||||
}
|
|
||||||
type={signupfields[name].type}
|
|
||||||
values={signupfields[name].values}
|
|
||||||
disabled={isBusy}
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
))}
|
|
||||||
</Row>
|
|
||||||
));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -228,7 +120,32 @@ const SignupPage = () => {
|
|||||||
<h1 className="signup-header-text">Create a Novodraft account</h1>
|
<h1 className="signup-header-text">Create a Novodraft account</h1>
|
||||||
</div>
|
</div>
|
||||||
<Form className="signup-form">
|
<Form className="signup-form">
|
||||||
{isMobile ? <MobileForm /> : <DesktopForm />}
|
{splitEvery(
|
||||||
|
Object.keys(signupfields).slice(0, -2),
|
||||||
|
fieldsChunkSize
|
||||||
|
).map((names, j) => (
|
||||||
|
<Row key={`row${j}`}>
|
||||||
|
{names.map((name, i) => (
|
||||||
|
<Col key={`${name}${i + fieldsChunkSize * j}`} className="mb-3">
|
||||||
|
<TextInput
|
||||||
|
name={name}
|
||||||
|
value={data[name].value}
|
||||||
|
onChange={(e) => handleChangeInput(e, name)}
|
||||||
|
error={data[name].error}
|
||||||
|
message={data[name].message}
|
||||||
|
label={
|
||||||
|
data[name].value.length === 0
|
||||||
|
? signupfields[name].label
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
type={signupfields[name].type}
|
||||||
|
values={signupfields[name].values}
|
||||||
|
disabled={isBusy}
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
))}
|
||||||
|
</Row>
|
||||||
|
))}
|
||||||
<Row>
|
<Row>
|
||||||
<Col className="mb-3">
|
<Col className="mb-3">
|
||||||
<TextInput
|
<TextInput
|
||||||
@@ -268,12 +185,12 @@ const SignupPage = () => {
|
|||||||
</Form>
|
</Form>
|
||||||
<div className="signup-button-box">
|
<div className="signup-button-box">
|
||||||
<Button
|
<Button
|
||||||
className="primary-button signup-proceed-button"
|
className="primary-button"
|
||||||
type="button"
|
type="button"
|
||||||
size="lg"
|
size="lg"
|
||||||
onClick={handleProceedToPayment}
|
onClick={handleSignup}
|
||||||
disabled={isBusy}
|
disabled={isBusy}
|
||||||
labelText="Proceed to Payment"
|
labelText="Create Account"
|
||||||
/>
|
/>
|
||||||
<div className="mt-3">
|
<div className="mt-3">
|
||||||
<span>
|
<span>
|
||||||
@@ -291,18 +208,6 @@ const SignupPage = () => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{showPaymentModal ? (
|
|
||||||
<PaymentModal
|
|
||||||
onCancel={handleCancel}
|
|
||||||
handleChangePaymentInput={handleChangePaymentInput}
|
|
||||||
handleSignup={handleSignup}
|
|
||||||
paymentfields={paymentfields}
|
|
||||||
setPaymentdata={setPaymentdata}
|
|
||||||
paymentdata={paymentdata}
|
|
||||||
buttonLabelText="Signup"
|
|
||||||
modalText="Annual/Monthly option description"
|
|
||||||
/>
|
|
||||||
) : null}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
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,
|
|
||||||
},
|
|
||||||
cardSecNumber: {
|
|
||||||
required: true,
|
|
||||||
label: "Card CVV Number",
|
|
||||||
minLength: 3,
|
|
||||||
maxLength: 6,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -84,7 +84,6 @@ export const getValidatedFormData = (data, fields) =>
|
|||||||
}, data);
|
}, data);
|
||||||
|
|
||||||
export const handleFormDataChange = (e, name, data, fields) => {
|
export const handleFormDataChange = (e, name, data, fields) => {
|
||||||
console.log("e", e);
|
|
||||||
const value =
|
const value =
|
||||||
(typeof e?.target?.value === "undefined" ? e.value : e.target.value) || "";
|
(typeof e?.target?.value === "undefined" ? e.value : e.target.value) || "";
|
||||||
const field = fields[name];
|
const field = fields[name];
|
||||||
|
|||||||
@@ -42,56 +42,6 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
}
|
}
|
||||||
|
.signup-btn {
|
||||||
.signup-proceed-button {
|
width: 150px;
|
||||||
width: 160px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.signup-passw-inputs {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
span {
|
|
||||||
margin-right: 6px;
|
|
||||||
}
|
|
||||||
@media only screen and (max-width: 430px) {
|
|
||||||
.signup-sub-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
margin-top: 25px;
|
|
||||||
width: 420px;
|
|
||||||
border-radius: 10px;
|
|
||||||
background-color: rgb(240, 247, 250);
|
|
||||||
border: 1px solid #e9e9e9;
|
|
||||||
}
|
|
||||||
.signup-header-text {
|
|
||||||
font-size: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.signup-form {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
margin-right: auto;
|
|
||||||
margin-left: auto;
|
|
||||||
width: 390px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.signup-mobile-column {
|
|
||||||
width: 340px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.signup-button-box {
|
|
||||||
width: 320px;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.signup-passw-inputs {
|
|
||||||
width: 370px;
|
|
||||||
}
|
|
||||||
|
|
||||||
span {
|
|
||||||
margin-right: 6px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user