Issue 8 (web): dynamically reflect updated module categories on storefront #46

Merged
amit merged 1 commits from fix-module-category-reflection into main 2026-10-10 11:08:54 +00:00
1 changed files with 66 additions and 4 deletions

View File

@ -146,6 +146,67 @@ export default function App() {
}
};
// Dynamic Curriculum Modules with Live Categories
const [curriculumModules, setCurriculumModules] = useState<ModuleItem[]>(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() {
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6 xl:gap-8">
{/* 📦 Catalog Section */}
<CatalogSection
curriculumModules={CURRICULUM_MODULES}
curriculumModules={curriculumModules}
publicPlans={publicPlans}
cart={cart}
currency={currency}
@ -1003,7 +1065,7 @@ export default function App() {
setShowAuthModal(true);
}}
onSwitchTab={switchTab}
curriculumModules={CURRICULUM_MODULES}
curriculumModules={curriculumModules}
/>
)}
@ -1093,7 +1155,7 @@ export default function App() {
setShowProfileDrawer(false);
switchTab('storefront');
}}
curriculumModules={CURRICULUM_MODULES}
curriculumModules={curriculumModules}
/>
{/* 🔐 Password Updated Success Modal */}