Compare commits
No commits in common. "e801ec1aee2b3a6192897753a31553878983706c" and "feb878d314c18b8a91d80c7cdb512acf7f66da16" have entirely different histories.
e801ec1aee
...
feb878d314
17
src/App.tsx
17
src/App.tsx
|
|
@ -3,7 +3,6 @@ import axios from 'axios';
|
||||||
import { Database, RefreshCw, RefreshCcw, Menu, Sparkles } from 'lucide-react';
|
import { Database, RefreshCw, RefreshCcw, Menu, Sparkles } from 'lucide-react';
|
||||||
import { API_BASE } from './services/api';
|
import { API_BASE } from './services/api';
|
||||||
import type { AdminTabType } from './types';
|
import type { AdminTabType } from './types';
|
||||||
import { normalizeCategory } from './utils/category';
|
|
||||||
|
|
||||||
// Modular Components
|
// Modular Components
|
||||||
import { AdminSidebar } from './components/layout/AdminSidebar';
|
import { AdminSidebar } from './components/layout/AdminSidebar';
|
||||||
|
|
@ -261,14 +260,7 @@ export default function App() {
|
||||||
if (adminsRes.status === 'fulfilled') setAdminsList(adminsRes.value.data || []);
|
if (adminsRes.status === 'fulfilled') setAdminsList(adminsRes.value.data || []);
|
||||||
if (practRes.status === 'fulfilled') setPractitionersList(practRes.value.data || []);
|
if (practRes.status === 'fulfilled') setPractitionersList(practRes.value.data || []);
|
||||||
if (subLedgerRes.status === 'fulfilled') setUsersSubscriptions(subLedgerRes.value.data || []);
|
if (subLedgerRes.status === 'fulfilled') setUsersSubscriptions(subLedgerRes.value.data || []);
|
||||||
if (modulesRes.status === 'fulfilled') {
|
if (modulesRes.status === 'fulfilled') setAdminModulesList(modulesRes.value.data || []);
|
||||||
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 (plansRes.status === 'fulfilled') setAdminPlansList(plansRes.value.data || []);
|
||||||
if (couponsRes.status === 'fulfilled') setAdminCouponsList(couponsRes.value.data || []);
|
if (couponsRes.status === 'fulfilled') setAdminCouponsList(couponsRes.value.data || []);
|
||||||
if (dbRes.status === 'fulfilled') setDbInfo(dbRes.value.data || null);
|
if (dbRes.status === 'fulfilled') setDbInfo(dbRes.value.data || null);
|
||||||
|
|
@ -532,28 +524,27 @@ export default function App() {
|
||||||
setSelectedEditModule(mod);
|
setSelectedEditModule(mod);
|
||||||
setEditModuleName(mod.name || '');
|
setEditModuleName(mod.name || '');
|
||||||
setEditModuleDesc(mod.description || '');
|
setEditModuleDesc(mod.description || '');
|
||||||
setEditModuleCategory(normalizeCategory(mod.category));
|
setEditModuleCategory(mod.category || 'point');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveModuleDetails = async (e: React.FormEvent) => {
|
const handleSaveModuleDetails = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!selectedEditModule || !userToken) return;
|
if (!selectedEditModule || !userToken) return;
|
||||||
setEditModuleSaving(true);
|
setEditModuleSaving(true);
|
||||||
const normalizedCat = normalizeCategory(editModuleCategory);
|
|
||||||
try {
|
try {
|
||||||
await axios.put(
|
await axios.put(
|
||||||
`${API_BASE}/api/admin/modules/${selectedEditModule.id}`,
|
`${API_BASE}/api/admin/modules/${selectedEditModule.id}`,
|
||||||
{
|
{
|
||||||
name: editModuleName,
|
name: editModuleName,
|
||||||
description: editModuleDesc,
|
description: editModuleDesc,
|
||||||
category: normalizedCat,
|
category: editModuleCategory,
|
||||||
},
|
},
|
||||||
{ headers: { Authorization: `Bearer ${userToken}` } }
|
{ headers: { Authorization: `Bearer ${userToken}` } }
|
||||||
);
|
);
|
||||||
setAdminModulesList((prev) =>
|
setAdminModulesList((prev) =>
|
||||||
prev.map((m) =>
|
prev.map((m) =>
|
||||||
m.id === selectedEditModule.id
|
m.id === selectedEditModule.id
|
||||||
? { ...m, name: editModuleName, description: editModuleDesc, category: normalizedCat }
|
? { ...m, name: editModuleName, description: editModuleDesc, category: editModuleCategory }
|
||||||
: m
|
: m
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { XCircle, RefreshCw } from 'lucide-react';
|
import { XCircle, RefreshCw } from 'lucide-react';
|
||||||
import type { ModuleItem } from '../../types';
|
import type { ModuleItem } from '../../types';
|
||||||
import { normalizeCategory } from '../../utils/category';
|
|
||||||
|
|
||||||
interface EditModuleModalProps {
|
interface EditModuleModalProps {
|
||||||
module: ModuleItem | null;
|
module: ModuleItem | null;
|
||||||
|
|
@ -70,11 +69,11 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Category</label>
|
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Category</label>
|
||||||
<select
|
<select
|
||||||
value={normalizeCategory(category)}
|
value={category}
|
||||||
onChange={(e) => onCategoryChange(e.target.value)}
|
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"
|
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="Patterns">Patterns</option>
|
||||||
<option value="Nutrition">Nutrition</option>
|
<option value="Nutrition">Nutrition</option>
|
||||||
<option value="Therapeutics">Therapeutics</option>
|
<option value="Therapeutics">Therapeutics</option>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import React from 'react';
|
||||||
import { Edit } from 'lucide-react';
|
import { Edit } from 'lucide-react';
|
||||||
import type { ModuleItem } from '../../types';
|
import type { ModuleItem } from '../../types';
|
||||||
import { Pagination } from '../common/Pagination';
|
import { Pagination } from '../common/Pagination';
|
||||||
import { normalizeCategory, CLINICAL_CATEGORIES } from '../../utils/category';
|
|
||||||
|
|
||||||
interface ModulesTabProps {
|
interface ModulesTabProps {
|
||||||
modules: ModuleItem[];
|
modules: ModuleItem[];
|
||||||
|
|
@ -50,7 +49,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
||||||
|
|
||||||
const matchesCategory =
|
const matchesCategory =
|
||||||
categoryFilter === 'all' ||
|
categoryFilter === 'all' ||
|
||||||
normalizeCategory(m.category).toLowerCase() === categoryFilter.toLowerCase();
|
(m.category || '').toLowerCase() === categoryFilter.toLowerCase();
|
||||||
|
|
||||||
return matchesSearch && matchesStatus && matchesCategory;
|
return matchesSearch && matchesStatus && matchesCategory;
|
||||||
});
|
});
|
||||||
|
|
@ -61,7 +60,13 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
||||||
const startIndex = (safePage - 1) * perPage;
|
const startIndex = (safePage - 1) * perPage;
|
||||||
const paginatedModules = filtered.slice(startIndex, startIndex + 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 (
|
return (
|
||||||
<div className="space-y-5">
|
<div className="space-y-5">
|
||||||
|
|
@ -119,7 +124,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
||||||
const count =
|
const count =
|
||||||
cat.key === 'all'
|
cat.key === 'all'
|
||||||
? modules.length
|
? 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();
|
const isSelected = categoryFilter.toLowerCase() === cat.key.toLowerCase();
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
|
|
@ -203,7 +208,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
||||||
{/* Column 3: Category */}
|
{/* Column 3: Category */}
|
||||||
<td className="py-3.5 px-3.5">
|
<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">
|
<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>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { AlertCircle, RefreshCw } from 'lucide-react';
|
import { AlertCircle, RefreshCw } from 'lucide-react';
|
||||||
import { normalizeCategory } from '../../utils/category';
|
|
||||||
|
|
||||||
interface CreatePlanModalProps {
|
interface CreatePlanModalProps {
|
||||||
show: boolean;
|
show: boolean;
|
||||||
|
|
@ -273,7 +272,7 @@ export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
||||||
/>
|
/>
|
||||||
<div className="truncate flex-1">
|
<div className="truncate flex-1">
|
||||||
<p className="truncate text-xs">{mod.name}</p>
|
<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>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -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' },
|
|
||||||
];
|
|
||||||
Loading…
Reference in New Issue