2026-10-12 15:19:50 +03:30
|
|
|
// The product and variant titles shown on one line of an order.
|
|
|
|
|
//
|
|
|
|
|
// These now arrive WITH the order: GET customer/me/orders includes each item's
|
|
|
|
|
// variant, its product and the product's first image.
|
|
|
|
|
//
|
|
|
|
|
// Before that, this joined against the shared catalogue in the browser. Two
|
|
|
|
|
// problems, both fixed by the include: it fetched the whole catalogue (~16k
|
|
|
|
|
// products in the real data) to label a few rows, and a product that had since
|
|
|
|
|
// left the storefront was absent from the catalogue, so the row rendered blank —
|
|
|
|
|
// precisely for old orders, which is where order history matters most.
|
|
|
|
|
import type { OrderItemDetail } from '../api/client'
|
2026-09-18 12:54:45 +03:30
|
|
|
|
2026-10-12 15:19:50 +03:30
|
|
|
export interface VariantLookup {
|
|
|
|
|
productTitle: string
|
|
|
|
|
variantTitle: string
|
|
|
|
|
imageUrl?: string
|
|
|
|
|
}
|
2026-09-18 12:54:45 +03:30
|
|
|
|
2026-10-12 15:19:50 +03:30
|
|
|
/** Reads the labels off the item itself; no request, no catalogue. */
|
|
|
|
|
export function orderItemLookup(item: OrderItemDetail): VariantLookup | undefined {
|
|
|
|
|
const variant = item.productVariant
|
|
|
|
|
if (!variant) return undefined
|
|
|
|
|
return {
|
|
|
|
|
productTitle: variant.product.title,
|
|
|
|
|
variantTitle: variant.title,
|
|
|
|
|
imageUrl: variant.product.images[0]?.url,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Kept as a composable so the call sites read unchanged. Synchronous now —
|
|
|
|
|
* `lookup` is resolved from the item, so it returns a value rather than a
|
|
|
|
|
* promise, and callers no longer need to await anything on mount.
|
|
|
|
|
*/
|
2026-09-18 12:54:45 +03:30
|
|
|
export function useOrderItemProduct() {
|
2026-10-12 15:19:50 +03:30
|
|
|
return { lookup: orderItemLookup }
|
2026-09-18 12:54:45 +03:30
|
|
|
}
|