fix(wizard): prevent duplicate device names in the shopping cart
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user