diff --git a/components/forms/pricing-tiers.tsx b/components/forms/pricing-tiers.tsx index 2f246d4..407e93a 100644 --- a/components/forms/pricing-tiers.tsx +++ b/components/forms/pricing-tiers.tsx @@ -37,23 +37,27 @@ export const PricingTiers = ({ const validateTier = (tier: any, index: number) => { const errors = []; - if (tier.minQuantity <= 0) { + // Only validate if both fields have values + if (tier.minQuantity > 0 && tier.pricePerUnit > 0) { + // Check for duplicate quantities only if both fields are complete + const duplicateIndex = pricing.findIndex((p, i) => + i !== index && p.minQuantity === tier.minQuantity && p.minQuantity > 0 + ); + + if (duplicateIndex !== -1) { + errors.push("Duplicate quantity found"); + } + } + + // Only show validation errors for completed fields + if (tier.minQuantity !== 0 && tier.minQuantity <= 0) { errors.push("Quantity must be greater than 0"); } - if (tier.pricePerUnit <= 0) { + if (tier.pricePerUnit !== 0 && tier.pricePerUnit <= 0) { errors.push("Price must be greater than 0"); } - // Check for duplicate quantities - const duplicateIndex = pricing.findIndex((p, i) => - i !== index && p.minQuantity === tier.minQuantity - ); - - if (duplicateIndex !== -1) { - errors.push("Duplicate quantity found"); - } - return errors; }; @@ -108,10 +112,10 @@ export const PricingTiers = ({ type="number" min="1" step="1" - placeholder="e.g. 10" + placeholder="e.g. 29" value={tier.minQuantity === 0 ? "" : tier.minQuantity} onChange={(e) => handleTierChange(e, originalIndex)} - className={`h-10 ${errors.some(e => e.includes('Quantity')) ? 'border-red-500' : ''}`} + className={`h-10 ${errors.some(e => e.includes('Quantity') || e.includes('Duplicate')) ? 'border-red-500' : ''}`} /> {errors.some(e => e.includes('Quantity')) && (
{errors.find(e => e.includes('Quantity'))}
@@ -151,7 +155,7 @@ export const PricingTiers = ({ - {errors.some(e => e.includes('Duplicate')) && ( + {errors.some(e => e.includes('Duplicate')) && tier.minQuantity > 0 && tier.pricePerUnit > 0 && (⚠️ This quantity is already used in another tier