Compare commits
No commits in common. "3f45514fd850c3be2fab29e40bf42c19f28489e2" and "4b9e0627be5e62001afdff5b0933805273046ca9" have entirely different histories.
3f45514fd8
...
4b9e0627be
1 changed files with 5 additions and 38 deletions
|
@ -4,51 +4,18 @@ import { IMaskInput } from 'react-imask';
|
||||||
const CentsInADollar = 100;
|
const CentsInADollar = 100;
|
||||||
const DefaultTotal = 0;
|
const DefaultTotal = 0;
|
||||||
|
|
||||||
function deepClone(data) {
|
|
||||||
// TODO: replace with structuredClone?
|
|
||||||
return JSON.parse(
|
|
||||||
JSON.stringify(
|
|
||||||
data
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function costToReadable(cost) {
|
function costToReadable(cost) {
|
||||||
return cost / CentsInADollar;
|
return cost / CentsInADollar;
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitPurchase(data) {
|
|
||||||
// TODO: Send to backend
|
|
||||||
console.log(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function BandForm({ band }) {
|
function BandForm({ band }) {
|
||||||
const formRef = useRef(null);
|
const formRef = useRef(null);
|
||||||
const [total, setTotal] = useState(DefaultTotal);
|
const [total, setTotal] = useState(DefaultTotal);
|
||||||
const [formIsPending, setFormIsPending] = useState(false);
|
const [formIsPending, setFormIsPending] = useState(false);
|
||||||
|
|
||||||
function normalizePurchaseData(formData) {
|
|
||||||
const data = deepClone(Object.fromEntries(formData));
|
|
||||||
delete data.ticketQuantity;
|
|
||||||
data.tickets = formData.getAll('ticketQuantity').map((quantity, index) => {
|
|
||||||
const {cost, name} = band.ticketTypes[index];
|
|
||||||
return {
|
|
||||||
name,
|
|
||||||
quantity,
|
|
||||||
totalCost: cost * quantity,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
function purchase(formData) {
|
function purchase(formData) {
|
||||||
if (formRef.current.checkValidity() === false) {
|
console.log(formData);
|
||||||
console.warn('Form is invalid');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setFormIsPending(true);
|
setFormIsPending(true);
|
||||||
submitPurchase(normalizePurchaseData(formData));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ticketQuantityChanged() {
|
function ticketQuantityChanged() {
|
||||||
|
@ -114,9 +81,9 @@ function BandForm({ band }) {
|
||||||
type="text"
|
type="text"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/* TODO: third party library address verification */}
|
|
||||||
<input
|
<input
|
||||||
required
|
required
|
||||||
|
{/* TODO: third party library address verification */}
|
||||||
name="address"
|
name="address"
|
||||||
label="Address"
|
label="Address"
|
||||||
placeholder="Address"
|
placeholder="Address"
|
||||||
|
@ -127,10 +94,10 @@ function BandForm({ band }) {
|
||||||
<fieldset className="payment">
|
<fieldset className="payment">
|
||||||
<legend>Payment Details</legend>
|
<legend>Payment Details</legend>
|
||||||
|
|
||||||
{/* TODO: regex pattern */}
|
|
||||||
<IMaskInput
|
<IMaskInput
|
||||||
required
|
required
|
||||||
mask="0000 0000 0000 0000"
|
mask="0000 0000 0000 0000"
|
||||||
|
{/* TODO: regex pattern */}
|
||||||
name="cardNumber"
|
name="cardNumber"
|
||||||
label="Card Number"
|
label="Card Number"
|
||||||
placeholder="0000 0000 0000 0000"
|
placeholder="0000 0000 0000 0000"
|
||||||
|
@ -138,9 +105,9 @@ function BandForm({ band }) {
|
||||||
></IMaskInput>
|
></IMaskInput>
|
||||||
|
|
||||||
<div className="form-row">
|
<div className="form-row">
|
||||||
{/* TODO: regex pattern */}
|
|
||||||
<IMaskInput
|
<IMaskInput
|
||||||
required
|
required
|
||||||
|
{/* TODO: regex pattern */}
|
||||||
mask="00 / 00"
|
mask="00 / 00"
|
||||||
pattern="\d*"
|
pattern="\d*"
|
||||||
name="cardExpiration"
|
name="cardExpiration"
|
||||||
|
@ -149,9 +116,9 @@ function BandForm({ band }) {
|
||||||
type="text"
|
type="text"
|
||||||
></IMaskInput>
|
></IMaskInput>
|
||||||
|
|
||||||
{/* TODO: regex pattern */}
|
|
||||||
<IMaskInput
|
<IMaskInput
|
||||||
required
|
required
|
||||||
|
{/* TODO: regex pattern */}
|
||||||
mask={Number}
|
mask={Number}
|
||||||
name="cardCVV"
|
name="cardCVV"
|
||||||
label="Card CVV"
|
label="Card CVV"
|
||||||
|
|
Loading…
Add table
Reference in a new issue