import { useAppState } from '@components/common/context/app.js'; import { OrderSummaryItems } from '@components/frontStore/checkout/OrderSummaryItems.js'; import { OrderTotalSummary } from '@components/frontStore/checkout/OrderTotalSummary.js'; import { OrderItem } from '@components/frontStore/customer/CustomerContext.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import React from 'react'; interface ShipmentItem { uuid: string; qty: number; productSku: string | null; productName: string | null; } interface Shipment { uuid: string; shipmentId: number; carrier: string | null; carrierName: string | null; trackingNumber: string | null; trackingUrl: string | null; status: { code: string; name: string; badge: string; phase: string; }; phase: string; shippedAt: { text: string } | null; deliveredAt: { text: string } | null; canceledAt: { text: string } | null; createdAt: { text: string } | null; items: ShipmentItem[]; } interface Order { orderId: number; uuid: string; orderNumber: string; createdAt: { text: string }; grandTotal: { text: string }; shipmentStatus: { name: string; code: string; badge: string } | null; status: { name: string; code: string; badge: string } | null; shippingMethodName: string | null; shippingMethodData: { snapshot?: { name?: string; cost?: number }; } | null; subTotal: { text: string }; subTotalInclTax: { text: string }; shippingFeeInclTax: { text: string }; shippingFeeExclTax: { text: string }; totalTaxAmount: { text: string }; discountAmount: { text: string }; coupon: string | null; items: OrderItem[]; shipments: Shipment[]; } interface OrderViewProps { order: Order | null; } const StatusPill: React.FC<{ children: React.ReactNode }> = ({ children }) => ( {children} ); function whenShipped(shipment: Shipment): string { // Direct pending → delivered transitions leave `shippedAt` NULL; fall back // to deliveredAt, then to createdAt, per the wiki guidance for templates // that need a "when did it ship" line. return ( shipment.shippedAt?.text ?? shipment.deliveredAt?.text ?? shipment.createdAt?.text ?? '' ); } /** * Customer-facing order detail page. Shows what the customer paid for at the * top (the service-level quote), then a per-shipment block for each fulfillment * row with the actual carrier, tracking link, items, and dates. * * Design intent: the customer should never see the carrier name at checkout * (it's a fulfillment metadata field). This page is the FIRST surface where * a carrier name appears, because by definition the shipment has actually * been handed off. */ export default function OrderView({ order }: OrderViewProps) { const { config: { tax: { priceIncludingTax } } } = useAppState(); if (!order) { return (

{_('Order not found')}

{_( 'We could not find this order. It may have been removed, or it may belong to a different account.' )}

← {_('Back to orders')}
); } return (
← {_('Back to orders')}

{_('Order #${orderNumber}', { orderNumber: order.orderNumber })}

{order.createdAt?.text}
{order.shipmentStatus?.name && ( {order.shipmentStatus.name} )} {order.status?.name && {order.status.name}}

{_('Order summary')}

{_('Shipments')}

{order.shipments.length === 0 ? (
{_('No shipments yet — your order is being prepared.')}
) : (
{order.shipments.map((shipment) => { const trackHref = shipment.trackingUrl; const carrierLabel = shipment.carrierName ?? shipment.carrier; const shippedText = whenShipped(shipment); return (
{_('Shipment')} #{shipment.shipmentId} {shipment.status.name}
{carrierLabel && (
{carrierLabel} {shipment.trackingNumber && ( <> · {shipment.trackingNumber} )}
)}
    {shipment.items.map((item) => (
  • {item.productName ?? item.productSku ?? _('Item')} × {item.qty}
  • ))}
{(shippedText || shipment.deliveredAt?.text || trackHref) && (
{shipment.phase === 'delivered' && shipment.deliveredAt?.text && ( {_('Delivered')} {shipment.deliveredAt.text} )} {shipment.phase === 'shipped' && shippedText && ( {_('Shipped')} {shippedText} )} {shipment.phase === 'canceled' && shipment.canceledAt?.text && ( {_('Canceled')} {shipment.canceledAt.text} )} {trackHref && ( {_('Track shipment →')} )}
)}
); })}
)}
); } export const layout = { areaId: 'content', sortOrder: 10 }; export const query = ` query Query { order(uuid: getContextValue("orderUuid")) { orderId uuid orderNumber createdAt { text } grandTotal { text } shipmentStatus { name code badge } status { name code badge } shippingMethodName shippingMethodData { snapshot { name cost } } subTotal { text } subTotalInclTax { text } shippingFeeInclTax { text } shippingFeeExclTax { text } totalTaxAmount { text } discountAmount { text } coupon items { uuid productName thumbnail productSku qty productUrl productPrice { text } productPriceInclTax { text } variantOptions { attributeCode attributeName attributeId optionId optionText } lineTotalInclTax { text } lineTotal { text } } shipments { uuid shipmentId carrier carrierName trackingNumber trackingUrl status { code name badge phase } phase shippedAt { text } deliveredAt { text } canceledAt { text } createdAt { text } items { uuid qty productSku productName } } } } `;