import { notFound } from "next/navigation"; import { getAdminUser } from "@/lib/admin-permissions"; import { getAdminOrderDetail, type AdminOrder } from "@/actions/orders"; import { formatDate } from "@/lib/format-date"; import PageHeader from "@/components/admin/PageHeader"; import StatusPill, { type StatusKind } from "@/components/admin/StatusPill"; import StickyActionBar from "@/components/admin/StickyActionBar"; import OrderActionButtons from "@/components/admin/orders/OrderActionButtons"; export const dynamic = "force-dynamic"; /** * Map the legacy `orders.status` + `pickup_complete` pair onto the * StatusPill's `StatusKind` union. Must match the helper in * `orders/page.tsx` so the list and detail pages agree on the * pill vocabulary. Kept inlined here to avoid a shared-types file * until we know the mapping is stable. */ type OrderStatusKind = "placed" | "ready" | "picked-up" | "cancelled"; function statusKind(o: { status: string; pickup_complete: boolean }): OrderStatusKind { if (o.status === "canceled") return "cancelled"; if (o.pickup_complete || o.status === "fulfilled") return "picked-up"; if (o.status === "confirmed") return "ready"; return "placed"; } export default async function OrderDetailV2Page({ params, }: { params: Promise<{ id: string }>; }) { const { id } = await params; const adminUser = await getAdminUser(); if (!adminUser) return null; const order = await getAdminOrderDetail(id); if (!order) notFound(); const kind = statusKind(order); const subtotal = Number(order.subtotal ?? 0); const taxAmount = Number(order.tax_amount ?? 0); const discountAmount = Number(order.discount_amount ?? 0); const total = subtotal + taxAmount - discountAmount; const itemCount = order.order_items?.length ?? 0; return (
} />

{order.customer_name}

{order.customer_phone && ( {order.customer_phone} )} {order.customer_email && ( {order.customer_email} )}
{order.stops && (

PICKUP

{order.stops.city}, {order.stops.state}
{order.stops.date && (
{formatDate(order.stops.date)}
)}
)}

ITEMS ({itemCount})

{itemCount > 0 ? (
    {order.order_items?.map((item: NonNullable[number]) => { const unitPrice = Number(item.price ?? 0); const lineTotal = unitPrice * item.quantity; return (
  • {item.products?.name ?? "Unknown product"}
    {item.quantity} × ${unitPrice.toFixed(2)}
    ${lineTotal.toFixed(2)}
  • ); })}
) : (
No items
)}
TOTAL ${total.toFixed(2)}
{order.internal_notes && (

“{order.internal_notes}”

)}
); }