feat(inventory): implement numeric stock inventory across fullstack and improve prescription UX handoff
Deploy Canina / deploy (push) Failing after 2m31s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s

This commit is contained in:
devops committed 2026-10-12 19:29:48 +00:00
1 parent e9582430e6
commit 741365f04c
13 files changed
+177 -47

No files matched your search

+10 -4
View File
@@ -61,23 +61,26 @@ export const useCartStore = create<CartStore>()(
orders: [],
addItem: (product, quantity, dose) => {
// Prevent adding out-of-stock products
const maxStock = typeof product.stock === 'number' ? product.stock : (product.stockStatus === 'OUT_OF_STOCK' ? 0 : 999);
const isOutOfStock =
product.stockStatus === 'OUT_OF_STOCK' ||
product.stockStatus === 'DISCONTINUED' ||
(typeof product.packageSize === 'number' && product.packageSize <= 0);
maxStock <= 0;
if (isOutOfStock || quantity <= 0) {
return;
}
const items = get().items;
const existing = items.find((i) => i.product.id === product.id);
if (existing) {
const newQty = Math.min(existing.quantity + quantity, maxStock);
set({
items: items.map((i) =>
i.product.id === product.id ? { ...i, quantity: i.quantity + quantity } : i
i.product.id === product.id ? { ...i, quantity: newQty } : i
),
});
} else {
set({ items: [...items, { product, quantity, calculatedDose: dose }] });
const initialQty = Math.min(quantity, maxStock);
set({ items: [...items, { product, quantity: initialQty, calculatedDose: dose }] });
}
},
removeItem: (productId) => {
@@ -88,9 +91,12 @@ export const useCartStore = create<CartStore>()(
get().removeItem(productId);
return;
}
const currentItem = get().items.find((i) => i.product.id === productId);
const maxStock = currentItem && typeof currentItem.product.stock === 'number' ? currentItem.product.stock : 999;
const boundedQty = Math.min(quantity, maxStock);
set({
items: get().items.map((i) =>
i.product.id === productId ? { ...i, quantity } : i
i.product.id === productId ? { ...i, quantity: boundedQty } : i
),
});
},