From db565842f3985816967a7ee5a2e4c989136495fe Mon Sep 17 00:00:00 2001 From: suryac Date: Fri, 7 Aug 2026 16:01:59 +0530 Subject: [PATCH] refresh key fix --- src/components/dv/StoreDetail.tsx | 5 +-- src/components/forms/DynamicForm.tsx | 34 ++++++++++--------- .../forms/fields/StorePotentialGrid.tsx | 30 ++++++++-------- src/screens/StoresPage.tsx | 1 + 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/components/dv/StoreDetail.tsx b/src/components/dv/StoreDetail.tsx index 444011f..2767d09 100644 --- a/src/components/dv/StoreDetail.tsx +++ b/src/components/dv/StoreDetail.tsx @@ -11,9 +11,10 @@ export interface StoreDetailProps { instanceId: string | number; onBack?: () => void; onEdit?: () => void; + refreshKey?: number; } -export function StoreDetail({ instanceId, onBack, onEdit }: StoreDetailProps) { +export function StoreDetail({ instanceId, onBack, onEdit, refreshKey }: StoreDetailProps) { const [data, setData] = useState | null>(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); @@ -34,7 +35,7 @@ export function StoreDetail({ instanceId, onBack, onEdit }: StoreDetailProps) { } run(); return () => { live = false; }; - }, [instanceId]); + }, [instanceId, refreshKey]); if (error) { return ( diff --git a/src/components/forms/DynamicForm.tsx b/src/components/forms/DynamicForm.tsx index eafd102..84006de 100644 --- a/src/components/forms/DynamicForm.tsx +++ b/src/components/forms/DynamicForm.tsx @@ -378,24 +378,26 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId: const currentBags = Number(getGridVal(r, ['bags', 'quantity'])) || 0; const currentSku = Number(getGridVal(r, ['sku'], ['code'])) || 0; - if (cat && prod) { - const key = `${cat}::${prod}`; - if (indexMap.has(key) && currentBags > 0) { - const targetIdx = indexMap.get(key)!; - const existingRow = merged[targetIdx]; - const existingBags = Number(getGridVal(existingRow, ['bags', 'quantity'])) || 0; - const addedBags = currentBags; - const newBags = existingBags + addedBags; - const skuVal = Number(getGridVal(existingRow, ['sku'], ['code']) || currentSku || 0); + const key = prod ? (cat ? `${cat}::${prod}` : prod) : cat; + if (key) { + if (indexMap.has(key)) { + if (currentBags > 0) { + const targetIdx = indexMap.get(key)!; + const existingRow = merged[targetIdx]; + const existingBags = Number(getGridVal(existingRow, ['bags', 'quantity'])) || 0; + const addedBags = currentBags; + const newBags = existingBags + addedBags; + const skuVal = Number(getGridVal(existingRow, ['sku'], ['code']) || currentSku || 0); - merged[targetIdx] = { - ...existingRow, - bags: newBags, - quantity: newBags, - row_kgs: skuVal * newBags, - }; + merged[targetIdx] = { + ...existingRow, + bags: newBags, + quantity: newBags, + row_kgs: skuVal * newBags, + }; + } continue; - } else if (!indexMap.has(key)) { + } else { indexMap.set(key, merged.length); } } diff --git a/src/components/forms/fields/StorePotentialGrid.tsx b/src/components/forms/fields/StorePotentialGrid.tsx index 83b16d4..ed9e16c 100644 --- a/src/components/forms/fields/StorePotentialGrid.tsx +++ b/src/components/forms/fields/StorePotentialGrid.tsx @@ -66,24 +66,26 @@ export function StorePotentialGrid({ const currentBags = Number(r[bagsColId] ?? r.bags ?? r.quantity ?? 0); if (cat) { - if (indexMap.has(cat) && currentBags > 0) { - const targetIdx = indexMap.get(cat)!; - const existingRow = merged[targetIdx]; + if (indexMap.has(cat)) { + if (currentBags > 0) { + const targetIdx = indexMap.get(cat)!; + const existingRow = merged[targetIdx]; - const existingBags = Number(existingRow[bagsColId] ?? existingRow.bags ?? existingRow.quantity ?? 0); - const addedBags = currentBags; - const newBags = existingBags + addedBags; + const existingBags = Number(existingRow[bagsColId] ?? existingRow.bags ?? existingRow.quantity ?? 0); + const addedBags = currentBags; + const newBags = existingBags + addedBags; - const updatedRow: Record = { - ...existingRow, - bags: newBags, - quantity: newBags, - }; - if (bagsCol) updatedRow[bagsCol.id] = newBags; + const updatedRow: Record = { + ...existingRow, + bags: newBags, + quantity: newBags, + }; + if (bagsCol) updatedRow[bagsCol.id] = newBags; - merged[targetIdx] = updatedRow; + merged[targetIdx] = updatedRow; + } continue; - } else if (!indexMap.has(cat)) { + } else { indexMap.set(cat, merged.length); } } diff --git a/src/screens/StoresPage.tsx b/src/screens/StoresPage.tsx index ba12a33..87976f5 100644 --- a/src/screens/StoresPage.tsx +++ b/src/screens/StoresPage.tsx @@ -28,6 +28,7 @@ export function StoresPage() { instanceId={instanceId} onBack={() => navigate('/stores')} onEdit={() => setEditingInstanceId(instanceId)} + refreshKey={refreshKey} />