Compare commits
2 commits
4b9e0627be
...
3f45514fd8
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3f45514fd8 | ||
![]() |
71c24d1cec |
1 changed files with 38 additions and 5 deletions
|
@ -4,18 +4,51 @@ 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) {
|
||||||
console.log(formData);
|
if (formRef.current.checkValidity() === false) {
|
||||||
|
console.warn('Form is invalid');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setFormIsPending(true);
|
setFormIsPending(true);
|
||||||
|
submitPurchase(normalizePurchaseData(formData));
|
||||||
}
|
}
|
||||||
|
|
||||||
function ticketQuantityChanged() {
|
function ticketQuantityChanged() {
|
||||||
|
@ -81,9 +114,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"
|
||||||
|
@ -94,10 +127,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"
|
||||||
|
@ -105,9 +138,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"
|
||||||
|
@ -116,9 +149,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