feat/admin-module-builder #34
|
|
@ -9,6 +9,7 @@ import { AdminSidebar } from './components/layout/AdminSidebar';
|
|||
import { SyncOverview } from './components/sync/SyncOverview';
|
||||
import { ModulesTab } from './components/modules/ModulesTab';
|
||||
import { EditModuleModal } from './components/modules/EditModuleModal';
|
||||
import { ModuleBuilderTab } from './components/modules/ModuleBuilderTab';
|
||||
import { PlansTab } from './components/plans/PlansTab';
|
||||
import { CreatePlanModal } from './components/plans/CreatePlanModal';
|
||||
import { EditPriceModal } from './components/plans/EditPriceModal';
|
||||
|
|
@ -1019,6 +1020,7 @@ export default function App() {
|
|||
<h2 className="text-xl sm:text-2xl font-black text-slate-900 tracking-tight">
|
||||
{adminSubTab === 'overview' && 'System Overview & Audit Logs'}
|
||||
{adminSubTab === 'modules' && 'Curriculum Modules'}
|
||||
{adminSubTab === 'module_builder' && 'Clinical Module Builder'}
|
||||
{adminSubTab === 'plans' && 'Subscription Plans & Pricing'}
|
||||
{adminSubTab === 'coupons' && 'Promotions & Coupons'}
|
||||
{adminSubTab === 'customers' && 'Customer Directory'}
|
||||
|
|
@ -1031,6 +1033,7 @@ export default function App() {
|
|||
<p className="text-slate-500 text-xs font-semibold">
|
||||
{adminSubTab === 'overview' && 'Real-time telemetry, synchronized payment logs, and platform health metrics.'}
|
||||
{adminSubTab === 'modules' && 'Configure learning modules, categories, pricing, and availability states.'}
|
||||
{adminSubTab === 'module_builder' && 'Author and customize disease categories, clinical patterns, and treatment formulas.'}
|
||||
{adminSubTab === 'plans' && 'Manage localized pricing tiers, curriculum module bundles, and active pricing.'}
|
||||
{adminSubTab === 'coupons' && 'Manage discount codes, percentage cuts, module restrictions, and expiry dates.'}
|
||||
{adminSubTab === 'customers' && 'Inspect practitioner accounts, credentials, countries, and purchased plans.'}
|
||||
|
|
@ -1101,6 +1104,10 @@ export default function App() {
|
|||
/>
|
||||
)}
|
||||
|
||||
{adminSubTab === 'module_builder' && (
|
||||
<ModuleBuilderTab />
|
||||
)}
|
||||
|
||||
{adminSubTab === 'plans' && (
|
||||
<PlansTab
|
||||
plans={adminPlansList}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
import { Component, type ErrorInfo, type ReactNode } from 'react';
|
||||
import { AlertTriangle, RefreshCw } from 'lucide-react';
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
fallbackTitle?: string;
|
||||
}
|
||||
|
||||
interface State {
|
||||
hasError: boolean;
|
||||
error: Error | null;
|
||||
}
|
||||
|
||||
export class ErrorBoundary extends Component<Props, State> {
|
||||
public state: State = {
|
||||
hasError: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
public static getDerivedStateFromError(error: Error): State {
|
||||
return { hasError: true, error };
|
||||
}
|
||||
|
||||
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||
console.error('ErrorBoundary caught an error:', error, errorInfo);
|
||||
}
|
||||
|
||||
public handleReset = () => {
|
||||
this.setState({ hasError: false, error: null });
|
||||
};
|
||||
|
||||
public render() {
|
||||
if (this.state.hasError) {
|
||||
return (
|
||||
<div className="p-8 bg-white border border-rose-200 rounded-3xl shadow-sm text-center space-y-4 max-w-lg mx-auto my-8">
|
||||
<div className="h-12 w-12 rounded-2xl bg-rose-50 text-rose-600 flex items-center justify-center mx-auto">
|
||||
<AlertTriangle className="h-6 w-6" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-base font-black text-slate-900">
|
||||
{this.props.fallbackTitle || 'Something went wrong in this section'}
|
||||
</h3>
|
||||
<p className="text-xs text-slate-500 font-medium mt-1">
|
||||
{this.state.error?.message || 'An unexpected rendering error occurred.'}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={this.handleReset}
|
||||
className="px-4 py-2 bg-indigo-600 hover:bg-indigo-500 text-white text-xs font-bold rounded-xl inline-flex items-center gap-1.5 shadow"
|
||||
>
|
||||
<RefreshCw className="h-3.5 w-3.5" />
|
||||
Try Again
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ import React from 'react';
|
|||
import {
|
||||
Sparkles, ChevronLeft, ChevronRight, LogOut,
|
||||
List, BookOpen, Tag, Ticket, Users, CheckCircle,
|
||||
Receipt, Shield, Database, FileText, X
|
||||
Receipt, Shield, Database, FileText, X, Layers
|
||||
} from 'lucide-react';
|
||||
import type { LoggedInUser, AdminTabType } from '../../types';
|
||||
|
||||
|
|
@ -64,6 +64,7 @@ export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
|||
const tabs: TabItem[] = [
|
||||
{ key: 'overview', label: 'Overview & Logs', icon: <List className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'modules', label: 'Modules', count: counts.modules, icon: <BookOpen className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'module_builder', label: 'Module Builder', icon: <Layers className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'plans', label: 'Plans & Pricing', count: counts.plans, icon: <Tag className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'coupons', label: 'Coupons', count: counts.coupons, icon: <Ticket className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'customers', label: 'Customers', count: counts.customers, icon: <Users className="h-4 w-4 shrink-0" /> },
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,228 @@
|
|||
import { api } from './api';
|
||||
|
||||
export interface BuilderModuleSummary {
|
||||
id?: string;
|
||||
code: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
short_description?: string | null;
|
||||
description?: string | null;
|
||||
kind: string;
|
||||
managed_by: string;
|
||||
default_template_code?: string | null;
|
||||
sort_order: number;
|
||||
is_active: boolean;
|
||||
category_count: number;
|
||||
disease_count: number;
|
||||
pattern_count: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface BuilderCategorySummary {
|
||||
id?: string;
|
||||
module_code: string;
|
||||
category_code: string;
|
||||
name: string;
|
||||
overview?: string | null;
|
||||
sort_order: number;
|
||||
disease_count: number;
|
||||
}
|
||||
|
||||
export interface BuilderDiseaseSummary {
|
||||
id?: string;
|
||||
module_code: string;
|
||||
category_code: string;
|
||||
disease_code: string;
|
||||
name: string;
|
||||
overview?: string | null;
|
||||
sort_order: number;
|
||||
pattern_count: number;
|
||||
}
|
||||
|
||||
export interface PatternClinicalData {
|
||||
clinical_manifestations: string[];
|
||||
tongue: string;
|
||||
pulse: string;
|
||||
treatment_principle: string;
|
||||
acupuncture: {
|
||||
points: string;
|
||||
method: string;
|
||||
};
|
||||
explanation: string[];
|
||||
}
|
||||
|
||||
export interface BuilderPattern {
|
||||
id?: string;
|
||||
module_code: string;
|
||||
category_code: string;
|
||||
disease_code: string;
|
||||
pattern_code: string;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
clinical_data: PatternClinicalData;
|
||||
sort_order: number;
|
||||
}
|
||||
|
||||
export interface BuilderDiseaseDetail {
|
||||
id?: string;
|
||||
module_code: string;
|
||||
category_code: string;
|
||||
disease_code: string;
|
||||
name: string;
|
||||
overview?: string | null;
|
||||
sort_order: number;
|
||||
patterns: BuilderPattern[];
|
||||
}
|
||||
|
||||
export interface SaveFullDiseasePayload {
|
||||
category_code: string;
|
||||
disease_code: string;
|
||||
name: string;
|
||||
overview?: string | null;
|
||||
patterns: {
|
||||
category_code: string;
|
||||
disease_code: string;
|
||||
pattern_code: string;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
clinical_data: PatternClinicalData;
|
||||
sort_order: number;
|
||||
}[];
|
||||
}
|
||||
|
||||
export const moduleBuilderService = {
|
||||
// Modules
|
||||
async getModules(): Promise<BuilderModuleSummary[]> {
|
||||
const res = await api.get('/api/admin/module-builder/modules');
|
||||
return res.data;
|
||||
},
|
||||
|
||||
async createModule(data: {
|
||||
name: string;
|
||||
code?: string;
|
||||
slug?: string;
|
||||
short_description?: string;
|
||||
description?: string;
|
||||
kind?: string;
|
||||
managed_by?: string;
|
||||
sort_order?: number;
|
||||
}): Promise<BuilderModuleSummary> {
|
||||
const res = await api.post('/api/admin/module-builder/modules', data);
|
||||
return res.data;
|
||||
},
|
||||
|
||||
async deleteModule(moduleCode: string): Promise<boolean> {
|
||||
const res = await api.delete(`/api/admin/module-builder/modules/${moduleCode}`);
|
||||
return res.data?.status === 'deleted' || res.status === 200;
|
||||
},
|
||||
|
||||
// Categories
|
||||
async getCategories(moduleCode: string): Promise<BuilderCategorySummary[]> {
|
||||
const res = await api.get(`/api/admin/module-builder/${moduleCode}/categories`);
|
||||
return res.data;
|
||||
},
|
||||
|
||||
async saveCategory(
|
||||
moduleCode: string,
|
||||
data: { category_code: string; name: string; overview?: string; sort_order?: number }
|
||||
): Promise<BuilderCategorySummary> {
|
||||
const res = await api.post(`/api/admin/module-builder/${moduleCode}/categories`, data);
|
||||
return res.data;
|
||||
},
|
||||
|
||||
async deleteCategory(moduleCode: string, categoryCode: string): Promise<boolean> {
|
||||
const res = await api.delete(`/api/admin/module-builder/${moduleCode}/categories/${categoryCode}`);
|
||||
return res.data?.success ?? true;
|
||||
},
|
||||
|
||||
// Diseases
|
||||
async getDiseases(moduleCode: string, categoryCode: string): Promise<BuilderDiseaseSummary[]> {
|
||||
const res = await api.get(`/api/admin/module-builder/${moduleCode}/categories/${categoryCode}/diseases`);
|
||||
return res.data;
|
||||
},
|
||||
|
||||
async getDiseaseDetail(
|
||||
moduleCode: string,
|
||||
categoryCode: string,
|
||||
diseaseCode: string
|
||||
): Promise<BuilderDiseaseDetail> {
|
||||
const res = await api.get(
|
||||
`/api/admin/module-builder/${moduleCode}/categories/${categoryCode}/diseases/${diseaseCode}`
|
||||
);
|
||||
return res.data;
|
||||
},
|
||||
|
||||
async saveDisease(
|
||||
moduleCode: string,
|
||||
categoryCode: string,
|
||||
data: { disease_code: string; name: string; overview?: string; sort_order?: number; category_code?: string }
|
||||
): Promise<BuilderDiseaseSummary> {
|
||||
const res = await api.post(
|
||||
`/api/admin/module-builder/${moduleCode}/categories/${categoryCode}/diseases`,
|
||||
{ ...data, category_code: categoryCode }
|
||||
);
|
||||
return res.data;
|
||||
},
|
||||
|
||||
async deleteDisease(
|
||||
moduleCode: string,
|
||||
categoryCode: string,
|
||||
diseaseCode: string
|
||||
): Promise<boolean> {
|
||||
const res = await api.delete(
|
||||
`/api/admin/module-builder/${moduleCode}/categories/${categoryCode}/diseases/${diseaseCode}`
|
||||
);
|
||||
return res.data?.success ?? true;
|
||||
},
|
||||
|
||||
// Save Full Disease with Patterns
|
||||
async saveFullDisease(
|
||||
moduleCode: string,
|
||||
payload: SaveFullDiseasePayload
|
||||
): Promise<BuilderDiseaseDetail> {
|
||||
const res = await api.post(`/api/admin/module-builder/${moduleCode}/save-full`, payload);
|
||||
return res.data;
|
||||
},
|
||||
|
||||
// Export JSON
|
||||
async exportModuleJson(moduleCode: string): Promise<any> {
|
||||
const res = await api.get(`/api/admin/module-builder/${moduleCode}/export-json`);
|
||||
return res.data;
|
||||
},
|
||||
|
||||
// Export Production ZIP Package
|
||||
async exportBundleZip(moduleCode: string): Promise<{ blob: Blob; filename: string }> {
|
||||
const res = await api.get(`/api/admin/module-builder/${moduleCode}/export-bundle`, {
|
||||
responseType: 'blob',
|
||||
});
|
||||
const disposition = res.headers['content-disposition'] || '';
|
||||
let filename = `${moduleCode}_package.zip`;
|
||||
const match = disposition.match(/filename="?([^";]+)"?/);
|
||||
if (match && match[1]) {
|
||||
filename = match[1];
|
||||
}
|
||||
return { blob: res.data, filename };
|
||||
},
|
||||
|
||||
// Sync Directly to Content Repo
|
||||
async syncContentRepo(moduleCode: string): Promise<{
|
||||
status: string;
|
||||
module_code: string;
|
||||
module_name: string;
|
||||
target_dir: string;
|
||||
files_written: number;
|
||||
config_updated: boolean;
|
||||
message: string;
|
||||
}> {
|
||||
const res = await api.post(`/api/admin/module-builder/${moduleCode}/sync-content-repo`);
|
||||
return res.data;
|
||||
},
|
||||
|
||||
// Import JSON
|
||||
async importModuleJson(moduleCode: string, contents: any[]): Promise<any> {
|
||||
const res = await api.post(`/api/admin/module-builder/${moduleCode}/import-json`, { contents });
|
||||
return res.data;
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
export type AdminTabType =
|
||||
| 'overview'
|
||||
| 'modules'
|
||||
| 'module_builder'
|
||||
| 'plans'
|
||||
| 'coupons'
|
||||
| 'customers'
|
||||
|
|
|
|||
Loading…
Reference in New Issue