From 27b5b9fc789c845419abede98688ccc04496feed Mon Sep 17 00:00:00 2001 From: SJCoetz Date: Sun, 24 May 2026 22:31:35 +0200 Subject: [PATCH] feat: update collection and supplier handling across components --- app/page.tsx | 14 ++--- components/CollectModal.tsx | 10 ++-- components/CollectionItemCard.tsx | 27 +++++----- components/CollectionMap.tsx | 68 +++++++++++------------- components/LocationTracker.tsx | 87 ++++++++++++++----------------- components/ProblemModal.tsx | 4 +- lib/pocketbase.ts | 42 ++++++++++----- lib/types.ts | 30 +++++------ lib/utils.ts | 24 +++++++++ 9 files changed, 163 insertions(+), 143 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 74aebf5..de2931c 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -85,9 +85,9 @@ export default function CollectionsPage() { filtered = filtered.filter((c) => { const desc = c.is_manual ? c.description - : c.expand?.order_item?.description || ''; - const supplier = c.expand?.supplier?.suppliername || ''; - const orderNum = c.expand?.order_item?.expand?.order?.order_number || ''; + : c.expand?.orders_orderitem?.description || ''; + const supplier = c.expand?.wfdash_suppliers?.suppliername || ''; + const orderNum = c.expand?.orders_orderitem?.expand?.orders_order?.order_number || ''; return ( desc.toLowerCase().includes(query) || supplier.toLowerCase().includes(query) || @@ -180,7 +180,7 @@ export default function CollectionsPage() { // Group by supplier const groupedBySupplier = filteredCollections.reduce((acc, collection) => { - const supplier = collection.expand?.supplier; + const supplier = collection.expand?.wfdash_suppliers; if (!supplier) return acc; const key = supplier.id; @@ -189,7 +189,7 @@ export default function CollectionsPage() { } acc[key].items.push(collection); return acc; - }, {} as Record['supplier']; items: Collection[] }>); + }, {} as Record['wfdash_suppliers']; items: Collection[] }>); const groupedArray = Object.values(groupedBySupplier).sort((a, b) => (a.supplier?.suppliername || '').localeCompare(b.supplier?.suppliername || '') @@ -358,9 +358,9 @@ export default function CollectionsPage() { {items.length} - {supplier!.address && ( + {supplier!.supplieraddress && ( - {supplier!.address} + {supplier!.supplieraddress} )} diff --git a/components/CollectModal.tsx b/components/CollectModal.tsx index e19677e..4bfc7d4 100644 --- a/components/CollectModal.tsx +++ b/components/CollectModal.tsx @@ -24,7 +24,7 @@ export default function CollectModal({ if (!isOpen || !collection) return null; - const expectedQty = collection.quantity || collection.expand?.order_item?.quantity || 0; + const expectedQty = collection.quantity || collection.expand?.orders_orderitem?.quantity || 0; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); @@ -68,14 +68,14 @@ export default function CollectModal({

{collection.is_manual ? collection.description - : collection.expand?.order_item?.description || 'Unknown item'} + : collection.expand?.orders_orderitem?.description || 'Unknown item'}

- Expected: {expectedQty} {collection.unit || collection.expand?.order_item?.unit || 'units'} + Expected: {expectedQty} {collection.unit || collection.expand?.orders_orderitem?.unit || 'units'}

- {collection.expand?.order_item?.selling_price && ( + {collection.expand?.orders_orderitem?.selling_price && (

- Unit price: {formatCurrency(collection.expand.order_item.selling_price)} + Unit price: {formatCurrency(collection.expand.orders_orderitem.selling_price)}

)} diff --git a/components/CollectionItemCard.tsx b/components/CollectionItemCard.tsx index 0eb530c..1d13c23 100644 --- a/components/CollectionItemCard.tsx +++ b/components/CollectionItemCard.tsx @@ -2,7 +2,7 @@ import { useState } from 'react'; import { Collection } from '@/lib/types'; -import { cn, formatDate, formatCurrency } from '@/lib/utils'; +import { cn, formatDate, formatCurrency, parseCoordinates } from '@/lib/utils'; import { Check, AlertTriangle, @@ -38,8 +38,8 @@ function getItemType(collection: Collection): { }; } - const orderNumber = collection.expand?.order_item?.expand?.order?.order_number || ''; - const desc = collection.description || collection.expand?.order_item?.description || ''; + const orderNumber = collection.expand?.orders_orderitem?.expand?.orders_order?.order_number || ''; + const desc = collection.description || collection.expand?.orders_orderitem?.description || ''; if (orderNumber.toLowerCase().includes('breakdown')) { return { @@ -83,13 +83,14 @@ export default function CollectionItemCard({ onNavigate, }: CollectionItemProps) { const [expanded, setExpanded] = useState(false); - const [showActions, setShowActions] = useState(false); - const supplier = collection.expand?.supplier; - const orderItem = collection.expand?.order_item; + const supplier = collection.expand?.wfdash_suppliers; + const orderItem = collection.expand?.orders_orderitem; const itemType = getItemType(collection); - const hasCoords = supplier?.latitude && supplier?.longitude; + // Parse coordinates from text field + const coords = parseCoordinates(supplier?.coordinates); + const hasCoords = coords !== null; const description = collection.is_manual ? collection.description @@ -98,8 +99,8 @@ export default function CollectionItemCard({ const quantity = collection.quantity || orderItem?.quantity || 0; const unit = collection.unit || orderItem?.unit || 'units'; - const orderNumber = orderItem?.expand?.order?.order_number || ''; - const poNumber = orderItem?.expand?.purchase_order?.po_number || ''; + const orderNumber = orderItem?.expand?.orders_order?.order_number || ''; + const poNumber = orderItem?.expand?.orders_purchaseorder?.po_number || ''; return (
)} - {supplier?.address && ( + {supplier?.supplieraddress && (

- Address: {supplier.address} + Address: {supplier.supplieraddress}

)} @@ -216,11 +217,11 @@ export default function CollectionItemCard({ Problem - {hasCoords && supplier && ( + {hasCoords && coords && supplier && (
))} @@ -187,9 +179,9 @@ export default function CollectionMap({ collections, onNavigate }: MapViewProps)