fix(wizard): prevent duplicate device names in the shopping cart

This commit is contained in:
DanielS
2026-07-10 14:59:10 +02:00
parent 6d6bb4dfe6
commit f091b97ca0

View File

@@ -310,6 +310,17 @@ export function OrderWizard({
// Product validation errors (requirements and exclusions) // Product validation errors (requirements and exclusions)
const productValidationErrors = useMemo(() => { const productValidationErrors = useMemo(() => {
const errors: string[] = [] 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[] = [] const selectedProductIds: string[] = []
Object.values(selections).forEach(s => { Object.values(selections).forEach(s => {
if (s.productIds && s.productIds.length > 0) { if (s.productIds && s.productIds.length > 0) {
@@ -349,7 +360,7 @@ export function OrderWizard({
}) })
return errors return errors
}, [selections, products]) }, [selections, products, deviceName, basketItems, editingIdx])
const isNextStepDisabled = !allCategoriesFilled || productValidationErrors.length > 0 const isNextStepDisabled = !allCategoriesFilled || productValidationErrors.length > 0