fix(modules): dynamically and generically resolve clinical module categories
This commit is contained in:
parent
feb878d314
commit
f537ab3ae3
17
src/App.tsx
17
src/App.tsx
|
|
@ -3,6 +3,7 @@ import axios from 'axios';
|
|||
import { Database, RefreshCw, RefreshCcw, Menu, Sparkles } from 'lucide-react';
|
||||
import { API_BASE } from './services/api';
|
||||
import type { AdminTabType } from './types';
|
||||
import { normalizeCategory } from './utils/category';
|
||||
|
||||
// Modular Components
|
||||
import { AdminSidebar } from './components/layout/AdminSidebar';
|
||||
|
|
@ -260,7 +261,14 @@ export default function App() {
|
|||
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 rawMods: any[] = modulesRes.value.data || [];
|
||||
const resolved = rawMods.map((m: any) => ({
|
||||
...m,
|
||||
category: normalizeCategory(m.category || m.metadata?.category || m.metadata?.kind || m.kind),
|
||||
}));
|
||||
setAdminModulesList(resolved);
|
||||
}
|
||||
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);
|
||||
|
|
@ -524,27 +532,28 @@ export default function App() {
|
|||
setSelectedEditModule(mod);
|
||||
setEditModuleName(mod.name || '');
|
||||
setEditModuleDesc(mod.description || '');
|
||||
setEditModuleCategory(mod.category || 'point');
|
||||
setEditModuleCategory(normalizeCategory(mod.category));
|
||||
};
|
||||
|
||||
const handleSaveModuleDetails = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!selectedEditModule || !userToken) return;
|
||||
setEditModuleSaving(true);
|
||||
const normalizedCat = normalizeCategory(editModuleCategory);
|
||||
try {
|
||||
await axios.put(
|
||||
`${API_BASE}/api/admin/modules/${selectedEditModule.id}`,
|
||||
{
|
||||
name: editModuleName,
|
||||
description: editModuleDesc,
|
||||
category: editModuleCategory,
|
||||
category: normalizedCat,
|
||||
},
|
||||
{ headers: { Authorization: `Bearer ${userToken}` } }
|
||||
);
|
||||
setAdminModulesList((prev) =>
|
||||
prev.map((m) =>
|
||||
m.id === selectedEditModule.id
|
||||
? { ...m, name: editModuleName, description: editModuleDesc, category: editModuleCategory }
|
||||
? { ...m, name: editModuleName, description: editModuleDesc, category: normalizedCat }
|
||||
: m
|
||||
)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import React from 'react';
|
||||
import { XCircle, RefreshCw } from 'lucide-react';
|
||||
import type { ModuleItem } from '../../types';
|
||||
import { normalizeCategory } from '../../utils/category';
|
||||
|
||||
interface EditModuleModalProps {
|
||||
module: ModuleItem | null;
|
||||
|
|
@ -69,11 +70,11 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
|||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Category</label>
|
||||
<select
|
||||
value={category}
|
||||
value={normalizeCategory(category)}
|
||||
onChange={(e) => onCategoryChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
||||
>
|
||||
<option value="point">Points</option>
|
||||
<option value="Points">Points</option>
|
||||
<option value="Patterns">Patterns</option>
|
||||
<option value="Nutrition">Nutrition</option>
|
||||
<option value="Therapeutics">Therapeutics</option>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||
import { Edit } from 'lucide-react';
|
||||
import type { ModuleItem } from '../../types';
|
||||
import { Pagination } from '../common/Pagination';
|
||||
import { normalizeCategory, CLINICAL_CATEGORIES } from '../../utils/category';
|
||||
|
||||
interface ModulesTabProps {
|
||||
modules: ModuleItem[];
|
||||
|
|
@ -49,7 +50,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
|||
|
||||
const matchesCategory =
|
||||
categoryFilter === 'all' ||
|
||||
(m.category || '').toLowerCase() === categoryFilter.toLowerCase();
|
||||
normalizeCategory(m.category).toLowerCase() === categoryFilter.toLowerCase();
|
||||
|
||||
return matchesSearch && matchesStatus && matchesCategory;
|
||||
});
|
||||
|
|
@ -60,13 +61,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
|||
const startIndex = (safePage - 1) * perPage;
|
||||
const paginatedModules = filtered.slice(startIndex, startIndex + perPage);
|
||||
|
||||
const categories = [
|
||||
{ key: 'all', label: 'All Categories' },
|
||||
{ key: 'point', label: 'Points' },
|
||||
{ key: 'Patterns', label: 'Patterns' },
|
||||
{ key: 'Nutrition', label: 'Nutrition' },
|
||||
{ key: 'Therapeutics', label: 'Therapeutics' },
|
||||
];
|
||||
const categories = CLINICAL_CATEGORIES;
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
|
|
@ -124,7 +119,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
|||
const count =
|
||||
cat.key === 'all'
|
||||
? modules.length
|
||||
: modules.filter((m) => (m.category || '').toLowerCase() === cat.key.toLowerCase()).length;
|
||||
: modules.filter((m) => normalizeCategory(m.category).toLowerCase() === cat.key.toLowerCase()).length;
|
||||
const isSelected = categoryFilter.toLowerCase() === cat.key.toLowerCase();
|
||||
return (
|
||||
<button
|
||||
|
|
@ -208,7 +203,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
|||
{/* Column 3: Category */}
|
||||
<td className="py-3.5 px-3.5">
|
||||
<span className="text-[10px] font-bold text-indigo-600 bg-indigo-50 px-2.5 py-1 rounded-lg border border-indigo-100 uppercase tracking-wider">
|
||||
{mod.category || 'General'}
|
||||
{normalizeCategory(mod.category)}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import React from 'react';
|
||||
import { AlertCircle, RefreshCw } from 'lucide-react';
|
||||
import { normalizeCategory } from '../../utils/category';
|
||||
|
||||
interface CreatePlanModalProps {
|
||||
show: boolean;
|
||||
|
|
@ -272,7 +273,7 @@ export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
|||
/>
|
||||
<div className="truncate flex-1">
|
||||
<p className="truncate text-xs">{mod.name}</p>
|
||||
<span className="text-[9px] text-slate-400 font-semibold">{mod.category || 'General'}</span>
|
||||
<span className="text-[9px] text-slate-400 font-semibold">{normalizeCategory(mod.category)}</span>
|
||||
</div>
|
||||
</label>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* Generic clinical category resolver and normalizer.
|
||||
* Maps raw categories or content kinds into standardized display categories.
|
||||
*/
|
||||
export function normalizeCategory(categoryOrKind?: string | null): string {
|
||||
if (!categoryOrKind) return 'General';
|
||||
const val = categoryOrKind.trim();
|
||||
const lower = val.toLowerCase();
|
||||
if (lower === 'point' || lower === 'points') return 'Points';
|
||||
if (lower === 'pattern' || lower === 'patterns' || lower === 'five-elements') return 'Patterns';
|
||||
if (lower === 'nutrition') return 'Nutrition';
|
||||
if (lower === 'therapeutic' || lower === 'therapeutics') return 'Therapeutics';
|
||||
if (lower === 'general') return 'General';
|
||||
return val;
|
||||
}
|
||||
|
||||
export const CLINICAL_CATEGORIES = [
|
||||
{ key: 'all', label: 'All Categories' },
|
||||
{ key: 'Points', label: 'Points' },
|
||||
{ key: 'Patterns', label: 'Patterns' },
|
||||
{ key: 'Nutrition', label: 'Nutrition' },
|
||||
{ key: 'Therapeutics', label: 'Therapeutics' },
|
||||
];
|
||||
Loading…
Reference in New Issue