From f091b97ca04767f3cfc05cc4d6b693504d50134d Mon Sep 17 00:00:00 2001 From: DanielS Date: Fri, 10 Jul 2026 14:59:10 +0200 Subject: [PATCH] fix(wizard): prevent duplicate device names in the shopping cart --- shop/components/order-wizard.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/shop/components/order-wizard.tsx b/shop/components/order-wizard.tsx index 7b3d510..7a2c803 100644 --- a/shop/components/order-wizard.tsx +++ b/shop/components/order-wizard.tsx @@ -310,6 +310,17 @@ export function OrderWizard({ // Product validation errors (requirements and exclusions) const productValidationErrors = useMemo(() => { const errors: string[] = [] + + // Check for duplicate device names + const currentName = deviceName.trim() || (editingIdx !== null ? basketItems[editingIdx]?.deviceName : `Kasse ${basketItems.length + 1}`) + const isDuplicate = basketItems.some((item, idx) => { + if (editingIdx !== null && idx === editingIdx) return false + return item.deviceName.toLowerCase().trim() === currentName.toLowerCase().trim() + }) + if (isDuplicate) { + errors.push(`Gerätename "${currentName}" existiert bereits im Warenkorb. Bitte einen anderen Namen wählen.`) + } + const selectedProductIds: string[] = [] Object.values(selections).forEach(s => { if (s.productIds && s.productIds.length > 0) { @@ -349,7 +360,7 @@ export function OrderWizard({ }) return errors - }, [selections, products]) + }, [selections, products, deviceName, basketItems, editingIdx]) const isNextStepDisabled = !allCategoriesFilled || productValidationErrors.length > 0