import { Badge } from '@components/common/ui/Badge.js'; import { Card, CardContent, CardHeader, CardTitle } from '@components/common/ui/Card.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import { CheckCircle2, Package } from 'lucide-react'; import React from 'react'; import { NewShipmentDialog, type UnshippedItem } from './Shipments/NewShipmentDialog.js'; import { PhaseBadge } from './Shipments/phaseBadge.js'; interface VariantOption { attributeName?: string; attributeCode?: string; optionText?: string; } interface OrderItem { orderItemId: string; qty: number; productName: string; productSku: string; productUrl: string | null; thumbnail: string | null; noShippingRequired: boolean; variantOptions: VariantOption[] | null; productPrice: { value: number; text: string }; lineTotal: { value: number; text: string }; fulfillmentBadge: string; } interface Carrier { code: string; name: string; capabilities?: { createLabel?: boolean; generateTrackingUrl?: boolean; voidLabel?: boolean; fetchStatus?: boolean; }; } interface ItemsProps { order: { items: OrderItem[]; unshippedItems: UnshippedItem[]; noShippingRequired: boolean; createShipmentApi: string; shippingMethodData: { snapshot?: { carrier?: string | null } | null; } | null; }; carriers: Carrier[]; } function ItemRow({ item, unshippedMap }: { item: OrderItem; unshippedMap: Map; }) { const isDigital = item.noShippingRequired; const remaining = unshippedMap.get(Number(item.orderItemId)) ?? 0; const showRemainHint = !isDigital && item.fulfillmentBadge === 'partial_shipped' && remaining > 0; return (
{item.thumbnail ? ( {item.productName} ) : (
)}
{item.productName}
SKU: {item.productSku}
{item.variantOptions && item.variantOptions.length > 0 && (
{item.variantOptions.map((opt) => ( {opt.attributeName}:{' '} {opt.optionText} ))}
)}
{item.productPrice.text} × {item.qty}
{item.lineTotal.text}
{showRemainHint && (
{remaining} {_('left to ship')}
)}
); } /** * Items card. Sits at the top of the admin order-edit left column. * Header carries the "Create shipment" trigger (or "All items fulfilled" * badge when nothing is left). The body is the line-item list, each row * showing the per-item fulfillment badge from the server resolver and an * "N left to ship" hint when partial. * * The Shipments list lives in a sibling card (`Shipments.tsx`, sortOrder 15) * — the previous "Shipments-inside-Items via order_actions area" nesting is * gone with this refactor. */ export default function Items({ order, carriers }: ItemsProps) { const { items, unshippedItems, noShippingRequired, createShipmentApi, shippingMethodData } = order; const defaultCarrierCode = shippingMethodData?.snapshot?.carrier ?? null; const canCreateShipment = unshippedItems.length > 0 && !noShippingRequired; // Quick lookup from orderItemId → qtyUnshipped for the "N left to ship" hint. const unshippedMap = new Map(); for (const u of unshippedItems) unshippedMap.set(u.orderItemId, u.qtyUnshipped); return (
{_('Items')} {items.length}
{noShippingRequired ? ( {_('No shipping required')} ) : canCreateShipment ? ( window.location.reload()} /> ) : ( {_('All items fulfilled')} )}
{items.map((item) => ( ))}
); } export const layout = { areaId: 'leftSide', sortOrder: 10 }; export const query = ` query Query { order(uuid: getContextValue("orderId")) { noShippingRequired createShipmentApi shippingMethodData { snapshot { carrier } } items { orderItemId qty productName productSku productUrl thumbnail noShippingRequired fulfillmentBadge variantOptions { attributeCode attributeName attributeId optionId optionText } productPrice { value text } lineTotal { value text } } unshippedItems { uuid orderItemId productSku productName qtyOrdered qtyUnshipped } } carriers { code name capabilities { createLabel generateTrackingUrl voidLabel fetchStatus } } } `;