From 870b3062d6a8c0165ae4cf025144bc3f2f6d20f3 Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Fri, 9 Oct 2026 16:37:07 +0530 Subject: [PATCH] fix: dynamically reflect updated module categories on storefront --- src/App.tsx | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index ad2c620..c812df5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -146,6 +146,67 @@ export default function App() { } }; + // Dynamic Curriculum Modules with Live Categories + const [curriculumModules, setCurriculumModules] = useState(CURRICULUM_MODULES); + + const fetchModuleCategories = async () => { + try { + const res = await axios.get(`${API_BASE}/api/contents/modules`); + const apiModules: any[] = res.data?.modules || []; + if (apiModules.length > 0) { + const normalizeCategory = (cat?: string) => { + if (!cat) return null; + const c = cat.toLowerCase(); + if (c === 'point' || c === 'points') return 'Points'; + if (c === 'pattern' || c === 'patterns') return 'Pattern'; + if (c === 'nutrition') return 'Nutrition'; + if (c === 'therapeutics' || c === 'therapeutic') return 'Therapeutics'; + return cat; + }; + + setCurriculumModules((prev) => + prev.map((item) => { + const matched = apiModules.find((m) => { + const mCode = (m.code || '').toLowerCase(); + const iCode = (item.code || '').toLowerCase(); + if (mCode && iCode && mCode === iCode) return true; + const slug = (m.slug || '').toLowerCase(); + const mName = (m.name || '').toLowerCase(); + const iName = item.name.toLowerCase(); + + const cleanI = iName.replace('points:', '').replace('therapeutics:', '').split('(')[0].trim(); + const cleanM = mName.replace('points:', '').replace('therapeutics:', '').split('(')[0].trim(); + + if (cleanI.includes('acu') && cleanM.includes('acupuncture') && !cleanI.includes('scalp') && !cleanI.includes('ear')) return true; + if (cleanI.includes('scalp') && cleanM.includes('scalp')) return true; + if (cleanI.includes('ear') && (cleanM.includes('ear') || slug.includes('auriculo'))) return true; + if (cleanI.includes('gyneco') && slug.includes('gyneco')) return true; + if (cleanI.includes('eight') && slug.includes('eight')) return true; + if (cleanI.includes('zang') && slug.includes('tcm-pattern')) return true; + if (cleanI.includes('qi') && slug.includes('qi')) return true; + if (cleanI.includes('pathogenic') && slug.includes('pathogenic')) return true; + if (cleanI.includes('six') && slug.includes('six')) return true; + if (cleanI.includes('four') && slug.includes('four')) return true; + if (cleanI.includes('three') && slug.includes('three')) return true; + if (cleanI.includes('five') && slug.includes('five')) return true; + if (cleanI.includes('food') && slug.includes('nutrition')) return true; + return false; + }); + + const updatedCat = normalizeCategory(matched?.metadata?.category || matched?.category); + if (updatedCat) { + return { ...item, category: updatedCat }; + } + return item; + }) + ); + } + } catch (err) { + console.error('Failed to load module categories:', err); + } + }; + + const getLivePlan = (code: string) => { return publicPlans.find(p => p.code === code || p.base_code === code); }; @@ -193,7 +254,7 @@ export default function App() { } if (urlPlanCode) { - const targetModule = CURRICULUM_MODULES.find(m => m.code === urlPlanCode); + const targetModule = curriculumModules.find(m => m.code === urlPlanCode); if (targetModule) { setCart([targetModule]); setShowLockedByCategory(prev => ({ @@ -218,6 +279,7 @@ export default function App() { }); fetchPublicPlans(); + fetchModuleCategories(); if (activeToken && !urlToken) { fetchUserProfile(activeToken); @@ -945,7 +1007,7 @@ export default function App() {
{/* 📦 Catalog Section */} )} @@ -1093,7 +1155,7 @@ export default function App() { setShowProfileDrawer(false); switchTab('storefront'); }} - curriculumModules={CURRICULUM_MODULES} + curriculumModules={curriculumModules} /> {/* 🔐 Password Updated Success Modal */} -- 2.34.1