'use client' import { useEffect, useState } from 'react' import { BASE } from '@/lib/basepath' import { fmt } from '@/lib/format' interface OrderData { shortRef: string state: string stateLabel: string type: 'delivery' | 'pickup' slotISO: string | null lineItems: Array<{ name: string; quantity: string }> totalCents: number | null } const STATE_COLOR: Record = { OPEN: '#e67e00', COMPLETED: '#27ae60', CANCELED: '#cc3333', } export default function OrderStatusPage({ params }: { params: Promise<{ orderId: string }> }) { const [orderId, setOrderId] = useState(null) const [order, setOrder] = useState(null) const [error, setError] = useState('') useEffect(() => { params.then((p) => setOrderId(p.orderId)) }, [params]) useEffect(() => { if (!orderId) return fetch(`${BASE}/api/order/${orderId}`) .then((r) => r.json()) .then((data) => { if (data.error) { setError(data.error); return } setOrder(data) }) .catch(() => setError('Could not load order. Please try again.')) }, [orderId]) const fmtSlot = (iso: string) => new Date(iso).toLocaleString('en-US', { timeZone: 'America/New_York', dateStyle: 'long', timeStyle: 'short', }) return (
← Back to shop {!order && !error && (

Loading order…

)} {error && (
{error}
)} {order && (

Order reference

#{order.shortRef}

{order.stateLabel}
{order.slotISO && (

{order.type === 'delivery' ? 'Scheduled delivery' : 'Pickup time'}

{fmtSlot(order.slotISO)}

)}

Items

{order.lineItems.map((li, i) => (
{li.name} × {li.quantity}
))}
{order.totalCents != null && (
Total {fmt(order.totalCents)}
)}

Questions about your order?{' '} Contact us.

)}
) }