import { getAdminUser } from "@/lib/admin-permissions"; import { getAdminOrderDetail } from "@/actions/orders"; import OrderEditForm from "@/components/admin/OrderEditForm"; import OrderPaymentSection from "@/components/admin/OrderPaymentSection"; import OrderPickupAction from "@/components/admin/OrderPickupAction"; import AdminAccessDenied from "@/components/admin/AdminAccessDenied"; import { formatDate } from "@/lib/format-date"; import { redirect } from "next/navigation"; type OrderDetailPageProps = { params: Promise<{ id: string; }>; }; function formatCurrency(amount: number) { return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(amount); } export default async function OrderDetailPage({ params }: OrderDetailPageProps) { const { id } = await params; const order = await getAdminOrderDetail(id); if (!order) { return (
← Back to Orders

Order not found

); } const adminUser = await getAdminUser(); if (!adminUser) return ; if (!adminUser.can_manage_orders) redirect("/admin/pickup"); if (adminUser?.brand_id && order.stops?.brand_id !== adminUser.brand_id) { return ; } const brandId = order.stops?.brand_id ?? null; const subtotal = Number(order.subtotal); const discount_amount = Number(order.discount_amount ?? 0); const taxAmount = Number(order.tax_amount ?? 0); const total = subtotal + taxAmount - discount_amount; return (
{/* Header */}

Order Details

{formatDate(order.created_at)}

{order.pickup_complete ? "✓ Picked Up" : "⏳ Pending"} {order.payment_processor && ( {order.payment_processor} )}
{/* Customer info */}

Customer

{order.customer_name}

{order.customer_phone && (

Phone

{order.customer_phone}

)} {order.customer_email && (

Email

{order.customer_email}

)}
{/* Stop info */} {order.stops && (

Pickup Location

{order.stops.city}, {order.stops.state}

{formatDate(order.stops.date)}

)} {/* Order items */}

Order Items

{order.order_items && order.order_items.length > 0 ? (
{order.order_items.map((item: any) => (

{item.products?.name ?? "Unknown Product"}

Qty: {item.quantity} × {formatCurrency(Number(item.price))}

{formatCurrency(Number(item.price) * item.quantity)}

))}
) : (

No items found

)} {/* Totals */}
Subtotal {formatCurrency(subtotal)}
{taxAmount > 0 && (
Tax {formatCurrency(taxAmount)}
)} {discount_amount > 0 && (
Discount -{formatCurrency(discount_amount)} {order.discount_reason && ( ({order.discount_reason}) )}
)}
Total {formatCurrency(total)}
{/* Payment & Refunds */}

Payment & Refunds

Record payment details and manage refunds

{/* Edit form */}

Edit Order

Update customer details, pricing, and status

{/* Internal notes */} {order.internal_notes && (

Internal Notes

{order.internal_notes}

)}
); }