Compare commits
7 Commits
715d9d294c
...
4ea4ed09c1
| Author | SHA1 | Date |
|---|---|---|
|
|
4ea4ed09c1 | |
|
|
ba6d47cef9 | |
|
|
c9e19047e9 | |
|
|
3793e1c2c2 | |
|
|
8f7864bb4d | |
|
|
ff62878cd6 | |
|
|
22404d03e1 |
|
|
@ -0,0 +1,2 @@
|
||||||
|
Branch: main
|
||||||
|
Commit: 75acd1de923fe310458333b66b71450f444eee2b
|
||||||
33
src/App.tsx
33
src/App.tsx
|
|
@ -291,14 +291,14 @@ export default function App() {
|
||||||
}
|
}
|
||||||
}, [userToken]);
|
}, [userToken]);
|
||||||
|
|
||||||
// Recalculate price whenever cart, coupon, or currency changes
|
// Recalculate price whenever cart, coupon, currency, or logged-in user changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (cart.length === 0) {
|
if (cart.length === 0) {
|
||||||
setPricingCalc(null);
|
setPricingCalc(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
calculatePricing();
|
calculatePricing();
|
||||||
}, [cart, appliedCoupon, currency]);
|
}, [cart, appliedCoupon, currency, loggedInUser]);
|
||||||
|
|
||||||
// Update currency and dial code automatically on country selection during registration
|
// Update currency and dial code automatically on country selection during registration
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -649,14 +649,40 @@ export default function App() {
|
||||||
setLoadingPricing(true);
|
setLoadingPricing(true);
|
||||||
try {
|
try {
|
||||||
const headers = userToken ? { 'Authorization': `Bearer ${userToken}` } : {};
|
const headers = userToken ? { 'Authorization': `Bearer ${userToken}` } : {};
|
||||||
|
|
||||||
|
// Derive owned categories from loggedInUser to ensure loyalty discounts apply automatically
|
||||||
|
const userOwnedCategories: string[] = [];
|
||||||
|
if (loggedInUser?.active_subscriptions) {
|
||||||
|
for (const sub of loggedInUser.active_subscriptions) {
|
||||||
|
const code = (sub.plan_code || '').toUpperCase();
|
||||||
|
if (code.startsWith('POINT')) userOwnedCategories.push('Points');
|
||||||
|
else if (code.startsWith('PATTERN')) userOwnedCategories.push('Pattern');
|
||||||
|
else if (code.startsWith('NUTRITION')) userOwnedCategories.push('Nutrition');
|
||||||
|
else if (code.startsWith('THERAPEUTIC')) userOwnedCategories.push('Therapeutics');
|
||||||
|
else if (code === 'LIFETIME_ALL' || code === 'LIFETIME_ALL_USD') userOwnedCategories.push('Lifetime');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (loggedInUser?.unlocked_module_slugs) {
|
||||||
|
for (const slug of loggedInUser.unlocked_module_slugs) {
|
||||||
|
const s = slug.toLowerCase();
|
||||||
|
if (s.includes('point') || s.includes('ear') || s.includes('scalp') || s.includes('tung')) userOwnedCategories.push('Points');
|
||||||
|
else if (s.includes('pattern') || s.includes('eight') || s.includes('principles') || s.includes('zang') || s.includes('stages') || s.includes('burners') || s.includes('channels') || s.includes('elements') || s.includes('vessel')) userOwnedCategories.push('Pattern');
|
||||||
|
else if (s.includes('nutrition') || s.includes('food')) userOwnedCategories.push('Nutrition');
|
||||||
|
else if (s.includes('therapeutic') || s.includes('gynae') || s.includes('auriculo')) userOwnedCategories.push('Therapeutics');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const uniqueOwnedCategories = Array.from(new Set(userOwnedCategories));
|
||||||
|
|
||||||
const res = await axios.post(`${API_BASE}/api/cart/calculate`, {
|
const res = await axios.post(`${API_BASE}/api/cart/calculate`, {
|
||||||
cart_item_codes: cart.map(item => item.code),
|
cart_item_codes: cart.map(item => item.code),
|
||||||
|
owned_category_names: uniqueOwnedCategories,
|
||||||
|
is_first_purchase: uniqueOwnedCategories.length === 0,
|
||||||
coupon_code: appliedCoupon || undefined,
|
coupon_code: appliedCoupon || undefined,
|
||||||
currency: currency
|
currency: currency
|
||||||
}, { headers });
|
}, { headers });
|
||||||
|
|
||||||
const calcData = res.data;
|
const calcData = res.data;
|
||||||
if (appliedCoupon && (!calcData.coupon_applied || calcData.coupon_applied === 'None')) {
|
if (appliedCoupon && (!calcData.coupon_applied || calcData.coupon_applied === 'None' || calcData.coupon_discount_amount <= 0)) {
|
||||||
calcData.coupon_error = calcData.coupon_error || 'Invalid or expired coupon code.';
|
calcData.coupon_error = calcData.coupon_error || 'Invalid or expired coupon code.';
|
||||||
}
|
}
|
||||||
setPricingCalc(calcData);
|
setPricingCalc(calcData);
|
||||||
|
|
@ -789,6 +815,7 @@ export default function App() {
|
||||||
pricingCalc &&
|
pricingCalc &&
|
||||||
pricingCalc.coupon_applied &&
|
pricingCalc.coupon_applied &&
|
||||||
pricingCalc.coupon_applied !== 'None' &&
|
pricingCalc.coupon_applied !== 'None' &&
|
||||||
|
pricingCalc.coupon_discount_amount > 0 &&
|
||||||
!pricingCalc.coupon_error
|
!pricingCalc.coupon_error
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,7 @@ 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 || !pricingCalc?.coupon_applied || pricingCalc?.coupon_applied === 'None' || (pricingCalc?.coupon_discount_amount !== undefined && pricingCalc?.coupon_discount_amount <= 0) ? (
|
||||||
<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 || 'Invalid or expired coupon code.'}
|
⚠️ {pricingCalc?.coupon_error || 'Invalid or expired coupon code.'}
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,17 @@ export interface UserProfile {
|
||||||
roles?: string[];
|
roles?: string[];
|
||||||
external_ref?: string;
|
external_ref?: string;
|
||||||
active_subscriptions: UserSubscription[];
|
active_subscriptions: UserSubscription[];
|
||||||
|
unlocked_module_slugs?: string[];
|
||||||
created_at?: string;
|
created_at?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PricingCalculation {
|
export interface PricingCalculation {
|
||||||
|
base_subtotal?: number;
|
||||||
original_price: number;
|
original_price: number;
|
||||||
discount_amount: number;
|
discount_amount: number;
|
||||||
|
discount_policy?: string;
|
||||||
|
bundle_discount_amount?: number;
|
||||||
|
total_discounts?: number;
|
||||||
taxable_amount: number;
|
taxable_amount: number;
|
||||||
gst_amount: number;
|
gst_amount: number;
|
||||||
convenience_fee?: number;
|
convenience_fee?: number;
|
||||||
|
|
@ -51,7 +56,9 @@ export interface PricingCalculation {
|
||||||
total_amount?: number;
|
total_amount?: number;
|
||||||
currency: Currency;
|
currency: Currency;
|
||||||
renewal_discount_amount?: number;
|
renewal_discount_amount?: number;
|
||||||
bundle_discount_amount?: number;
|
coupon_applied?: string;
|
||||||
|
coupon_discount_amount?: number;
|
||||||
|
coupon_error?: string | null;
|
||||||
applied_coupon?: {
|
applied_coupon?: {
|
||||||
code: string;
|
code: string;
|
||||||
discount_type: 'percentage' | 'fixed';
|
discount_type: 'percentage' | 'fixed';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue