diff --git a/shop/components/order-wizard.tsx b/shop/components/order-wizard.tsx index 7a2c803..9e7ceeb 100644 --- a/shop/components/order-wizard.tsx +++ b/shop/components/order-wizard.tsx @@ -307,6 +307,10 @@ export function OrderWizard({ }) }, [visibleCategories, selections, products, selectedBillingInterval]) + const hasActiveSelection = useMemo(() => { + return Object.values(selections).some(sel => sel.productId || (sel.productIds && sel.productIds.length > 0)) + }, [selections]) + // Product validation errors (requirements and exclusions) const productValidationErrors = useMemo(() => { const errors: string[] = [] @@ -549,8 +553,7 @@ export function OrderWizard({ const nextStep = () => { if (step === 3 && allCategoriesFilled && productValidationErrors.length === 0) { - const hasProduct = Object.values(selections).some(sel => sel.productId || (sel.productIds && sel.productIds.length > 0)) - if (hasProduct) { + if (hasActiveSelection) { addToBasket() } } @@ -680,9 +683,7 @@ export function OrderWizard({ setIsSubmitting(true) try { let finalItems = [...basketItems] - const hasProduct = Object.values(selections).some(sel => sel.productId || (sel.productIds && sel.productIds.length > 0)) - - if (hasProduct && allCategoriesFilled && productValidationErrors.length === 0) { + if (hasActiveSelection && allCategoriesFilled && productValidationErrors.length === 0) { const currentItem = { deviceName: deviceName || (editingIdx !== null ? basketItems[editingIdx]?.deviceName : `Kasse ${basketItems.length + 1}`), selections: JSON.parse(JSON.stringify(selections)), @@ -1558,7 +1559,7 @@ export function OrderWizard({ onClick={addToBasket} disabled={isNextStepDisabled} > - {editingIdx !== null ? '💾 Änderungen an Kasse speichern' : 'Noch eine Kasse hinzufügen'} + {editingIdx !== null ? '💾 Änderungen an Kasse speichern' : (hasActiveSelection ? 'Kasse speichern' : 'Kasse anlegen')}