From a80721c6e0d949cd15901b05792ce461bf17f8d1 Mon Sep 17 00:00:00 2001 From: SJCoetz Date: Wed, 29 Jul 2026 16:11:11 +0200 Subject: [PATCH] fix(orders): review modal mount review fixes (customer fallback, dead ai wiring) Co-Authored-By: Claude Opus 4.8 Co-authored-by: Orca --- src/app/(app)/orders/page.tsx | 30 ++++++++++---------------- src/components/orders-review-modal.tsx | 4 ++-- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/app/(app)/orders/page.tsx b/src/app/(app)/orders/page.tsx index 5de4350..65c9aec 100644 --- a/src/app/(app)/orders/page.tsx +++ b/src/app/(app)/orders/page.tsx @@ -92,7 +92,7 @@ function OrdersReviewModalMount({ order: import("@/lib/types").Order; items: OrderItem[]; customer: import("@/lib/types").Customer; - company: import("@/lib/types").Company; + company: import("@/lib/types").Company | null; customers: import("@/lib/types").Customer[]; quoteEmail: { subject: string; body: string }; attachments: import("@/lib/types").QuoteAttachment[]; @@ -134,22 +134,20 @@ function OrdersReviewModalMount({ if (cancelled) return; + // Customer fallback chain: expand → match by ID in the loaded list → + // first customer as a last resort. The "first customer" fallback + // is misleading (it's just the newest customer in PB, not anything + // related to the order), but it preserves the previous UX if the + // list happens to be empty after filtering. const customer = (order.expand?.customer as import("@/lib/types").Customer) || + customersResult.find((c) => c.id === order.customer) || customersResult[0]; + // Company can be null if the order's company record isn't loaded. + // The modal renders "(unknown)" in that case rather than fabricating + // a stub with the wrong ID. const company = - (order.expand?.company as import("@/lib/types").Company) || { - id: order.company, - created: "", - updated: "", - collectionId: "", - collectionName: "", - company: "(unknown)", - address: "", - vendor: "", - company_email: "", - company_tel: "", - }; + (order.expand?.company as import("@/lib/types").Company) || null; setData({ order, @@ -465,10 +463,8 @@ export default function OrdersPage() { isExpanded={expanded.has(order.id)} showAll={showAllByOrder.has(order.id)} activeTab={activeTab} - aiExpanded={false} onToggleExpand={() => toggleExpand(order.id)} onToggleShowAll={() => toggleShowAll(order.id)} - onToggleAi={() => {}} onOpen={() => router.push(`/orders/${order.id}`)} onOpenReview={() => openReview(order.id)} /> @@ -525,10 +521,8 @@ function OrderCard({ isExpanded, showAll, activeTab, - aiExpanded, onToggleExpand, onToggleShowAll, - onToggleAi, onOpen, onOpenReview, }: { @@ -537,10 +531,8 @@ function OrderCard({ isExpanded: boolean; showAll: boolean; activeTab: TabGroup; - aiExpanded: boolean; onToggleExpand: () => void; onToggleShowAll: () => void; - onToggleAi: () => void; onOpen: () => void; onOpenReview: () => void; }) { diff --git a/src/components/orders-review-modal.tsx b/src/components/orders-review-modal.tsx index 51f5bee..558e12e 100644 --- a/src/components/orders-review-modal.tsx +++ b/src/components/orders-review-modal.tsx @@ -50,7 +50,7 @@ export interface OrdersReviewModalProps { items: OrderItem[]; customers: Customer[]; customer: Customer; - company: Company; + company: Company | null; quoteEmail: { subject: string; body: string }; attachments: QuoteAttachment[]; } @@ -375,7 +375,7 @@ export function OrdersReviewModal({

- {company.company} + {company?.company || "(unknown)"}