Compare commits
No commits in common. "059265098573f4c75a526a95c90fe6de904b2c03" and "46a18112cc6100005c7c55d0b2603cf2d6d63cc9" have entirely different histories.
0592650985
...
46a18112cc
2 changed files with 6 additions and 103 deletions
|
@ -1,96 +1,28 @@
|
||||||
import { useState, useRef } from 'react';
|
|
||||||
|
|
||||||
const CentsInADollar = 100;
|
|
||||||
const DefaultTotal = 0;
|
|
||||||
|
|
||||||
function costToReadable(cost) {
|
function costToReadable(cost) {
|
||||||
return cost / CentsInADollar;
|
const centsInADollar = 100;
|
||||||
|
return cost / centsInADollar;
|
||||||
}
|
}
|
||||||
|
|
||||||
function BandForm({ band }) {
|
function BandForm({ band }) {
|
||||||
const formRef = useRef(null);
|
|
||||||
const [total, setTotal] = useState(DefaultTotal);
|
|
||||||
const [formIsPending, setFormIsPending] = useState(false);
|
|
||||||
|
|
||||||
function purchase(formData) {
|
|
||||||
console.log(formData);
|
|
||||||
setFormIsPending(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ticketQuantityChanged() {
|
|
||||||
const formData = new FormData(formRef.current);
|
|
||||||
const ticketQuantities = formData.getAll('ticketQuantity');
|
|
||||||
|
|
||||||
|
|
||||||
setTotal(
|
|
||||||
ticketQuantities.reduce((total, quantity, index) => {
|
|
||||||
return total += (band.ticketTypes[index].cost * quantity);
|
|
||||||
}, 0)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="form" action={purchase} ref={formRef}>
|
<form className="form">
|
||||||
<h2>Select Tickets</h2>
|
<h2>Select Tickets</h2>
|
||||||
|
|
||||||
{band.ticketTypes.map(({type, name, description, cost}, index) => (
|
{band.ticketTypes.map(({type, name, description, cost}) => (
|
||||||
<div className="ticketWrapper" key={name}>
|
<div className="ticketWrapper" key={name}>
|
||||||
<div className="ticket">
|
<div className="ticket">
|
||||||
<div className="ticketDetails">
|
<div className="ticketDetails">
|
||||||
<h3 id={name}>{name}</h3>
|
<h3>{name}</h3>
|
||||||
<p>{description}</p>
|
<p>{description}</p>
|
||||||
<h4>${costToReadable(cost)}</h4>
|
<h4>${costToReadable(cost)}</h4>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{/* TODO: describedby cost and description */}
|
<input type="number" step="1" />
|
||||||
<input
|
|
||||||
labelledby={name}
|
|
||||||
defaultValue="0"
|
|
||||||
name="ticketQuantity"
|
|
||||||
id={name}
|
|
||||||
type="number"
|
|
||||||
step="1"
|
|
||||||
onChange={ticketQuantityChanged}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
<div className="total">
|
|
||||||
<h3>Total</h3>
|
|
||||||
<p aria-live="polite">${costToReadable(total)}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="information">
|
|
||||||
<div className="form-row">
|
|
||||||
<input
|
|
||||||
name="first_name"
|
|
||||||
label="First Name"
|
|
||||||
placeholder="First Name"
|
|
||||||
type="text"
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
name="last_name"
|
|
||||||
label="Last Name"
|
|
||||||
placeholder="Last Name"
|
|
||||||
type="text"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<input
|
|
||||||
name="address"
|
|
||||||
label="Address"
|
|
||||||
placeholder="Address"
|
|
||||||
type="text"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<fieldset className="payment">
|
|
||||||
<legend>Payment Details</legend>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<button type="submit" disabled={formIsPending}>Get Tickets</button>
|
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
@import "./reset.css";
|
@import "./reset.css";
|
||||||
@import "./variables.css";
|
@import "./variables.css";
|
||||||
|
|
||||||
* {
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
html {
|
html {
|
||||||
color: var(--color-text);
|
color: var(--color-text);
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||||
|
@ -16,12 +12,6 @@ html {
|
||||||
font-size: var(--font-base);
|
font-size: var(--font-base);
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
|
||||||
width: 100%;
|
|
||||||
padding: 1rem;
|
|
||||||
font-size: var(--font-base);
|
|
||||||
}
|
|
||||||
|
|
||||||
hr {
|
hr {
|
||||||
border-color: var(--color-text);
|
border-color: var(--color-text);
|
||||||
border-width: 1px;
|
border-width: 1px;
|
||||||
|
@ -94,23 +84,4 @@ h4 {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: var(--spacing-md);
|
gap: var(--spacing-md);
|
||||||
}
|
}
|
||||||
|
|
||||||
.total {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: space-between;
|
|
||||||
font-size: var(--font-lg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-row {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
gap: var(--spacing-md);
|
|
||||||
}
|
|
||||||
|
|
||||||
.information, .payment {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: var(--spacing-md);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue