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;
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<Record<string, unknown> | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
@ -34,7 +35,7 @@ export function StoreDetail({ instanceId, onBack, onEdit }: StoreDetailProps) {
}
run();
return () => { live = false; };
}, [instanceId]);
}, [instanceId, refreshKey]);
if (error) {
return (

View File

@ -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);
}
}

View File

@ -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<string, unknown> = {
...existingRow,
bags: newBags,
quantity: newBags,
};
if (bagsCol) updatedRow[bagsCol.id] = newBags;
const updatedRow: Record<string, unknown> = {
...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);
}
}

View File

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