refresh key fix

This commit is contained in:
suryac 2026-08-07 16:01:59 +05:30
parent e962291b80
commit db565842f3
4 changed files with 38 additions and 32 deletions

View File

@ -11,9 +11,10 @@ export interface StoreDetailProps {
instanceId: string | number; instanceId: string | number;
onBack?: () => void; onBack?: () => void;
onEdit?: () => void; onEdit?: () => void;
refreshKey?: number;
} }
export function StoreDetail({ instanceId, onBack, onEdit }: StoreDetailProps) { export function StoreDetail({ instanceId, onBack, onEdit, refreshKey }: StoreDetailProps) {
const [data, setData] = useState<Record<string, unknown> | null>(null); const [data, setData] = useState<Record<string, unknown> | null>(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
@ -34,7 +35,7 @@ export function StoreDetail({ instanceId, onBack, onEdit }: StoreDetailProps) {
} }
run(); run();
return () => { live = false; }; return () => { live = false; };
}, [instanceId]); }, [instanceId, refreshKey]);
if (error) { if (error) {
return ( return (

View File

@ -378,24 +378,26 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId:
const currentBags = Number(getGridVal(r, ['bags', 'quantity'])) || 0; const currentBags = Number(getGridVal(r, ['bags', 'quantity'])) || 0;
const currentSku = Number(getGridVal(r, ['sku'], ['code'])) || 0; const currentSku = Number(getGridVal(r, ['sku'], ['code'])) || 0;
if (cat && prod) { const key = prod ? (cat ? `${cat}::${prod}` : prod) : cat;
const key = `${cat}::${prod}`; if (key) {
if (indexMap.has(key) && currentBags > 0) { if (indexMap.has(key)) {
const targetIdx = indexMap.get(key)!; if (currentBags > 0) {
const existingRow = merged[targetIdx]; const targetIdx = indexMap.get(key)!;
const existingBags = Number(getGridVal(existingRow, ['bags', 'quantity'])) || 0; const existingRow = merged[targetIdx];
const addedBags = currentBags; const existingBags = Number(getGridVal(existingRow, ['bags', 'quantity'])) || 0;
const newBags = existingBags + addedBags; const addedBags = currentBags;
const skuVal = Number(getGridVal(existingRow, ['sku'], ['code']) || currentSku || 0); const newBags = existingBags + addedBags;
const skuVal = Number(getGridVal(existingRow, ['sku'], ['code']) || currentSku || 0);
merged[targetIdx] = { merged[targetIdx] = {
...existingRow, ...existingRow,
bags: newBags, bags: newBags,
quantity: newBags, quantity: newBags,
row_kgs: skuVal * newBags, row_kgs: skuVal * newBags,
}; };
}
continue; continue;
} else if (!indexMap.has(key)) { } else {
indexMap.set(key, merged.length); indexMap.set(key, merged.length);
} }
} }

View File

@ -66,24 +66,26 @@ export function StorePotentialGrid({
const currentBags = Number(r[bagsColId] ?? r.bags ?? r.quantity ?? 0); const currentBags = Number(r[bagsColId] ?? r.bags ?? r.quantity ?? 0);
if (cat) { if (cat) {
if (indexMap.has(cat) && currentBags > 0) { if (indexMap.has(cat)) {
const targetIdx = indexMap.get(cat)!; if (currentBags > 0) {
const existingRow = merged[targetIdx]; const targetIdx = indexMap.get(cat)!;
const existingRow = merged[targetIdx];
const existingBags = Number(existingRow[bagsColId] ?? existingRow.bags ?? existingRow.quantity ?? 0); const existingBags = Number(existingRow[bagsColId] ?? existingRow.bags ?? existingRow.quantity ?? 0);
const addedBags = currentBags; const addedBags = currentBags;
const newBags = existingBags + addedBags; const newBags = existingBags + addedBags;
const updatedRow: Record<string, unknown> = { const updatedRow: Record<string, unknown> = {
...existingRow, ...existingRow,
bags: newBags, bags: newBags,
quantity: newBags, quantity: newBags,
}; };
if (bagsCol) updatedRow[bagsCol.id] = newBags; if (bagsCol) updatedRow[bagsCol.id] = newBags;
merged[targetIdx] = updatedRow; merged[targetIdx] = updatedRow;
}
continue; continue;
} else if (!indexMap.has(cat)) { } else {
indexMap.set(cat, merged.length); indexMap.set(cat, merged.length);
} }
} }

View File

@ -28,6 +28,7 @@ export function StoresPage() {
instanceId={instanceId} instanceId={instanceId}
onBack={() => navigate('/stores')} onBack={() => navigate('/stores')}
onEdit={() => setEditingInstanceId(instanceId)} onEdit={() => setEditingInstanceId(instanceId)}
refreshKey={refreshKey}
/> />
</div> </div>