From 662c1cb0d4137812b52bed43822e66a27a60468e Mon Sep 17 00:00:00 2001 From: Emily Neighbour Date: Mon, 19 May 2025 13:32:20 +0100 Subject: [PATCH] modal pop-up's when buying --- src/app/shop/page.tsx | 229 +++++++++++++++++++++++++++++++++++------- 1 file changed, 193 insertions(+), 36 deletions(-) diff --git a/src/app/shop/page.tsx b/src/app/shop/page.tsx index c8b7088..3665e94 100644 --- a/src/app/shop/page.tsx +++ b/src/app/shop/page.tsx @@ -189,6 +189,11 @@ const artefacts: Artefact[] = [ export default function Shop() { const [currentPage, setCurrentPage] = useState(1); const [selectedArtefact, setSelectedArtefact] = useState(null); + const [showPaymentModal, setShowPaymentModal] = useState(false); + const [artefactToBuy, setArtefactToBuy] = useState(null); + const [showThankYouModal, setShowThankYouModal] = useState(false); + const [orderNumber, setOrderNumber] = useState(null); + const artefactsPerPage = 12; const indexOfLastArtefact = currentPage * artefactsPerPage; const indexOfFirstArtefact = indexOfLastArtefact - artefactsPerPage; @@ -198,25 +203,41 @@ export default function Shop() { const conversionRates = useStoreState((state) => state.currency.conversionRates); const currencyTickers = useStoreState((state) => state.currency.tickers); - const convertPrice = useCallback((price: number, currency: Currency) => (price * conversionRates[currency]).toFixed(2), []); + const convertPrice = useCallback( + (price: number, currency: Currency) => (price * conversionRates[currency]).toFixed(2), + [conversionRates] + ); const handleNextPage = () => { - if (indexOfLastArtefact < artefacts.length) { - setCurrentPage((prev) => prev + 1); - } + if (indexOfLastArtefact < artefacts.length) setCurrentPage((prev) => prev + 1); }; const handlePreviousPage = () => { - if (currentPage > 1) { - setCurrentPage((prev) => prev - 1); - } + if (currentPage > 1) setCurrentPage((prev) => prev - 1); }; + function ArtefactCard({ artefact }: { artefact: Artefact }) { + return ( +
setSelectedArtefact(artefact)} + > + {artefact.name} +
+

{artefact.name}

+

{artefact.location}

+

{artefact.earthquakeID}

+

+ {currencyTickers[selectedCurrency]} + {convertPrice(artefact.price, selectedCurrency)} +

+
+
+ ); + } function Modal({ artefact }: { artefact: Artefact }) { if (!artefact) return null; - const handleOverlayClick = (e: { target: any; currentTarget: any }) => { - if (e.target === e.currentTarget) { - setSelectedArtefact(null); - } + const handleOverlayClick = (e: React.MouseEvent) => { + if (e.target === e.currentTarget) setSelectedArtefact(null); }; return (

{artefact.name}

{artefact.name}

@@ -243,7 +264,11 @@ export default function Shop() {

{artefact.dateReleased}

+ +
+
); } + function ThankYouModal({ orderNumber, onClose }: { orderNumber: string; onClose: () => void }) { + const handleOverlayClick = (e: React.MouseEvent) => { + if (e.target === e.currentTarget) onClose(); + }; + return ( +
+
+

Thank you for your purchase!

+

Your order number is:

+

{orderNumber}

+ +
+
+ ); + } return (
- {/* Overlay */}
- {/* Title & Subheading */}

Artefact Shop

@@ -294,17 +447,11 @@ export default function Shop() { Discover extraordinary historical artefacts and collectibles from major seismic events from around the world - now available for purchase.

- - {/* Artefact Grid */}
- {" "} - {/* gap-10 for more spacing */} {currentArtefacts.map((artefact) => ( ))}
- - {/* Pagination Footer */}
- - {/* Modal */} {selectedArtefact && } + {artefactToBuy && showPaymentModal && ( + { + setShowPaymentModal(false); + setArtefactToBuy(null); + }} + /> + )} + {showThankYouModal && orderNumber && ( + setShowThankYouModal(false)} /> + )}
); }