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; shipments: Shipment[]; } interface OrderTrackingProps { order: Order | null; trackingTokenStatus: 'ok' | 'expired' | 'invalid' | 'mismatch' | 'no_secret'; } const StatusPill: React.FC<{ children: React.ReactNode }> = ({ children }) => ( {children} ); function whenShipped(shipment: Shipment): string { return ( shipment.shippedAt?.text ?? shipment.deliveredAt?.text ?? shipment.createdAt?.text ?? '' ); } /** * Anonymous tracking page rendered at `/orders/:uuid/track?token=...`. * The token is verified in the page middleware; this component only branches * on `trackingTokenStatus`. On 'ok' it queries the order and renders the same * shipments block as `/account/orders/:uuid`, minus the back-to-orders link * (the customer is not logged in). On 'expired' it shows a friendly CTA to * `/account/orders`. */ export default function OrderTracking({ order, trackingTokenStatus }: OrderTrackingProps) { if (trackingTokenStatus !== 'ok' || !order) { const title = trackingTokenStatus === 'expired' ? _('This tracking link has expired') : _('This tracking link is no longer valid'); const body = trackingTokenStatus === 'expired' ? _( 'Tracking links are good for a limited time. Sign in to your account to see the current status of your order.' ) : _( 'We could not verify this link. If you received it in an email from us, please try again from the most recent message, or sign in to your account.' ); return (
); } return (