From 5b65523417503b767102dfa24a4fc7201dfec71b Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Sat, 10 Oct 2026 09:07:22 +0530 Subject: [PATCH] Issue 14: dynamically resolv clinical categories in admin dashboard --- src/App.tsx | 47 +++++++++++++++++++++++++-- src/components/modules/ModulesTab.tsx | 3 +- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index ce2efc2..2aebded 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -217,7 +217,7 @@ export default function App() { setAdminDataLoading(true); const headers = { Authorization: `Bearer ${userToken}` }; try { - const [payRes, adminsRes, practRes, subLedgerRes, modulesRes, plansRes, couponsRes, dbRes] = + const [payRes, adminsRes, practRes, subLedgerRes, modulesRes, plansRes, couponsRes, dbRes, contentModsRes] = await Promise.allSettled([ axios.get(`${API_BASE}/api/admin/razorpay/payments`, { headers }), axios.get(`${API_BASE}/api/admin/super-admins`, { headers }), @@ -227,13 +227,56 @@ export default function App() { axios.get(`${API_BASE}/api/admin/plans`, { headers }), axios.get(`${API_BASE}/api/admin/coupons`, { headers }), axios.get(`${API_BASE}/api/admin/database/info`, { headers }), + axios.get(`${API_BASE}/api/contents/modules`), ]); if (payRes.status === 'fulfilled') setRzpPayments(payRes.value.data.payments || []); if (adminsRes.status === 'fulfilled') setAdminsList(adminsRes.value.data || []); if (practRes.status === 'fulfilled') setPractitionersList(practRes.value.data || []); if (subLedgerRes.status === 'fulfilled') setUsersSubscriptions(subLedgerRes.value.data || []); - if (modulesRes.status === 'fulfilled') setAdminModulesList(modulesRes.value.data || []); + if (modulesRes.status === 'fulfilled') { + const rawModules: any[] = modulesRes.value.data || []; + const contentModules: any[] = + contentModsRes.status === 'fulfilled' ? contentModsRes.value.data?.modules || [] : []; + + // Generic clinical kind to category mapping + const kindToCategory: Record = { + point: 'point', + points: 'point', + pattern: 'Patterns', + patterns: 'Patterns', + 'five-elements': 'Patterns', + nutrition: 'Nutrition', + therapeutic: 'Therapeutics', + therapeutics: 'Therapeutics', + }; + + const resolvedModules = rawModules.map((m: any) => { + const matched = contentModules.find( + (c: any) => + (c.id && m.id && c.id === m.id) || + (c.slug && m.slug && c.slug.toLowerCase() === m.slug.toLowerCase()) || + (c.code && m.code && c.code.toLowerCase() === m.code.toLowerCase()) + ); + + const explicitCategory = matched?.metadata?.category; + const kind = (matched?.metadata?.kind || '').toLowerCase(); + const kindCategory = kindToCategory[kind]; + + const resolvedCategory = + explicitCategory || + kindCategory || + (m.category && m.category.toLowerCase() !== 'general' ? m.category : null) || + 'General'; + + return { + ...m, + category: resolvedCategory, + }; + }); + + setAdminModulesList(resolvedModules); + } if (plansRes.status === 'fulfilled') setAdminPlansList(plansRes.value.data || []); if (couponsRes.status === 'fulfilled') setAdminCouponsList(couponsRes.value.data || []); if (dbRes.status === 'fulfilled') setDbInfo(dbRes.value.data || null); diff --git a/src/components/modules/ModulesTab.tsx b/src/components/modules/ModulesTab.tsx index 25680a5..02cda01 100644 --- a/src/components/modules/ModulesTab.tsx +++ b/src/components/modules/ModulesTab.tsx @@ -208,10 +208,11 @@ export const ModulesTab: React.FC = ({ {/* Column 3: Category */} - {mod.category || 'General'} + {mod.category === 'point' ? 'Points' : mod.category || 'General'} + {/* Column 4: Linked Plans */} -- 2.34.1