Compare commits

..

No commits in common. "e801ec1aee2b3a6192897753a31553878983706c" and "feb878d314c18b8a91d80c7cdb512acf7f66da16" have entirely different histories.

5 changed files with 17 additions and 46 deletions

View File

@ -3,7 +3,6 @@ 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';
@ -261,14 +260,7 @@ 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') {
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 (modulesRes.status === 'fulfilled') setAdminModulesList(modulesRes.value.data || []);
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);
@ -532,28 +524,27 @@ export default function App() {
setSelectedEditModule(mod);
setEditModuleName(mod.name || '');
setEditModuleDesc(mod.description || '');
setEditModuleCategory(normalizeCategory(mod.category));
setEditModuleCategory(mod.category || 'point');
};
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: normalizedCat,
category: editModuleCategory,
},
{ headers: { Authorization: `Bearer ${userToken}` } }
);
setAdminModulesList((prev) =>
prev.map((m) =>
m.id === selectedEditModule.id
? { ...m, name: editModuleName, description: editModuleDesc, category: normalizedCat }
? { ...m, name: editModuleName, description: editModuleDesc, category: editModuleCategory }
: m
)
);

View File

@ -1,7 +1,6 @@
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;
@ -70,11 +69,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={normalizeCategory(category)}
value={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="Points">Points</option>
<option value="point">Points</option>
<option value="Patterns">Patterns</option>
<option value="Nutrition">Nutrition</option>
<option value="Therapeutics">Therapeutics</option>

View File

@ -2,7 +2,6 @@ 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[];
@ -50,7 +49,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
const matchesCategory =
categoryFilter === 'all' ||
normalizeCategory(m.category).toLowerCase() === categoryFilter.toLowerCase();
(m.category || '').toLowerCase() === categoryFilter.toLowerCase();
return matchesSearch && matchesStatus && matchesCategory;
});
@ -61,7 +60,13 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
const startIndex = (safePage - 1) * perPage;
const paginatedModules = filtered.slice(startIndex, startIndex + perPage);
const categories = CLINICAL_CATEGORIES;
const categories = [
{ key: 'all', label: 'All Categories' },
{ key: 'point', label: 'Points' },
{ key: 'Patterns', label: 'Patterns' },
{ key: 'Nutrition', label: 'Nutrition' },
{ key: 'Therapeutics', label: 'Therapeutics' },
];
return (
<div className="space-y-5">
@ -119,7 +124,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
const count =
cat.key === 'all'
? modules.length
: modules.filter((m) => normalizeCategory(m.category).toLowerCase() === cat.key.toLowerCase()).length;
: modules.filter((m) => (m.category || '').toLowerCase() === cat.key.toLowerCase()).length;
const isSelected = categoryFilter.toLowerCase() === cat.key.toLowerCase();
return (
<button
@ -203,7 +208,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">
{normalizeCategory(mod.category)}
{mod.category || 'General'}
</span>
</td>

View File

@ -1,6 +1,5 @@
import React from 'react';
import { AlertCircle, RefreshCw } from 'lucide-react';
import { normalizeCategory } from '../../utils/category';
interface CreatePlanModalProps {
show: boolean;
@ -273,7 +272,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">{normalizeCategory(mod.category)}</span>
<span className="text-[9px] text-slate-400 font-semibold">{mod.category || 'General'}</span>
</div>
</label>
);

View File

@ -1,23 +0,0 @@
/**
* 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' },
];