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 (
{_( 'We could not find this order. It may have been removed, or it may belong to a different account.' )}
← {_('Back to orders')}