Compare commits

..

No commits in common. "3a5ddee97afa53990f9bb1dd06ed736b5ce7465e" and "776e09a9185778487ff1f5249a373fcbe723ed3d" have entirely different histories.

2 changed files with 10 additions and 55 deletions

View File

@ -466,18 +466,9 @@ export default function App() {
currency: currency currency: currency
}, { headers }); }, { headers });
const calcData = res.data; setPricingCalc(res.data);
if (appliedCoupon && (!calcData.coupon_applied || calcData.coupon_applied === 'None')) { } catch (err) {
calcData.coupon_error = calcData.coupon_error || 'Invalid or expired coupon code.';
}
setPricingCalc(calcData);
} catch (err: any) {
console.error('Pricing engine calculation error:', err); console.error('Pricing engine calculation error:', err);
const errorMsg = err.response?.data?.detail || 'Invalid or expired coupon code.';
setPricingCalc((prev: any) => ({
...(prev || {}),
coupon_error: errorMsg
}));
} finally { } finally {
setLoadingPricing(false); setLoadingPricing(false);
} }
@ -534,7 +525,6 @@ export default function App() {
const removePromoCode = () => { const removePromoCode = () => {
setAppliedCoupon(null); setAppliedCoupon(null);
setCouponCode(''); setCouponCode('');
setPricingCalc((prev: any) => (prev ? { ...prev, coupon_error: null } : null));
}; };
const isModuleUnlocked = (code: string) => { const isModuleUnlocked = (code: string) => {
@ -584,17 +574,10 @@ export default function App() {
setCheckoutLoading(true); setCheckoutLoading(true);
setVerificationResult(null); setVerificationResult(null);
const isCouponValid = Boolean(
pricingCalc &&
pricingCalc.coupon_applied &&
pricingCalc.coupon_applied !== 'None' &&
!pricingCalc.coupon_error
);
try { try {
const orderRes = await axios.post(`${API_BASE}/api/checkout/create-order`, { const orderRes = await axios.post(`${API_BASE}/api/checkout/create-order`, {
cart_item_codes: cart.map(item => item.code), cart_item_codes: cart.map(item => item.code),
coupon_code: isCouponValid ? appliedCoupon : undefined, coupon_code: appliedCoupon || undefined,
currency: currency currency: currency
}, { }, {
headers: { 'Authorization': `Bearer ${userToken}` } headers: { 'Authorization': `Bearer ${userToken}` }

View File

@ -141,11 +141,9 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
</button> </button>
</div> </div>
{appliedCoupon && {appliedCoupon &&
(pricingCalc?.coupon_error || !pricingCalc?.coupon_applied || pricingCalc?.coupon_applied === 'None' ? ( (pricingCalc?.coupon_error ? (
<div className="flex justify-between items-center bg-rose-50 border border-rose-200 text-rose-700 text-xs px-3 py-2 rounded-xl font-bold"> <div className="flex justify-between items-center bg-rose-50 border border-rose-200 text-rose-700 text-xs px-3 py-2 rounded-xl font-bold">
<span className="flex items-center gap-1"> <span className="flex items-center gap-1">⚠️ {pricingCalc.coupon_error}</span>
⚠️ {pricingCalc?.coupon_error || 'Invalid or expired coupon code.'}
</span>
<button <button
onClick={removePromoCode} onClick={removePromoCode}
className="text-rose-700 hover:text-rose-900 font-bold ml-2 cursor-pointer" className="text-rose-700 hover:text-rose-900 font-bold ml-2 cursor-pointer"
@ -185,44 +183,18 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
: `$${pricingCalc.base_subtotal}`} : `$${pricingCalc.base_subtotal}`}
</span> </span>
</div> </div>
{pricingCalc.bundle_discount_amount > 0 && ( {pricingCalc.total_discounts > 0 && (
<div className="flex justify-between text-xs text-emerald-700 font-bold"> <div className="flex justify-between text-xs text-emerald-700 font-bold">
<span>Bundle Discount</span> <span>Total Discounts</span>
<span> <span>
-{currency === 'INR' -{currency === 'INR'
? `₹${pricingCalc.bundle_discount_amount}` ? `₹${pricingCalc.total_discounts}`
: currency === 'EUR' : currency === 'EUR'
? `€${pricingCalc.bundle_discount_amount}` ? `€${pricingCalc.total_discounts}`
: `$${pricingCalc.bundle_discount_amount}`} : `$${pricingCalc.total_discounts}`}
</span> </span>
</div> </div>
)} )}
{pricingCalc.coupon_discount_amount > 0 && (
<div className="flex justify-between text-xs text-emerald-700 font-bold">
<span>Coupon Discount ({appliedCoupon})</span>
<span>
-{currency === 'INR'
? `₹${pricingCalc.coupon_discount_amount}`
: currency === 'EUR'
? `€${pricingCalc.coupon_discount_amount}`
: `$${pricingCalc.coupon_discount_amount}`}
</span>
</div>
)}
{pricingCalc.total_discounts > 0 &&
!pricingCalc.bundle_discount_amount &&
!pricingCalc.coupon_discount_amount && (
<div className="flex justify-between text-xs text-emerald-700 font-bold">
<span>Total Discounts</span>
<span>
-{currency === 'INR'
? `₹${pricingCalc.total_discounts}`
: currency === 'EUR'
? `€${pricingCalc.total_discounts}`
: `$${pricingCalc.total_discounts}`}
</span>
</div>
)}
{pricingCalc.convenience_fee > 0 && ( {pricingCalc.convenience_fee > 0 && (
<div className="flex justify-between text-xs text-slate-600 font-bold"> <div className="flex justify-between text-xs text-slate-600 font-bold">
<span>Gateway fee ({pricingCalc.convenience_fee_rate}%)</span> <span>Gateway fee ({pricingCalc.convenience_fee_rate}%)</span>