diff --git a/src/BandForm.js b/src/BandForm.js index 21cff14..54ab1dc 100644 --- a/src/BandForm.js +++ b/src/BandForm.js @@ -1,28 +1,69 @@ +import { useState, useRef } from 'react'; + +const CentsInADollar = 100; +const DefaultTotal = 0; + function costToReadable(cost) { - const centsInADollar = 100; - return cost / centsInADollar; + return cost / CentsInADollar; } 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 ( -
); } diff --git a/src/index.css b/src/index.css index 83b9a12..8f6f0e6 100644 --- a/src/index.css +++ b/src/index.css @@ -84,4 +84,11 @@ h4 { flex-direction: column; gap: var(--spacing-md); } + + .total { + display: flex; + flex-direction: row; + justify-content: space-between; + font-size: var(--font-lg); + } }