Merge pull request 'Issue#4 : fix(cart) display error for invalid or expired coupon codes' (#11) from fix/issue-4-expired-coupon-validation into main
Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-store-ui/pulls/11 Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
commit
3a5ddee97a
23
src/App.tsx
23
src/App.tsx
|
|
@ -466,9 +466,18 @@ export default function App() {
|
||||||
currency: currency
|
currency: currency
|
||||||
}, { headers });
|
}, { headers });
|
||||||
|
|
||||||
setPricingCalc(res.data);
|
const calcData = res.data;
|
||||||
} catch (err) {
|
if (appliedCoupon && (!calcData.coupon_applied || calcData.coupon_applied === 'None')) {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
@ -525,6 +534,7 @@ 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) => {
|
||||||
|
|
@ -574,10 +584,17 @@ 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: appliedCoupon || undefined,
|
coupon_code: isCouponValid ? appliedCoupon : undefined,
|
||||||
currency: currency
|
currency: currency
|
||||||
}, {
|
}, {
|
||||||
headers: { 'Authorization': `Bearer ${userToken}` }
|
headers: { 'Authorization': `Bearer ${userToken}` }
|
||||||
|
|
|
||||||
|
|
@ -141,9 +141,11 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{appliedCoupon &&
|
{appliedCoupon &&
|
||||||
(pricingCalc?.coupon_error ? (
|
(pricingCalc?.coupon_error || !pricingCalc?.coupon_applied || pricingCalc?.coupon_applied === 'None' ? (
|
||||||
<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">⚠️ {pricingCalc.coupon_error}</span>
|
<span className="flex items-center gap-1">
|
||||||
|
⚠️ {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"
|
||||||
|
|
@ -183,18 +185,44 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
|
||||||
: `$${pricingCalc.base_subtotal}`}
|
: `$${pricingCalc.base_subtotal}`}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{pricingCalc.total_discounts > 0 && (
|
{pricingCalc.bundle_discount_amount > 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>Total Discounts</span>
|
<span>Bundle Discount</span>
|
||||||
<span>
|
<span>
|
||||||
-{currency === 'INR'
|
-{currency === 'INR'
|
||||||
? `₹${pricingCalc.total_discounts}`
|
? `₹${pricingCalc.bundle_discount_amount}`
|
||||||
: currency === 'EUR'
|
: currency === 'EUR'
|
||||||
? `€${pricingCalc.total_discounts}`
|
? `€${pricingCalc.bundle_discount_amount}`
|
||||||
: `$${pricingCalc.total_discounts}`}
|
: `$${pricingCalc.bundle_discount_amount}`}
|
||||||
</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>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue