Compare commits
No commits in common. "main" and "test/storefront-e2e-setup" have entirely different histories.
main
...
test/store
218
src/App.tsx
218
src/App.tsx
|
|
@ -2,7 +2,6 @@ import { useState, useEffect, useMemo } from 'react';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
import { CURRICULUM_MODULES } from './constants/modules';
|
import { CURRICULUM_MODULES } from './constants/modules';
|
||||||
import { buildDynamicCatalog } from './utils/catalog';
|
|
||||||
import { getCountryRuleByName } from './constants/countries';
|
import { getCountryRuleByName } from './constants/countries';
|
||||||
import type { ModuleItem, Currency, UserProfile, VerificationResult, PublicPlan } from './types';
|
import type { ModuleItem, Currency, UserProfile, VerificationResult, PublicPlan } from './types';
|
||||||
import { API_BASE } from './services/api';
|
import { API_BASE } from './services/api';
|
||||||
|
|
@ -177,60 +176,109 @@ export default function App() {
|
||||||
const [showBillingPhoneModal, setShowBillingPhoneModal] = useState<boolean>(false);
|
const [showBillingPhoneModal, setShowBillingPhoneModal] = useState<boolean>(false);
|
||||||
const [pendingCheckoutAfterPhone, setPendingCheckoutAfterPhone] = useState<boolean>(false);
|
const [pendingCheckoutAfterPhone, setPendingCheckoutAfterPhone] = useState<boolean>(false);
|
||||||
|
|
||||||
// Dynamic Public Storefront Plans & Modules
|
// Dynamic Public Storefront Plans
|
||||||
const [publicPlans, setPublicPlans] = useState<PublicPlan[]>([]);
|
const [publicPlans, setPublicPlans] = useState<PublicPlan[]>([]);
|
||||||
const [apiModules, setApiModules] = useState<any[]>([]);
|
|
||||||
const [pendingUrlPlanCode, setPendingUrlPlanCode] = useState<string | null>(null);
|
|
||||||
const [plansLoaded, setPlansLoaded] = useState<boolean>(false);
|
|
||||||
|
|
||||||
const fetchPublicPlans = async () => {
|
const fetchPublicPlans = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(`${API_BASE}/api/plans`);
|
const res = await axios.get(`${API_BASE}/api/plans`);
|
||||||
if (Array.isArray(res.data)) {
|
if (Array.isArray(res.data)) {
|
||||||
setPublicPlans(res.data);
|
setPublicPlans(res.data);
|
||||||
setPlansLoaded(true);
|
fetchModuleCategories(res.data);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load public plans:', err);
|
console.error('Failed to load public plans:', err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Dynamic Curriculum Modules derived from /api/plans + /api/contents/modules
|
// Dynamic Curriculum Modules with Live Categories
|
||||||
const [curriculumModules, setCurriculumModules] = useState<ModuleItem[]>(CURRICULUM_MODULES);
|
const [curriculumModules, setCurriculumModules] = useState<ModuleItem[]>(CURRICULUM_MODULES);
|
||||||
|
|
||||||
const fetchModuleCategories = async () => {
|
const fetchModuleCategories = async (plansList?: PublicPlan[]) => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(`${API_BASE}/api/contents/modules`);
|
const res = await axios.get(`${API_BASE}/api/contents/modules`);
|
||||||
const mods: any[] = Array.isArray(res.data) ? res.data : (res.data?.modules || []);
|
const apiModules: any[] = res.data?.modules || [];
|
||||||
if (mods.length > 0) {
|
const currentPlans = plansList && plansList.length > 0 ? plansList : publicPlans;
|
||||||
setApiModules(mods);
|
if (apiModules.length > 0) {
|
||||||
|
const normalizeCategory = (cat?: string): string | null => {
|
||||||
|
if (!cat) return null;
|
||||||
|
const c = cat.toLowerCase().trim();
|
||||||
|
if (c === 'point' || c === 'points') return 'Points';
|
||||||
|
if (c === 'pattern' || c === 'patterns' || c === 'five-elements') return 'Pattern';
|
||||||
|
if (c === 'nutrition') return 'Nutrition';
|
||||||
|
if (c === 'therapeutics' || c === 'therapeutic') return 'Therapeutics';
|
||||||
|
if (c === 'lifetime') return 'Lifetime';
|
||||||
|
return cat.charAt(0).toUpperCase() + cat.slice(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
setCurriculumModules((prev) =>
|
||||||
|
prev.map((item) => {
|
||||||
|
// 1. If item maps directly to a plan with single module slug, match by that slug
|
||||||
|
const matchedPlan = currentPlans.find((p) => p.code === item.code || p.base_code === item.code);
|
||||||
|
let matched: any = null;
|
||||||
|
if (matchedPlan) {
|
||||||
|
const slugs: string[] = matchedPlan.module_slugs || (matchedPlan.modules || []).map((m: any) => m.slug).filter(Boolean);
|
||||||
|
if (slugs.length === 1) {
|
||||||
|
const targetSlug = slugs[0].toLowerCase();
|
||||||
|
matched = apiModules.find((m) => (m.slug || '').toLowerCase() === targetSlug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Direct code match
|
||||||
|
if (!matched) {
|
||||||
|
const iCode = (item.code || '').toLowerCase();
|
||||||
|
matched = apiModules.find((m) => (m.code || '').toLowerCase() === iCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Normalized semantic match without collisions
|
||||||
|
if (!matched) {
|
||||||
|
const iName = item.name.toLowerCase();
|
||||||
|
const cleanI = iName.replace('points:', '').replace('therapeutics:', '').split('(')[0].trim();
|
||||||
|
|
||||||
|
matched = apiModules.find((m) => {
|
||||||
|
const mSlug = (m.slug || '').toLowerCase();
|
||||||
|
const mName = (m.name || '').toLowerCase();
|
||||||
|
const cleanM = mName.replace('points:', '').replace('therapeutics:', '').split('(')[0].trim();
|
||||||
|
|
||||||
|
if (cleanI.includes('scalp') && (cleanM.includes('scalp') || mSlug.includes('scalp'))) return true;
|
||||||
|
|
||||||
|
// Disambiguate Ear Reflexology / Auriculotherapy vs Ear Acupuncture
|
||||||
|
if (cleanI.includes('reflexology') || item.code === 'THERAPEUTICS_EAR') {
|
||||||
|
return mSlug.includes('auriculo') || cleanM.includes('reflexology') || mSlug.includes('reflexology');
|
||||||
|
}
|
||||||
|
if (cleanI.includes('ear') || item.code === 'POINTS_EAR') {
|
||||||
|
return mSlug.includes('ear-acupuncture') || (cleanM.includes('ear') && !mSlug.includes('auriculo') && !cleanM.includes('reflexology'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cleanI.includes('acu') && cleanM.includes('acupuncture') && !cleanI.includes('scalp') && !cleanI.includes('ear')) return true;
|
||||||
|
if (cleanI.includes('gyneco') && mSlug.includes('gyneco')) return true;
|
||||||
|
if (cleanI.includes('eight') && mSlug.includes('eight')) return true;
|
||||||
|
if (cleanI.includes('zang') && mSlug.includes('tcm-pattern')) return true;
|
||||||
|
if (cleanI.includes('qi') && mSlug.includes('qi')) return true;
|
||||||
|
if (cleanI.includes('pathogenic') && mSlug.includes('pathogenic')) return true;
|
||||||
|
if (cleanI.includes('six') && mSlug.includes('six')) return true;
|
||||||
|
if (cleanI.includes('four') && mSlug.includes('four')) return true;
|
||||||
|
if (cleanI.includes('three') && mSlug.includes('three')) return true;
|
||||||
|
if (cleanI.includes('five') && mSlug.includes('five')) return true;
|
||||||
|
if (cleanI.includes('food') && mSlug.includes('nutrition')) return true;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawCat = matched?.category || matched?.metadata?.category || matched?.metadata?.kind;
|
||||||
|
const updatedCat = normalizeCategory(rawCat);
|
||||||
|
if (updatedCat) {
|
||||||
|
return { ...item, category: updatedCat };
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load module categories:', err);
|
console.error('Failed to load module categories:', err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (publicPlans.length > 0) {
|
|
||||||
setCurriculumModules(buildDynamicCatalog(publicPlans, apiModules));
|
|
||||||
}
|
|
||||||
}, [publicPlans, apiModules]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!pendingUrlPlanCode) return;
|
|
||||||
const targetModule = curriculumModules.find(
|
|
||||||
(m) => m.code.toUpperCase() === pendingUrlPlanCode,
|
|
||||||
);
|
|
||||||
if (targetModule) {
|
|
||||||
setCart([targetModule]);
|
|
||||||
setShowLockedByCategory((prev) => ({
|
|
||||||
...prev,
|
|
||||||
[targetModule.category]: true,
|
|
||||||
}));
|
|
||||||
setPendingUrlPlanCode(null);
|
|
||||||
}
|
|
||||||
}, [pendingUrlPlanCode, curriculumModules]);
|
|
||||||
|
|
||||||
|
|
||||||
const getLivePlan = (code: string) => {
|
const getLivePlan = (code: string) => {
|
||||||
return publicPlans.find(p => p.code === code || p.base_code === code);
|
return publicPlans.find(p => p.code === code || p.base_code === code);
|
||||||
|
|
@ -239,27 +287,18 @@ export default function App() {
|
||||||
const getModulePrice = (item: ModuleItem) => {
|
const getModulePrice = (item: ModuleItem) => {
|
||||||
const livePlan = getLivePlan(item.code);
|
const livePlan = getLivePlan(item.code);
|
||||||
if (livePlan) {
|
if (livePlan) {
|
||||||
const priceInr = livePlan.price_inr ?? 0;
|
|
||||||
const priceUsd = livePlan.price_usd ?? 0;
|
|
||||||
const priceEur = livePlan.price_eur ?? livePlan.price_usd ?? 0;
|
|
||||||
const activeCurrencyPrice =
|
|
||||||
currency === 'INR' ? priceInr : currency === 'EUR' ? priceEur : priceUsd;
|
|
||||||
const planIsActive = livePlan.is_active !== undefined ? livePlan.is_active : true;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
priceInr: livePlan.price_inr ?? item.priceInr,
|
priceInr: livePlan.price_inr ?? item.priceInr,
|
||||||
priceUsd: livePlan.price_usd ?? item.priceUsd,
|
priceUsd: livePlan.price_usd ?? item.priceUsd,
|
||||||
priceEur: livePlan.price_eur ?? livePlan.price_usd ?? item.priceEur,
|
priceEur: livePlan.price_eur ?? livePlan.price_usd ?? item.priceEur,
|
||||||
// Require active flag and a positive price in the user's billing currency
|
isActive: livePlan.is_active !== undefined ? livePlan.is_active : true,
|
||||||
isActive: planIsActive && activeCurrencyPrice > 0,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
priceInr: item.priceInr,
|
priceInr: item.priceInr,
|
||||||
priceUsd: item.priceUsd,
|
priceUsd: item.priceUsd,
|
||||||
priceEur: item.priceEur,
|
priceEur: item.priceEur,
|
||||||
// Once /api/plans has loaded, catalog plans absent from it are inactive in the DB
|
isActive: true,
|
||||||
isActive: !plansLoaded,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -310,8 +349,6 @@ export default function App() {
|
||||||
...prev,
|
...prev,
|
||||||
[targetModule.category]: true
|
[targetModule.category]: true
|
||||||
}));
|
}));
|
||||||
} else {
|
|
||||||
setPendingUrlPlanCode(normalizedPlanCode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -369,7 +406,6 @@ export default function App() {
|
||||||
const mergedUser = {
|
const mergedUser = {
|
||||||
...profileRes.data,
|
...profileRes.data,
|
||||||
active_subscriptions: accessRes.data.active_subscriptions || [],
|
active_subscriptions: accessRes.data.active_subscriptions || [],
|
||||||
unlocked_module_codes: accessRes.data.unlocked_module_codes || [],
|
|
||||||
unlocked_module_slugs: accessRes.data.unlocked_module_slugs || [],
|
unlocked_module_slugs: accessRes.data.unlocked_module_slugs || [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -381,8 +417,7 @@ export default function App() {
|
||||||
setCurrency(countryRule.currency);
|
setCurrency(countryRule.currency);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to fetch user profile:', err);
|
console.error('Failed to fetch user profile:', err);
|
||||||
// Clear invalid/stale token silently so expired storage does not hijack initial storefront load into /logged-out.
|
handleLogout();
|
||||||
resetAuthSession();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -396,7 +431,7 @@ export default function App() {
|
||||||
setChangeConfirmPassword('');
|
setChangeConfirmPassword('');
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetAuthSession = () => {
|
const handleLogout = () => {
|
||||||
localStorage.removeItem('access_token');
|
localStorage.removeItem('access_token');
|
||||||
setUserToken(null);
|
setUserToken(null);
|
||||||
setLoggedInUser(null);
|
setLoggedInUser(null);
|
||||||
|
|
@ -412,10 +447,6 @@ export default function App() {
|
||||||
setProfileError(null);
|
setProfileError(null);
|
||||||
setProfileSuccess(false);
|
setProfileSuccess(false);
|
||||||
setShowAuthModal(false);
|
setShowAuthModal(false);
|
||||||
};
|
|
||||||
|
|
||||||
const handleLogout = () => {
|
|
||||||
resetAuthSession();
|
|
||||||
switchTab('logged-out');
|
switchTab('logged-out');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -616,8 +647,8 @@ export default function App() {
|
||||||
|
|
||||||
const userEmail = loggedInUser?.email || authEmail;
|
const userEmail = loggedInUser?.email || authEmail;
|
||||||
|
|
||||||
// Invalidate active session without navigating to the logged-out screen so user stays in place for re-auth
|
// Invalidate active session so re-authentication is required
|
||||||
resetAuthSession();
|
handleLogout();
|
||||||
setShowProfileDrawer(false);
|
setShowProfileDrawer(false);
|
||||||
|
|
||||||
// Pre-fill email and set auth mode to login for seamless re-auth
|
// Pre-fill email and set auth mode to login for seamless re-auth
|
||||||
|
|
@ -708,40 +739,22 @@ export default function App() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Keep cart synced with live plans: refresh prices and prune inactive/currency-unavailable plans
|
// Keep cart items dynamic prices updated when publicPlans are loaded
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!plansLoaded || cart.length === 0) return;
|
if (publicPlans.length > 0 && cart.length > 0) {
|
||||||
|
setCart(prev =>
|
||||||
const nextCart: ModuleItem[] = [];
|
prev.map(item => {
|
||||||
for (const item of cart) {
|
|
||||||
const live = getModulePrice(item);
|
const live = getModulePrice(item);
|
||||||
if (!live.isActive) continue;
|
return {
|
||||||
nextCart.push({
|
|
||||||
...item,
|
...item,
|
||||||
priceInr: live.priceInr,
|
priceInr: live.priceInr,
|
||||||
priceUsd: live.priceUsd,
|
priceUsd: live.priceUsd,
|
||||||
priceEur: live.priceEur,
|
priceEur: live.priceEur,
|
||||||
});
|
};
|
||||||
}
|
})
|
||||||
|
|
||||||
const changed =
|
|
||||||
nextCart.length !== cart.length ||
|
|
||||||
nextCart.some(
|
|
||||||
(n, idx) =>
|
|
||||||
n.priceInr !== cart[idx].priceInr ||
|
|
||||||
n.priceUsd !== cart[idx].priceUsd ||
|
|
||||||
n.priceEur !== cart[idx].priceEur
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (changed) {
|
|
||||||
setCart(nextCart);
|
|
||||||
if (nextCart.length === 0) {
|
|
||||||
setAppliedCoupon(null);
|
|
||||||
setCouponCode('');
|
|
||||||
setPricingCalc(null);
|
|
||||||
}
|
}
|
||||||
}
|
}, [publicPlans]);
|
||||||
}, [publicPlans, plansLoaded, currency, cart]);
|
|
||||||
|
|
||||||
const calculatePricing = async () => {
|
const calculatePricing = async () => {
|
||||||
setLoadingPricing(true);
|
setLoadingPricing(true);
|
||||||
|
|
@ -873,60 +886,25 @@ export default function App() {
|
||||||
if (!loggedInUser?.active_subscriptions) return false;
|
if (!loggedInUser?.active_subscriptions) return false;
|
||||||
|
|
||||||
const hasLifetime = loggedInUser.active_subscriptions.some((sub: any) =>
|
const hasLifetime = loggedInUser.active_subscriptions.some((sub: any) =>
|
||||||
sub.plan_code === 'LIFETIME_ALL' ||
|
sub.plan_code === 'LIFETIME_ALL' || sub.plan_code === 'LIFETIME_ALL_USD'
|
||||||
sub.plan_code === 'LIFETIME_ALL_USD' ||
|
|
||||||
sub.plan_code === 'LIFETIME_ALL_EUR'
|
|
||||||
);
|
);
|
||||||
if (hasLifetime) return true;
|
if (hasLifetime) return true;
|
||||||
|
|
||||||
const hasDirectSub = loggedInUser.active_subscriptions.some(
|
|
||||||
(sub: any) =>
|
|
||||||
sub.plan_code === code ||
|
|
||||||
sub.plan_code === `${code}_USD` ||
|
|
||||||
sub.plan_code === `${code}_EUR`
|
|
||||||
);
|
|
||||||
if (hasDirectSub) return true;
|
|
||||||
|
|
||||||
// Dynamic unlock check via /api/access/me unlocked_module_codes / unlocked_module_slugs
|
|
||||||
const unlockedCodes = new Set(
|
|
||||||
(loggedInUser.unlocked_module_codes || []).map((c: string) => c.toLowerCase()),
|
|
||||||
);
|
|
||||||
const unlockedSlugs = new Set(
|
|
||||||
(loggedInUser.unlocked_module_slugs || []).map((s: string) => s.toLowerCase()),
|
|
||||||
);
|
|
||||||
if (unlockedCodes.size > 0 || unlockedSlugs.size > 0) {
|
|
||||||
const matchedPlan = getLivePlan(code);
|
|
||||||
const planModules = matchedPlan?.modules || [];
|
|
||||||
if (planModules.length > 0) {
|
|
||||||
const allModulesUnlocked = planModules.every(
|
|
||||||
(m: any) =>
|
|
||||||
(m.code && unlockedCodes.has(String(m.code).toLowerCase())) ||
|
|
||||||
(m.slug && unlockedSlugs.has(String(m.slug).toLowerCase())),
|
|
||||||
);
|
|
||||||
if (allModulesUnlocked) return true;
|
|
||||||
}
|
|
||||||
const planSlugs = matchedPlan?.module_slugs || [];
|
|
||||||
if (planSlugs.length > 0 && planSlugs.every((s: string) => unlockedSlugs.has(s.toLowerCase()))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Legacy fallback when publicPlans lacks module lists
|
|
||||||
if (code === 'POINTS_ACU' || code === 'POINTS_SCALP' || code === 'POINTS_EAR' || code === 'POINTS_TUNG') {
|
if (code === 'POINTS_ACU' || code === 'POINTS_SCALP' || code === 'POINTS_EAR' || code === 'POINTS_TUNG') {
|
||||||
const hasPointsPack = loggedInUser.active_subscriptions.some((sub: any) =>
|
const hasPointsPack = loggedInUser.active_subscriptions.some((sub: any) =>
|
||||||
sub.plan_code === 'POINTS_PACK' || sub.plan_code === 'POINTS_PACK_USD' || sub.plan_code === 'POINTS_PACK_EUR'
|
sub.plan_code === 'POINTS_PACK' || sub.plan_code === 'POINTS_PACK_USD'
|
||||||
);
|
);
|
||||||
if (hasPointsPack) return true;
|
if (hasPointsPack) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code === 'THERAPEUTICS_GYNAE' || code === 'THERAPEUTICS_EAR') {
|
if (code === 'THERAPEUTICS_GYNAE' || code === 'THERAPEUTICS_EAR') {
|
||||||
const hasTherapeuticsPack = loggedInUser.active_subscriptions.some((sub: any) =>
|
const hasTherapeuticsPack = loggedInUser.active_subscriptions.some((sub: any) =>
|
||||||
sub.plan_code === 'THERAPEUTICS_CORE' || sub.plan_code === 'THERAPEUTICS_CORE_USD' || sub.plan_code === 'THERAPEUTICS_CORE_EUR'
|
sub.plan_code === 'THERAPEUTICS_CORE' || sub.plan_code === 'THERAPEUTICS_CORE_USD'
|
||||||
);
|
);
|
||||||
if (hasTherapeuticsPack) return true;
|
if (hasTherapeuticsPack) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return loggedInUser.active_subscriptions.some((sub: any) => sub.plan_code === code || sub.plan_code === `${code}_USD`);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Automatically remove already unlocked modules from the cart
|
// Automatically remove already unlocked modules from the cart
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { BookOpen, Check } from 'lucide-react';
|
import { BookOpen, Check } from 'lucide-react';
|
||||||
import type { ModuleItem, PublicPlan, Currency } from '../../types';
|
import type { ModuleItem, PublicPlan, Currency } from '../../types';
|
||||||
import { CORE_PACK_CODES, MAIN_CATEGORIES, resolvePlanCategory } from '../../utils/catalog';
|
|
||||||
|
|
||||||
interface CatalogSectionProps {
|
interface CatalogSectionProps {
|
||||||
curriculumModules: ModuleItem[];
|
curriculumModules: ModuleItem[];
|
||||||
|
|
@ -31,11 +30,6 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
showLockedByCategory,
|
showLockedByCategory,
|
||||||
setShowLockedByCategory,
|
setShowLockedByCategory,
|
||||||
}) => {
|
}) => {
|
||||||
const countLockedActive = (predicate: (category: string) => boolean) =>
|
|
||||||
curriculumModules.filter(
|
|
||||||
m => predicate(m.category) && !isModuleUnlocked(m.code) && getModulePrice(m).isActive
|
|
||||||
).length;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="xl:col-span-2 space-y-6">
|
<div className="xl:col-span-2 space-y-6">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
|
@ -63,7 +57,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Points: !prev.Points }))}
|
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Points: !prev.Points }))}
|
||||||
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
|
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
|
||||||
>
|
>
|
||||||
{showLockedByCategory.Points ? 'Hide Locked' : 'Show Locked'} ({countLockedActive(c => c === 'Points')})
|
{showLockedByCategory.Points ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => m.category === 'Points' && !isModuleUnlocked(m.code)).length})
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
|
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
|
||||||
|
|
@ -78,9 +72,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{(() => {
|
{(() => {
|
||||||
const items = curriculumModules
|
const items = curriculumModules.filter(m => m.category === 'Points');
|
||||||
.filter(m => m.category === 'Points')
|
|
||||||
.sort((a, b) => (a.sortOrder ?? 500) - (b.sortOrder ?? 500));
|
|
||||||
const visible = items.filter(sub => {
|
const visible = items.filter(sub => {
|
||||||
const isUnlocked = isModuleUnlocked(sub.code);
|
const isUnlocked = isModuleUnlocked(sub.code);
|
||||||
const live = getModulePrice(sub);
|
const live = getModulePrice(sub);
|
||||||
|
|
@ -184,7 +176,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Pattern: !prev.Pattern }))}
|
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Pattern: !prev.Pattern }))}
|
||||||
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
|
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
|
||||||
>
|
>
|
||||||
{showLockedByCategory.Pattern ? 'Hide Locked' : 'Show Locked'} ({countLockedActive(c => c === 'Pattern' || c === 'Patterns')})
|
{showLockedByCategory.Pattern ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => (m.category === 'Pattern' || m.category === 'Patterns') && !isModuleUnlocked(m.code)).length})
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
|
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
|
||||||
|
|
@ -199,9 +191,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{(() => {
|
{(() => {
|
||||||
const items = curriculumModules
|
const items = curriculumModules.filter(m => m.category === 'Pattern' || m.category === 'Patterns');
|
||||||
.filter(m => m.category === 'Pattern' || m.category === 'Patterns')
|
|
||||||
.sort((a, b) => (a.sortOrder ?? 500) - (b.sortOrder ?? 500));
|
|
||||||
const visible = items.filter(sub => {
|
const visible = items.filter(sub => {
|
||||||
const isUnlocked = isModuleUnlocked(sub.code);
|
const isUnlocked = isModuleUnlocked(sub.code);
|
||||||
const live = getModulePrice(sub);
|
const live = getModulePrice(sub);
|
||||||
|
|
@ -305,7 +295,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Nutrition: !prev.Nutrition }))}
|
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Nutrition: !prev.Nutrition }))}
|
||||||
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
|
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
|
||||||
>
|
>
|
||||||
{showLockedByCategory.Nutrition ? 'Hide Locked' : 'Show Locked'} ({countLockedActive(c => c === 'Nutrition')})
|
{showLockedByCategory.Nutrition ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => m.category === 'Nutrition' && !isModuleUnlocked(m.code)).length})
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
|
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
|
||||||
|
|
@ -320,9 +310,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{(() => {
|
{(() => {
|
||||||
const items = curriculumModules
|
const items = curriculumModules.filter(m => m.category === 'Nutrition');
|
||||||
.filter(m => m.category === 'Nutrition')
|
|
||||||
.sort((a, b) => (a.sortOrder ?? 500) - (b.sortOrder ?? 500));
|
|
||||||
const visible = items.filter(sub => {
|
const visible = items.filter(sub => {
|
||||||
const isUnlocked = isModuleUnlocked(sub.code);
|
const isUnlocked = isModuleUnlocked(sub.code);
|
||||||
const live = getModulePrice(sub);
|
const live = getModulePrice(sub);
|
||||||
|
|
@ -426,7 +414,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Therapeutics: !prev.Therapeutics }))}
|
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Therapeutics: !prev.Therapeutics }))}
|
||||||
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
|
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
|
||||||
>
|
>
|
||||||
{showLockedByCategory.Therapeutics ? 'Hide Locked' : 'Show Locked'} ({countLockedActive(c => c === 'Therapeutics')})
|
{showLockedByCategory.Therapeutics ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => m.category === 'Therapeutics' && !isModuleUnlocked(m.code)).length})
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
|
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
|
||||||
|
|
@ -441,9 +429,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{(() => {
|
{(() => {
|
||||||
const items = curriculumModules
|
const items = curriculumModules.filter(m => m.category === 'Therapeutics');
|
||||||
.filter(m => m.category === 'Therapeutics')
|
|
||||||
.sort((a, b) => (a.sortOrder ?? 500) - (b.sortOrder ?? 500));
|
|
||||||
const visible = items.filter(sub => {
|
const visible = items.filter(sub => {
|
||||||
const isUnlocked = isModuleUnlocked(sub.code);
|
const isUnlocked = isModuleUnlocked(sub.code);
|
||||||
const live = getModulePrice(sub);
|
const live = getModulePrice(sub);
|
||||||
|
|
@ -548,7 +534,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Lifetime: !prev.Lifetime }))}
|
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Lifetime: !prev.Lifetime }))}
|
||||||
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-2 py-1 rounded transition-colors"
|
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-2 py-1 rounded transition-colors"
|
||||||
>
|
>
|
||||||
{showLockedByCategory.Lifetime ? 'Hide Locked' : 'Show Locked'} ({countLockedActive(c => c === 'Lifetime')})
|
{showLockedByCategory.Lifetime ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => m.category === 'Lifetime' && !isModuleUnlocked(m.code)).length})
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<h3 className="text-xl font-black text-amber-900 tracking-tight">Lifetime Unlimited Access Pass</h3>
|
<h3 className="text-xl font-black text-amber-900 tracking-tight">Lifetime Unlimited Access Pass</h3>
|
||||||
|
|
@ -647,15 +633,10 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
{/* CARD 6: Custom Packages & Bundles (Dynamic Admin Plans) */}
|
{/* CARD 6: Custom Packages & Bundles (Dynamic Admin Plans) */}
|
||||||
{(() => {
|
{(() => {
|
||||||
const customPlans = publicPlans.filter((p: any) => {
|
const customPlans = publicPlans.filter((p: any) => {
|
||||||
const code = (p.base_code || p.code || '').toUpperCase();
|
const code = p.base_code || p.code;
|
||||||
const activePrice = currency === 'INR' ? (p.price_inr ?? 0) : currency === 'EUR' ? (p.price_eur ?? p.price_usd ?? 0) : (p.price_usd ?? 0);
|
const isCustom = !['POINTS_ACU', 'POINTS_SCALP', 'POINTS_EAR', 'POINTS_TUNG', 'POINTS_PACK', 'PATTERN_CORE', 'NUTRITION_CORE', 'THERAPEUTICS_GYNAE', 'THERAPEUTICS_EAR', 'THERAPEUTICS_CORE', 'LIFETIME_ALL'].includes(code);
|
||||||
const isActive = p.is_active !== false && activePrice > 0;
|
const isActive = p.is_active !== false;
|
||||||
if (!isActive || code === 'LIFETIME_ALL' || CORE_PACK_CODES.has(code)) return false;
|
return isCustom && isActive;
|
||||||
if (p.plan_type === 'bundle') return true;
|
|
||||||
const resolvedCat =
|
|
||||||
curriculumModules.find((m) => m.code.toUpperCase() === code)?.category ||
|
|
||||||
resolvePlanCategory(p);
|
|
||||||
return !MAIN_CATEGORIES.has(resolvedCat) && resolvedCat !== 'Lifetime';
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (customPlans.length === 0) return null;
|
if (customPlans.length === 0) return null;
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,6 @@ export interface ModuleItem {
|
||||||
desc: string;
|
desc: string;
|
||||||
color: string;
|
color: string;
|
||||||
isRenewal?: boolean;
|
isRenewal?: boolean;
|
||||||
sortOrder?: number;
|
|
||||||
planType?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserSubscription {
|
export interface UserSubscription {
|
||||||
|
|
@ -39,7 +37,6 @@ export interface UserProfile {
|
||||||
roles?: string[];
|
roles?: string[];
|
||||||
external_ref?: string;
|
external_ref?: string;
|
||||||
active_subscriptions: UserSubscription[];
|
active_subscriptions: UserSubscription[];
|
||||||
unlocked_module_codes?: string[];
|
|
||||||
unlocked_module_slugs?: string[];
|
unlocked_module_slugs?: string[];
|
||||||
created_at?: string;
|
created_at?: string;
|
||||||
}
|
}
|
||||||
|
|
@ -79,27 +76,15 @@ export interface PublicPlan {
|
||||||
code: string;
|
code: string;
|
||||||
base_code?: string;
|
base_code?: string;
|
||||||
name: string;
|
name: string;
|
||||||
plan_type?: string;
|
|
||||||
billing_period?: string;
|
|
||||||
price_inr?: number;
|
price_inr?: number;
|
||||||
price_usd?: number;
|
price_usd?: number;
|
||||||
price_eur?: number;
|
price_eur?: number;
|
||||||
is_active?: boolean;
|
is_active?: boolean;
|
||||||
pricing_status?: string;
|
|
||||||
color?: string;
|
|
||||||
badge_text?: string;
|
badge_text?: string;
|
||||||
heading?: string;
|
heading?: string;
|
||||||
subtitle?: string;
|
subtitle?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
modules?: Array<{
|
modules?: Array<{ id?: string; name: string; slug?: string }>;
|
||||||
id?: string;
|
|
||||||
code?: string;
|
|
||||||
name: string;
|
|
||||||
slug?: string;
|
|
||||||
description?: string;
|
|
||||||
category?: string;
|
|
||||||
sort_order?: number;
|
|
||||||
}>;
|
|
||||||
module_slugs?: string[];
|
module_slugs?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,223 +0,0 @@
|
||||||
import { CURRICULUM_MODULES } from '../constants/modules';
|
|
||||||
import type { ModuleItem, PublicPlan } from '../types';
|
|
||||||
|
|
||||||
export const CORE_PACK_CODES = new Set([
|
|
||||||
'POINTS_PACK',
|
|
||||||
'PATTERN_CORE',
|
|
||||||
'NUTRITION_CORE',
|
|
||||||
'THERAPEUTICS_CORE',
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const MAIN_CATEGORIES = new Set([
|
|
||||||
'Points',
|
|
||||||
'Pattern',
|
|
||||||
'Nutrition',
|
|
||||||
'Therapeutics',
|
|
||||||
]);
|
|
||||||
|
|
||||||
const MULTI_ITEM_CORE_PACKS: Record<string, { category: string; packTitle: string; defaultColor: string }> = {
|
|
||||||
PATTERN_CORE: {
|
|
||||||
category: 'Pattern',
|
|
||||||
packTitle: 'Pattern: Complete Pack',
|
|
||||||
defaultColor: 'from-rose-600 to-orange-600',
|
|
||||||
},
|
|
||||||
NUTRITION_CORE: {
|
|
||||||
category: 'Nutrition',
|
|
||||||
packTitle: 'Nutrition: Complete Pack',
|
|
||||||
defaultColor: 'from-teal-500 to-green-600',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export function normalizeCategory(cat?: string | null): string | null {
|
|
||||||
if (!cat) return null;
|
|
||||||
const c = cat.toLowerCase().trim();
|
|
||||||
if (c === 'point' || c === 'points') return 'Points';
|
|
||||||
if (c === 'pattern' || c === 'patterns' || c === 'five-elements') return 'Pattern';
|
|
||||||
if (c === 'nutrition') return 'Nutrition';
|
|
||||||
if (c === 'therapeutics' || c === 'therapeutic') return 'Therapeutics';
|
|
||||||
if (c === 'lifetime') return 'Lifetime';
|
|
||||||
return cat.charAt(0).toUpperCase() + cat.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function findMatchingApiModule(
|
|
||||||
plan: PublicPlan,
|
|
||||||
apiModules: any[],
|
|
||||||
): any | undefined {
|
|
||||||
if (!apiModules.length) return undefined;
|
|
||||||
const firstMod = plan.modules?.[0];
|
|
||||||
const slugs = plan.module_slugs || (plan.modules || []).map((m) => m.slug).filter(Boolean) as string[];
|
|
||||||
const targetSlug = (firstMod?.slug || (slugs.length === 1 ? slugs[0] : undefined))?.toLowerCase();
|
|
||||||
const targetCode = firstMod?.code?.toLowerCase();
|
|
||||||
|
|
||||||
if (targetCode) {
|
|
||||||
const byCode = apiModules.find((m) => (m.code || '').toLowerCase() === targetCode);
|
|
||||||
if (byCode) return byCode;
|
|
||||||
}
|
|
||||||
if (targetSlug) {
|
|
||||||
const bySlug = apiModules.find((m) => (m.slug || '').toLowerCase() === targetSlug);
|
|
||||||
if (bySlug) return bySlug;
|
|
||||||
}
|
|
||||||
const pCode = (plan.base_code || plan.code || '').toLowerCase();
|
|
||||||
return apiModules.find(
|
|
||||||
(m) => (m.plan_code || '').toLowerCase() === pCode || (m.code || '').toLowerCase() === pCode,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolvePlanCategory(plan: PublicPlan, apiModules: any[] = []): string {
|
|
||||||
const code = (plan.base_code || plan.code || '').toUpperCase();
|
|
||||||
if (code === 'LIFETIME_ALL' || plan.plan_type === 'lifetime') return 'Lifetime';
|
|
||||||
if (code === 'POINTS_PACK') return 'Points';
|
|
||||||
if (code === 'PATTERN_CORE') return 'Pattern';
|
|
||||||
if (code === 'NUTRITION_CORE') return 'Nutrition';
|
|
||||||
if (code === 'THERAPEUTICS_CORE') return 'Therapeutics';
|
|
||||||
|
|
||||||
const firstMod = plan.modules?.[0];
|
|
||||||
const apiMatch = findMatchingApiModule(plan, apiModules);
|
|
||||||
const rawCat =
|
|
||||||
firstMod?.category ||
|
|
||||||
apiMatch?.category ||
|
|
||||||
apiMatch?.metadata?.category ||
|
|
||||||
apiMatch?.metadata?.kind;
|
|
||||||
const normalized = normalizeCategory(rawCat);
|
|
||||||
if (normalized) return normalized;
|
|
||||||
|
|
||||||
const fallback = CURRICULUM_MODULES.find((m) => m.code.toUpperCase() === code);
|
|
||||||
if (fallback) return fallback.category;
|
|
||||||
|
|
||||||
return plan.plan_type === 'bundle' ? 'Bundle' : 'Custom';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildDynamicCatalog(
|
|
||||||
publicPlans: PublicPlan[],
|
|
||||||
apiModules: any[] = [],
|
|
||||||
): ModuleItem[] {
|
|
||||||
if (!publicPlans || publicPlans.length === 0) {
|
|
||||||
return CURRICULUM_MODULES;
|
|
||||||
}
|
|
||||||
|
|
||||||
const items: ModuleItem[] = [];
|
|
||||||
|
|
||||||
for (const plan of publicPlans) {
|
|
||||||
const code = (plan.base_code || plan.code || '').toUpperCase();
|
|
||||||
if (!code) continue;
|
|
||||||
|
|
||||||
const fallbackEntries = CURRICULUM_MODULES.filter((m) => m.code.toUpperCase() === code);
|
|
||||||
const primaryFallback = fallbackEntries[fallbackEntries.length - 1];
|
|
||||||
|
|
||||||
const priceInr = plan.price_inr ?? primaryFallback?.priceInr ?? 0;
|
|
||||||
const priceUsd = plan.price_usd ?? primaryFallback?.priceUsd ?? 0;
|
|
||||||
const priceEur = plan.price_eur ?? plan.price_usd ?? primaryFallback?.priceEur ?? priceUsd;
|
|
||||||
const planColor = plan.color || primaryFallback?.color || 'from-teal-500 to-cyan-500';
|
|
||||||
const planDesc = plan.description || primaryFallback?.desc || '';
|
|
||||||
|
|
||||||
// 1. Multi-item Core Packs (PATTERN_CORE, NUTRITION_CORE): emit sub-items + Complete Pack row
|
|
||||||
if (code in MULTI_ITEM_CORE_PACKS) {
|
|
||||||
const cfg = MULTI_ITEM_CORE_PACKS[code];
|
|
||||||
const planModules = [...(plan.modules || [])].sort(
|
|
||||||
(a, b) => (a.sort_order ?? 500) - (b.sort_order ?? 500),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (planModules.length > 0) {
|
|
||||||
for (const mod of planModules) {
|
|
||||||
const apiMatch = apiModules.find(
|
|
||||||
(m) =>
|
|
||||||
(mod.code && (m.code || '').toLowerCase() === mod.code.toLowerCase()) ||
|
|
||||||
(mod.slug && (m.slug || '').toLowerCase() === mod.slug.toLowerCase()),
|
|
||||||
);
|
|
||||||
items.push({
|
|
||||||
code,
|
|
||||||
name: mod.name,
|
|
||||||
category: cfg.category,
|
|
||||||
priceInr,
|
|
||||||
priceUsd,
|
|
||||||
priceEur,
|
|
||||||
desc: mod.description || apiMatch?.description || planDesc,
|
|
||||||
color: planColor,
|
|
||||||
sortOrder: mod.sort_order ?? apiMatch?.sort_order ?? 500,
|
|
||||||
planType: plan.plan_type,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (planModules.length > 1) {
|
|
||||||
items.push({
|
|
||||||
code,
|
|
||||||
name: cfg.packTitle,
|
|
||||||
category: cfg.category,
|
|
||||||
priceInr,
|
|
||||||
priceUsd,
|
|
||||||
priceEur,
|
|
||||||
desc: planDesc || primaryFallback?.desc || `Unlock all ${cfg.category} modules.`,
|
|
||||||
color: cfg.defaultColor,
|
|
||||||
sortOrder: Number.MAX_SAFE_INTEGER,
|
|
||||||
planType: plan.plan_type,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (fallbackEntries.length > 0) {
|
|
||||||
for (const fb of fallbackEntries) {
|
|
||||||
items.push({
|
|
||||||
...fb,
|
|
||||||
priceInr,
|
|
||||||
priceUsd,
|
|
||||||
priceEur,
|
|
||||||
sortOrder: fb.name.includes('Complete Pack') ? Number.MAX_SAFE_INTEGER : 500,
|
|
||||||
planType: plan.plan_type,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Lifetime or Core Category Packs (POINTS_PACK, THERAPEUTICS_CORE)
|
|
||||||
if (code === 'LIFETIME_ALL' || CORE_PACK_CODES.has(code)) {
|
|
||||||
const category = resolvePlanCategory(plan, apiModules);
|
|
||||||
items.push({
|
|
||||||
code,
|
|
||||||
name: primaryFallback?.name || plan.name,
|
|
||||||
category,
|
|
||||||
priceInr,
|
|
||||||
priceUsd,
|
|
||||||
priceEur,
|
|
||||||
desc: planDesc,
|
|
||||||
color: planColor,
|
|
||||||
sortOrder: Number.MAX_SAFE_INTEGER,
|
|
||||||
planType: plan.plan_type,
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Custom Bundles (plan_type === 'bundle') — rendered in Card 6 (Custom Packages & Bundles)
|
|
||||||
if (plan.plan_type === 'bundle') {
|
|
||||||
items.push({
|
|
||||||
code,
|
|
||||||
name: plan.name,
|
|
||||||
category: 'Bundle',
|
|
||||||
priceInr,
|
|
||||||
priceUsd,
|
|
||||||
priceEur,
|
|
||||||
desc: planDesc || 'Custom bundled access.',
|
|
||||||
color: plan.color || 'from-slate-700 to-slate-900',
|
|
||||||
sortOrder: 500,
|
|
||||||
planType: plan.plan_type,
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Single-module plans (POINTS_*, THERAPEUTICS_*, MOD_*, or any one_time plan)
|
|
||||||
const firstMod = plan.modules?.[0];
|
|
||||||
const apiMatch = findMatchingApiModule(plan, apiModules);
|
|
||||||
const category = resolvePlanCategory(plan, apiModules);
|
|
||||||
items.push({
|
|
||||||
code,
|
|
||||||
name: primaryFallback?.name || plan.name || firstMod?.name || code,
|
|
||||||
category,
|
|
||||||
priceInr,
|
|
||||||
priceUsd,
|
|
||||||
priceEur,
|
|
||||||
desc: planDesc || firstMod?.description || apiMatch?.description || '',
|
|
||||||
color: planColor,
|
|
||||||
sortOrder: firstMod?.sort_order ?? apiMatch?.sort_order ?? 500,
|
|
||||||
planType: plan.plan_type,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
@ -88,43 +88,4 @@ test.describe('Catalog Section', () => {
|
||||||
await expect(page.getByText('Acu (EOV+Cat+Ext+MR)')).toBeVisible();
|
await expect(page.getByText('Acu (EOV+Cat+Ext+MR)')).toBeVisible();
|
||||||
await expect(page.getByText('Scalp', { exact: true })).not.toBeVisible();
|
await expect(page.getByText('Scalp', { exact: true })).not.toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('renders newly activated Module Builder plan in its category and supports ?planCode deep link', async ({ page }) => {
|
|
||||||
await mockPublicStoreApis(page);
|
|
||||||
await page.route('**/api/plans', async (route) => {
|
|
||||||
await route.fulfill({
|
|
||||||
status: 200,
|
|
||||||
contentType: 'application/json',
|
|
||||||
body: JSON.stringify([
|
|
||||||
...MOCK_PLANS,
|
|
||||||
{
|
|
||||||
code: 'MOD_M0044',
|
|
||||||
base_code: 'MOD_M0044',
|
|
||||||
name: 'Pediatric Disorders',
|
|
||||||
description: 'TCM pediatric treatment protocols.',
|
|
||||||
plan_type: 'one_time',
|
|
||||||
billing_period: 'yearly',
|
|
||||||
price_inr: 600,
|
|
||||||
price_usd: 15,
|
|
||||||
price_eur: 15,
|
|
||||||
is_active: true,
|
|
||||||
modules: [
|
|
||||||
{
|
|
||||||
code: 'm0044',
|
|
||||||
slug: 'pediatric-disorders',
|
|
||||||
name: 'Pediatric Disorders',
|
|
||||||
description: 'TCM pediatric treatment protocols.',
|
|
||||||
category: 'Therapeutics',
|
|
||||||
sort_order: 40,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
await page.goto('./?planCode=MOD_M0044');
|
|
||||||
await expect(page.getByText('Pediatric Disorders').first()).toBeVisible();
|
|
||||||
await expect(page.getByText('1 Item')).toBeVisible();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -49,28 +49,6 @@ const mockPlansResponse = [
|
||||||
is_active: true,
|
is_active: true,
|
||||||
module_slugs: ['acupuncture-points'],
|
module_slugs: ['acupuncture-points'],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
code: 'POINTS_PACK',
|
|
||||||
name: 'Points Complete Pack (1 Yr)',
|
|
||||||
plan_type: 'bundle',
|
|
||||||
billing_period: 'yearly',
|
|
||||||
price_inr: 900,
|
|
||||||
price_usd: 15,
|
|
||||||
price_eur: 15,
|
|
||||||
is_active: true,
|
|
||||||
module_slugs: ['acupuncture-points', 'scalp-acupuncture', 'ear-acupuncture'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'THERAPEUTICS_CORE',
|
|
||||||
name: 'Therapeutics Complete Bundle (1 Yr)',
|
|
||||||
plan_type: 'bundle',
|
|
||||||
billing_period: 'yearly',
|
|
||||||
price_inr: 0,
|
|
||||||
price_usd: 30,
|
|
||||||
price_eur: 30,
|
|
||||||
is_active: true,
|
|
||||||
module_slugs: ['auriculotherapy', 'gynecological-disorders'],
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
function setupAxiosMocks(userOverrides: Record<string, any> = {}) {
|
function setupAxiosMocks(userOverrides: Record<string, any> = {}) {
|
||||||
|
|
@ -460,43 +438,4 @@ describe('App Integration', () => {
|
||||||
const closeDrawerBtn = document.querySelector('button svg.lucide-x-circle')?.closest('button') as HTMLButtonElement;
|
const closeDrawerBtn = document.querySelector('button svg.lucide-x-circle')?.closest('button') as HTMLButtonElement;
|
||||||
if (closeDrawerBtn) await user.click(closeDrawerBtn);
|
if (closeDrawerBtn) await user.click(closeDrawerBtn);
|
||||||
}, 15000);
|
}, 15000);
|
||||||
|
|
||||||
it('hides plans absent from /api/plans (POINTS_TUNG) or unpriced in billing currency (THERAPEUTICS_CORE) and prunes them from cart', async () => {
|
|
||||||
window.history.pushState({}, '', '/store/?planCode=POINTS_TUNG');
|
|
||||||
|
|
||||||
render(<App />);
|
|
||||||
|
|
||||||
// Wait for /api/plans to load and prune POINTS_TUNG from deep-linked cart & hide both unavailable plans
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(screen.getByText('Acu (EOV+Cat+Ext+MR)')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('0 Items')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(screen.queryByText('Master Tung')).not.toBeInTheDocument();
|
|
||||||
expect(screen.queryByText('₹0')).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('keeps storefront visible and clears stale token silently when initial profile fetch fails', async () => {
|
|
||||||
localStorage.setItem('access_token', 'stale-expired-jwt');
|
|
||||||
window.history.pushState({}, '', '/store/');
|
|
||||||
mockedAxios.get.mockImplementation((url: string) => {
|
|
||||||
if (url.includes('/api/auth/profile')) {
|
|
||||||
return Promise.reject({ response: { status: 401, data: { detail: 'Token expired' } } });
|
|
||||||
}
|
|
||||||
if (url.includes('/api/checkout/config')) return Promise.resolve({ data: { razorpay_key_id: 'rzp_test_123' } });
|
|
||||||
if (url.includes('/api/plans')) return Promise.resolve({ data: mockPlansResponse });
|
|
||||||
if (url.includes('/api/modules/categories')) return Promise.resolve({ data: [] });
|
|
||||||
return Promise.resolve({ data: {} });
|
|
||||||
});
|
|
||||||
|
|
||||||
render(<App />);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(screen.getByText('Unlock Professional TCM Modules')).toBeInTheDocument();
|
|
||||||
expect(localStorage.getItem('access_token')).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(screen.queryByText('Successfully Logged Out')).not.toBeInTheDocument();
|
|
||||||
expect(window.location.pathname).toBe('/store/');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,144 +0,0 @@
|
||||||
import { describe, it, expect } from 'vitest';
|
|
||||||
import { buildDynamicCatalog, resolvePlanCategory } from '../../src/utils/catalog';
|
|
||||||
import { CURRICULUM_MODULES } from '../../src/constants/modules';
|
|
||||||
import type { PublicPlan } from '../../src/types';
|
|
||||||
|
|
||||||
describe('buildDynamicCatalog', () => {
|
|
||||||
it('falls back to CURRICULUM_MODULES when publicPlans is empty', () => {
|
|
||||||
const result = buildDynamicCatalog([]);
|
|
||||||
expect(result).toEqual(CURRICULUM_MODULES);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('maps newly created Module Builder one_time plan to its normalized category with sortOrder', () => {
|
|
||||||
const plans: PublicPlan[] = [
|
|
||||||
{
|
|
||||||
code: 'MOD_M0044',
|
|
||||||
base_code: 'MOD_M0044',
|
|
||||||
name: 'Pediatric Disorders',
|
|
||||||
description: 'TCM pediatric treatment protocols.',
|
|
||||||
plan_type: 'one_time',
|
|
||||||
price_inr: 600,
|
|
||||||
price_usd: 15,
|
|
||||||
price_eur: 15,
|
|
||||||
is_active: true,
|
|
||||||
modules: [
|
|
||||||
{
|
|
||||||
id: 'mod-44',
|
|
||||||
code: 'm0044',
|
|
||||||
slug: 'pediatric-disorders',
|
|
||||||
name: 'Pediatric Disorders',
|
|
||||||
description: 'TCM pediatric treatment protocols.',
|
|
||||||
category: 'Therapeutics',
|
|
||||||
sort_order: 40,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const result = buildDynamicCatalog(plans);
|
|
||||||
expect(result).toHaveLength(1);
|
|
||||||
expect(result[0]).toMatchObject({
|
|
||||||
code: 'MOD_M0044',
|
|
||||||
name: 'Pediatric Disorders',
|
|
||||||
category: 'Therapeutics',
|
|
||||||
priceInr: 600,
|
|
||||||
priceUsd: 15,
|
|
||||||
priceEur: 15,
|
|
||||||
sortOrder: 40,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('expands PATTERN_CORE sub-modules from plan.modules and appends Complete Pack', () => {
|
|
||||||
const plans: PublicPlan[] = [
|
|
||||||
{
|
|
||||||
code: 'PATTERN_CORE',
|
|
||||||
name: 'Pattern: Complete Pack',
|
|
||||||
description: 'All pattern methodologies.',
|
|
||||||
plan_type: 'bundle',
|
|
||||||
price_inr: 500,
|
|
||||||
price_usd: 10,
|
|
||||||
price_eur: 10,
|
|
||||||
is_active: true,
|
|
||||||
modules: [
|
|
||||||
{ name: 'Zang-Fu Organs', slug: 'zang-fu', category: 'Pattern', sort_order: 2 },
|
|
||||||
{ name: 'Eight Principles', slug: 'eight-principles', category: 'Pattern', sort_order: 1 },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const result = buildDynamicCatalog(plans);
|
|
||||||
expect(result.map((m) => m.name)).toEqual([
|
|
||||||
'Eight Principles',
|
|
||||||
'Zang-Fu Organs',
|
|
||||||
'Pattern: Complete Pack',
|
|
||||||
]);
|
|
||||||
expect(result[2].sortOrder).toBe(Number.MAX_SAFE_INTEGER);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('omits Complete Pack row for NUTRITION_CORE when only 1 module exists and keeps POINTS_PACK last', () => {
|
|
||||||
const plans: PublicPlan[] = [
|
|
||||||
{
|
|
||||||
code: 'NUTRITION_CORE',
|
|
||||||
name: 'Nutrition Module Access (1 Yr)',
|
|
||||||
plan_type: 'one_time',
|
|
||||||
price_inr: 600,
|
|
||||||
price_usd: 15,
|
|
||||||
price_eur: 15,
|
|
||||||
is_active: true,
|
|
||||||
modules: [{ code: 'm0031', name: 'Nutrition', slug: 'nutrition', category: 'Nutrition', sort_order: 99999 }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'POINTS_PACK',
|
|
||||||
name: 'Points Complete Pack (1 Yr)',
|
|
||||||
plan_type: 'bundle',
|
|
||||||
price_inr: 900,
|
|
||||||
price_usd: 15,
|
|
||||||
price_eur: 15,
|
|
||||||
is_active: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: 'POINTS_ACU',
|
|
||||||
name: 'Acu Points Module (1 Yr)',
|
|
||||||
plan_type: 'one_time',
|
|
||||||
price_inr: 300,
|
|
||||||
price_usd: 5,
|
|
||||||
price_eur: 5,
|
|
||||||
is_active: true,
|
|
||||||
modules: [{ code: 'm0001', name: 'Acupuncture Points', slug: 'acupuncture-points', category: 'Points', sort_order: 99999 }],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const result = buildDynamicCatalog(plans);
|
|
||||||
const nutritionItems = result.filter((m) => m.category === 'Nutrition');
|
|
||||||
expect(nutritionItems).toHaveLength(1);
|
|
||||||
expect(nutritionItems[0].name).toBe('Nutrition');
|
|
||||||
|
|
||||||
const pointsItems = result
|
|
||||||
.filter((m) => m.category === 'Points')
|
|
||||||
.sort((a, b) => (a.sortOrder ?? 500) - (b.sortOrder ?? 500));
|
|
||||||
expect(pointsItems.map((m) => m.code)).toEqual(['POINTS_ACU', 'POINTS_PACK']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('resolves non-standard category or custom bundle cleanly', () => {
|
|
||||||
const unknownCatPlan: PublicPlan = {
|
|
||||||
code: 'MOD_HERB',
|
|
||||||
name: 'Herbal Formulas',
|
|
||||||
plan_type: 'one_time',
|
|
||||||
is_active: true,
|
|
||||||
modules: [{ name: 'Herbal Formulas', category: 'Herbalism', sort_order: 50 }],
|
|
||||||
};
|
|
||||||
expect(resolvePlanCategory(unknownCatPlan)).toBe('Herbalism');
|
|
||||||
|
|
||||||
const bundlePlan: PublicPlan = {
|
|
||||||
code: 'STARTER_BUNDLE',
|
|
||||||
name: 'Starter Bundle',
|
|
||||||
plan_type: 'bundle',
|
|
||||||
price_inr: 1200,
|
|
||||||
price_usd: 25,
|
|
||||||
price_eur: 25,
|
|
||||||
is_active: true,
|
|
||||||
};
|
|
||||||
const result = buildDynamicCatalog([bundlePlan]);
|
|
||||||
expect(result[0].category).toBe('Bundle');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Loading…
Reference in New Issue