From 2452a3c5f65b7eca8a588bfe302044623f42a605 Mon Sep 17 00:00:00 2001 From: NotII <46204250+NotII@users.noreply.github.com> Date: Sun, 27 Jul 2025 00:24:57 +0200 Subject: [PATCH] Sort pricing tiers by minQuantity in UI Pricing tiers are now displayed sorted by minQuantity, improving clarity for users. Event handlers are updated to use the original index to ensure correct tier manipulation after sorting. --- components/forms/pricing-tiers.tsx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/components/forms/pricing-tiers.tsx b/components/forms/pricing-tiers.tsx index 57c1d38..68df3f0 100644 --- a/components/forms/pricing-tiers.tsx +++ b/components/forms/pricing-tiers.tsx @@ -63,9 +63,16 @@ export const PricingTiers = ({
- {pricing.map((tier, index) => ( + {[...pricing] + .sort((a, b) => a.minQuantity - b.minQuantity) + .map((tier, sortedIndex) => { + // Find the original index for proper event handling + const originalIndex = pricing.findIndex(p => + p === tier || (p.minQuantity === tier.minQuantity && p.pricePerUnit === tier.pricePerUnit) + ); + return (No pricing tiers added.