'use client'; import React, { useState } from 'react'; import Image from 'next/image'; import { RiImageLine } from '@remixicon/react'; import type { Customer, CustomerOrder } from '@/services/shopify/customer'; interface OrderHistoryProps { customer: Customer; } const formatMoney = (amount: string, currencyCode: string) => { const value = parseFloat(amount); try { return new Intl.NumberFormat('en-US', { style: 'currency', currency: currencyCode, }).format(value); } catch { return `$${value.toFixed(2)}`; } }; const formatDate = (iso: string) => new Date(iso).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', }); const StatusPill: React.FC<{ label?: string | null }> = ({ label }) => { if (!label) return null; return ( {label.replace(/_/g, ' ').toLowerCase()} ); }; const OrderHistory: React.FC = ({ customer }) => { const orders: CustomerOrder[] = customer.orders?.edges.map((edge) => edge.node) ?? []; // The Storefront API has no standalone order-by-id query for customers, so // the detail is rendered from the order already loaded in this list. const [selectedId, setSelectedId] = useState( orders[0]?.id ?? null ); const selected = orders.find((order) => order.id === selectedId) ?? null; if (orders.length === 0) { return (

You haven't placed any orders yet.

); } return (
{/* List */}

Orders

    {orders.map((order) => { const isSelected = order.id === selectedId; return (
  • ); })}
{/* Detail — same screen, no navigation */}
{selected && ( <>

Order #{selected.orderNumber}

{formatMoney( selected.currentTotalPrice.amount, selected.currentTotalPrice.currencyCode )}
Placed {formatDate(selected.processedAt)}
    {selected.lineItems.edges.map(({ node }, index) => (
  • {node.variant?.image ? ( {node.variant.image.altText ) : (
    )}

    {node.title}

    Qty {node.quantity}

  • ))}
{selected.statusUrl && ( View order status )} )}
); }; export default OrderHistory;