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.
This commit is contained in:
@@ -98,7 +98,19 @@ export const ProductModal: React.FC<ProductModalProps> = ({
|
||||
const handleAddTier = () => {
|
||||
setProductData((prev) => ({
|
||||
...prev,
|
||||
pricing: [...prev.pricing, { minQuantity: 0, pricePerUnit: 0 }],
|
||||
pricing: [
|
||||
...prev.pricing,
|
||||
{
|
||||
minQuantity: 0,
|
||||
pricePerUnit: 0,
|
||||
// tempId ensures stable identity before backend assigns _id
|
||||
// Using crypto.randomUUID if available, otherwise a timestamp fallback
|
||||
tempId:
|
||||
(typeof crypto !== "undefined" && (crypto as any).randomUUID
|
||||
? (crypto as any).randomUUID()
|
||||
: `${Date.now()}-${Math.random()}`),
|
||||
},
|
||||
],
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user