Improve pick list item interactions and manage products search

This commit is contained in:
beatz174-bit
2025-11-24 08:56:26 +10:00
parent aa38a99eb4
commit f14a1ffd01
4 changed files with 72 additions and 19 deletions
+14 -2
View File
@@ -261,12 +261,24 @@ export const ManageProductsScreen = () => {
await assertUniqueName(updates.name, productId);
await assertUniqueBarcode(updates.barcode, productId);
await db.products.update(productId, {
const existing = await db.products.get(productId);
if (!existing) return;
const normalizedName = updates.name.trim();
const oldNameKey = existing.name.trim().toLowerCase();
const updatedProduct: Product = {
...existing,
...updates,
name: normalizedName,
unit_type: DEFAULT_UNIT_TYPE,
bulk_name: DEFAULT_BULK_NAME,
updated_at: Date.now(),
});
};
await db.products.put(updatedProduct);
await db.products
.filter((product) => product.id !== productId && product.name.trim().toLowerCase() === oldNameKey)
.delete();
setFeedback({ text: 'Product updated.', severity: 'success' });
};