"use client"; import { useState } from "react"; export function Checkout({ eventId, priceCents, stripeReady }: { eventId: string; priceCents: number; stripeReady: boolean }) { const [quantity, setQuantity] = useState(1); const [busy, setBusy] = useState(false); const [error, setError] = useState(""); async function submit() { setBusy(true); setError(""); try { const response = await fetch("/api/checkout", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ eventId, quantity }), }); const result = await response.json(); if (!response.ok) throw new Error(result.error || "Checkout could not start."); window.location.assign(result.url); } catch (problem) { setError(problem instanceof Error ? problem.message : "Checkout could not start."); setBusy(false); } } return (
Choose your seats
{quantity}
Total ${((priceCents * quantity) / 100).toFixed(2)}

{stripeReady ? "Stripe test mode is connected." : "Free test order mode. No payment key needed."}

{error &&

{error}

}
); }