From d44c23ef6dbf71d8222e147874005186771afafc Mon Sep 17 00:00:00 2001 From: josh Date: Thu, 7 May 2026 21:38:10 -0400 Subject: [PATCH] Autofill next asset ID and pre-select bin from existing inventory Asset tag field now defaults to the highest existing asset ID + 1. Bin selector pre-selects the bin where other instances of the same product are stored, falling back to the first bin. Co-Authored-By: Claude Opus 4.6 --- web/src/components/modals/AddInventoryFlow.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web/src/components/modals/AddInventoryFlow.tsx b/web/src/components/modals/AddInventoryFlow.tsx index 017859d..e8d1cb7 100644 --- a/web/src/components/modals/AddInventoryFlow.tsx +++ b/web/src/components/modals/AddInventoryFlow.tsx @@ -358,10 +358,18 @@ function InstanceDetailsStep({ return last.price; })(); - const [assetId, setAssetId] = useState(""); + const nextAssetId = useMemo(() => { + const max = data.inventoryItems.reduce( + (m, i) => Math.max(m, parseInt(i.assetId, 10) || 0), + 0, + ); + return max > 0 ? String(max + 1).padStart(6, "0") : ""; + }, [data.inventoryItems]); + + const [assetId, setAssetId] = useState(nextAssetId); const [form, setForm] = useState({ shopId: last?.shopId ?? data.shops[0]?.id ?? NEW_SHOP, - binId: data.bins[0]?.id ?? NEW_BIN, + binId: last?.binId ?? data.bins[0]?.id ?? NEW_BIN, weight: last?.weight ?? (isDiscrete ? 0 : 3.5), unitWeight: last?.unitWeight ?? (isDiscrete ? 0.7 : 0), price: initialPrice,