fix: enforce top-down state cascade and prevent base product hiding
This commit is contained in:
@@ -390,6 +390,20 @@ export function OrderWizard({
|
||||
[catId]: { productId: nextProductId, productIds: nextProductIds, moduleIds: [] },
|
||||
}
|
||||
|
||||
// Kaskaden-Bereinigung: Entferne inkompatible Module in anderen Kategorien
|
||||
const newProduct = products.find(p => p.id === nextProductId)
|
||||
categories.forEach(c => {
|
||||
if (c.id === catId) return
|
||||
const s = next[c.id]
|
||||
if (s && s.moduleIds.length > 0) {
|
||||
s.moduleIds = s.moduleIds.filter(mId => {
|
||||
// Prüfe ob das neue Basis-Produkt dieses Modul ausschließt
|
||||
const isExcluded = newProduct?.exclusions?.includes(mId)
|
||||
return !isExcluded
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
if (shouldReset) {
|
||||
// Reset all other categories
|
||||
categories.forEach(c => {
|
||||
@@ -429,7 +443,7 @@ export function OrderWizard({
|
||||
next[c.id] = {
|
||||
productId: validProductIds[0] || null,
|
||||
productIds: validProductIds,
|
||||
moduleIds: []
|
||||
moduleIds: s.moduleIds
|
||||
}
|
||||
} else if (s?.productId) {
|
||||
const prod = products.find(p => p.id === s.productId)
|
||||
@@ -902,27 +916,14 @@ export function OrderWizard({
|
||||
.map(([, s]) => s.productId)
|
||||
.filter((id): id is string => !!id)
|
||||
|
||||
// Filter products based on display flags and mutual exclusions
|
||||
// Filter products based on display flags (do not hide due to exclusions to prevent UI deadlocks)
|
||||
const catProducts = products.filter(p => {
|
||||
if (p.category_id !== cat.id) return false
|
||||
|
||||
const matchesInterval = selectedBillingInterval === 'one_time'
|
||||
? p.show_in_kauf !== false
|
||||
: p.show_in_abo !== false
|
||||
if (!matchesInterval) return false
|
||||
|
||||
// Check if p is excluded by any other selected product
|
||||
const isExcludedByOthers = otherSelectedProductIds.some(otherId => {
|
||||
const otherProd = products.find(prod => prod.id === otherId)
|
||||
return otherProd?.exclusions?.includes(p.id)
|
||||
})
|
||||
if (isExcludedByOthers) return false
|
||||
|
||||
// Check if p excludes any other selected product
|
||||
const excludesOthers = p.exclusions?.some(exId => otherSelectedProductIds.includes(exId))
|
||||
if (excludesOthers) return false
|
||||
|
||||
return true
|
||||
return matchesInterval
|
||||
})
|
||||
const sel = selections[cat.id]
|
||||
const selectedProduct = catProducts.find(p => p.id === sel?.productId) ?? null
|
||||
|
||||
Reference in New Issue
Block a user