From 03a2e37502044ce385c2fd3c12cf776154e2de18 Mon Sep 17 00:00:00 2001 From: NotII <46204250+NotII@users.noreply.github.com> Date: Thu, 16 Oct 2025 12:12:22 +0100 Subject: [PATCH] Ensure stable identity for pricing tiers in forms Adds a tempId to new pricing tiers for stable mapping before backend _id assignment. Updates mapping logic in pricing-tiers form to use tempId or _id for reliable event handling and rendering. --- components/forms/pricing-tiers.tsx | 10 ++++------ components/modals/product-modal.tsx | 14 +++++++++++++- public/git-info.json | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/components/forms/pricing-tiers.tsx b/components/forms/pricing-tiers.tsx index 4789397..a1d3228 100644 --- a/components/forms/pricing-tiers.tsx +++ b/components/forms/pricing-tiers.tsx @@ -76,14 +76,12 @@ export const PricingTiers = ({ .sort((a, b) => (a?.minQuantity || 0) - (b?.minQuantity || 0)) .map((tier, sortedIndex) => { if (!tier) return null; - - // Find the original index for proper event handling - const originalIndex = pricing.findIndex(p => - p === tier || (p?.minQuantity === tier?.minQuantity && p?.pricePerUnit === tier?.pricePerUnit) - ); + // Prefer stable identifiers for mapping back to the original array + const keyId = tier._id || tier.tempId; + const originalIndex = pricing.findIndex((p) => (p?._id || p?.tempId) === keyId); return (