From 93886751a374ad36cc5fc36147a26ff09c7c0b60 Mon Sep 17 00:00:00 2001 From: seaznCode Date: Tue, 5 May 2026 22:08:30 +0200 Subject: [PATCH] Enhance SelectionSummaryCard to improve pack selection feedback and error handling --- .../components/SelectionSummaryCard.tsx | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/app/coffee-abonnements/components/SelectionSummaryCard.tsx b/src/app/coffee-abonnements/components/SelectionSummaryCard.tsx index 2dc3c52..4ffe6a9 100644 --- a/src/app/coffee-abonnements/components/SelectionSummaryCard.tsx +++ b/src/app/coffee-abonnements/components/SelectionSummaryCard.tsx @@ -1,4 +1,5 @@ import type { CoffeeItem } from '../hooks/getActiveCoffees'; +import { MAX_ABO_PACKS, MIN_ABO_PACKS, packsToCapsules } from '../lib/orderRules'; type SelectedEntry = { coffee: CoffeeItem; @@ -12,9 +13,9 @@ type Props = { selectedShippingFee: number; totalNetWithShipping: number; totalCapsules: number; - packsSelected: number; - selectedPlanCapsules: number; - requiredPacks: number; + totalPacks: number; + orderPackError: string | null; + remainingMinPacks: number; canProceed: boolean; onProceed: () => void; title: string; @@ -29,9 +30,9 @@ export default function SelectionSummaryCard({ selectedShippingFee, totalNetWithShipping, totalCapsules, - packsSelected, - selectedPlanCapsules, - requiredPacks, + totalPacks, + orderPackError, + remainingMinPacks, canProceed, onProceed, title, @@ -49,10 +50,10 @@ export default function SelectionSummaryCard({
{entry.coffee.name} - {entry.quantity} pcs • EUR {entry.coffee.pricePer10}/10 + {entry.quantity} packs ({packsToCapsules(entry.quantity)} capsules) • EUR {entry.coffee.pricePer10.toFixed(2)}/pack
-
EUR {((entry.quantity / 10) * entry.coffee.pricePer10).toFixed(2)}
+
EUR {(entry.quantity * entry.coffee.pricePer10).toFixed(2)}
))} @@ -68,11 +69,21 @@ export default function SelectionSummaryCard({ EUR {totalNetWithShipping.toFixed(2)} -
- Selected: {totalCapsules} capsules ({packsSelected} packs of 10). Target: {selectedPlanCapsules} capsules ({requiredPacks} packs). - {packsSelected !== requiredPacks && ( - - {packsSelected < requiredPacks ? `${requiredPacks - packsSelected} packs missing.` : `${packsSelected - requiredPacks} packs too many.`} +
+
+ {totalPacks.toLocaleString('en-US')} packs selected. +
{totalCapsules.toLocaleString('en-US')} capsules total · minimum {MIN_ABO_PACKS} packs · maximum {MAX_ABO_PACKS.toLocaleString('en-US')} packs
+
+ + {orderPackError ? ( + + {remainingMinPacks > 0 + ? `${remainingMinPacks} more pack${remainingMinPacks === 1 ? '' : 's'} needed to reach the minimum order.` + : orderPackError} + + ) : ( + + Selection is within the allowed order range. )}
@@ -101,7 +112,9 @@ export default function SelectionSummaryCard({ {!canProceed && (

- You can continue once exactly {selectedPlanCapsules} capsules ({requiredPacks} packs) are selected. + {remainingMinPacks > 0 + ? `You can continue once at least ${MIN_ABO_PACKS} packs are selected.` + : `Please reduce the order to ${MAX_ABO_PACKS.toLocaleString('en-US')} packs or fewer.`}

)}