fix: admin audit — use actual API pattern + fix lazy imports
Some checks failed
Deploy Admin Frontend / build-and-deploy (push) Failing after 5s
Some checks failed
Deploy Admin Frontend / build-and-deploy (push) Failing after 5s
- Replace non-existent apiGet/apiPost with inline fetch - Fix lazy(() => import()).then() → lazy(() => import().then()) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
a9a7d651bb
commit
e4ab4bb02b
@ -7,14 +7,14 @@ const UserManagement = lazy(() => import('@/pages/UserManagement'))
|
|||||||
const MemberManagement = lazy(() => import('@/pages/MemberManagement'))
|
const MemberManagement = lazy(() => import('@/pages/MemberManagement'))
|
||||||
|
|
||||||
const LearningDashboard = lazy(() => import('@/pages/learning/Dashboard'))
|
const LearningDashboard = lazy(() => import('@/pages/learning/Dashboard'))
|
||||||
const ReadingEventPage = lazy(() => import('@/pages/learning/DataPages')).then(m => ({ default: m.ReadingEventPage }))
|
const ReadingEventPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.ReadingEventPage })))
|
||||||
const SessionPage = lazy(() => import('@/pages/learning/DataPages')).then(m => ({ default: m.SessionPage }))
|
const SessionPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.SessionPage })))
|
||||||
const ProgressPage = lazy(() => import('@/pages/learning/DataPages')).then(m => ({ default: m.ProgressPage }))
|
const ProgressPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.ProgressPage })))
|
||||||
const DailyActivityPage = lazy(() => import('@/pages/learning/DataPages')).then(m => ({ default: m.DailyActivityPage }))
|
const DailyActivityPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.DailyActivityPage })))
|
||||||
const RecordPage = lazy(() => import('@/pages/learning/DataPages')).then(m => ({ default: m.RecordPage }))
|
const RecordPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.RecordPage })))
|
||||||
const AnomalyPage = lazy(() => import('@/pages/learning/DataPages')).then(m => ({ default: m.AnomalyPage }))
|
const AnomalyPage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.AnomalyPage })))
|
||||||
const UserDiagnosePage = lazy(() => import('@/pages/learning/DataPages')).then(m => ({ default: m.UserDiagnosePage }))
|
const UserDiagnosePage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.UserDiagnosePage })))
|
||||||
const MaterialDiagnosePage = lazy(() => import('@/pages/learning/DataPages')).then(m => ({ default: m.MaterialDiagnosePage }))
|
const MaterialDiagnosePage = lazy(() => import('@/pages/learning/DataPages').then(m => ({ default: m.MaterialDiagnosePage })))
|
||||||
|
|
||||||
export interface RouteConfig {
|
export interface RouteConfig {
|
||||||
path: string
|
path: string
|
||||||
|
|||||||
@ -1,4 +1,30 @@
|
|||||||
import { apiGet, apiPost } from './api';
|
const BASE = '/api/admin/learning';
|
||||||
|
|
||||||
|
async function getApi<T>(path: string, params?: Record<string, any>): Promise<T> {
|
||||||
|
let url = `${BASE}${path}`;
|
||||||
|
if (params) {
|
||||||
|
const qs = Object.entries(params)
|
||||||
|
.filter(([, v]) => v !== undefined && v !== '')
|
||||||
|
.map(([k, v]) => `${k}=${encodeURIComponent(v)}`)
|
||||||
|
.join('&');
|
||||||
|
if (qs) url += `?${qs}`;
|
||||||
|
}
|
||||||
|
const res = await fetch(url, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${localStorage.getItem('admin_access_token') || ''}` } });
|
||||||
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
|
const json = await res.json();
|
||||||
|
return json.data ?? json;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function postApi<T>(path: string, body?: any): Promise<T> {
|
||||||
|
const res = await fetch(`${BASE}${path}`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${localStorage.getItem('admin_access_token') || ''}` },
|
||||||
|
body: body ? JSON.stringify(body) : undefined,
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
|
const json = await res.json();
|
||||||
|
return json.data ?? json;
|
||||||
|
}
|
||||||
|
|
||||||
export interface DashboardData {
|
export interface DashboardData {
|
||||||
overview: { totalEvents: number; todayEvents: number; failedEvents: number; duplicateEvents: number };
|
overview: { totalEvents: number; todayEvents: number; failedEvents: number; duplicateEvents: number };
|
||||||
@ -8,18 +34,18 @@ export interface DashboardData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const learningAdminAPI = {
|
export const learningAdminAPI = {
|
||||||
getDashboard: () => apiGet<DashboardData>('/admin/learning/dashboard'),
|
getDashboard: () => getApi<DashboardData>('/dashboard'),
|
||||||
getReadingEvents: (params?: Record<string, any>) => apiGet('/admin/learning/reading-events', params),
|
getReadingEvents: (params?: Record<string, any>) => getApi('/reading-events', params),
|
||||||
getFailedEvents: (params?: Record<string, any>) => apiGet('/admin/learning/reading-events/failed', params),
|
getFailedEvents: (params?: Record<string, any>) => getApi('/reading-events/failed', params),
|
||||||
getSessions: (params?: Record<string, any>) => apiGet('/admin/learning/sessions', params),
|
getSessions: (params?: Record<string, any>) => getApi('/sessions', params),
|
||||||
getProgress: (params?: Record<string, any>) => apiGet('/admin/learning/progress', params),
|
getProgress: (params?: Record<string, any>) => getApi('/progress', params),
|
||||||
getDailyActivities: (params?: Record<string, any>) => apiGet('/admin/learning/daily-activities', params),
|
getDailyActivities: (params?: Record<string, any>) => getApi('/daily-activities', params),
|
||||||
getRecords: (params?: Record<string, any>) => apiGet('/admin/learning/records', params),
|
getRecords: (params?: Record<string, any>) => getApi('/records', params),
|
||||||
getUserTimeline: (userId: string) => apiGet('/admin/learning/user-timeline', { userId }),
|
getUserTimeline: (userId: string) => getApi('/user-timeline', { userId }),
|
||||||
getUserDiagnose: (userId: string) => apiGet('/admin/learning/user-diagnose', { userId }),
|
getUserDiagnose: (userId: string) => getApi('/user-diagnose', { userId }),
|
||||||
getMaterialDiagnose: (materialId: string) => apiGet('/admin/learning/material-diagnose', { materialId }),
|
getMaterialDiagnose: (materialId: string) => getApi('/material-diagnose', { materialId }),
|
||||||
getAnomalies: () => apiGet('/admin/learning/anomalies'),
|
getAnomalies: () => getApi('/anomalies'),
|
||||||
getTemporaryMaterials: (params?: Record<string, any>) => apiGet('/admin/learning/temporary-materials', params),
|
getTemporaryMaterials: (params?: Record<string, any>) => getApi('/temporary-materials', params),
|
||||||
recalculate: () => apiPost('/admin/learning/recalculate'),
|
recalculate: () => postApi('/recalculate'),
|
||||||
exportData: (type: string) => apiGet('/admin/learning/export', { type }),
|
exportData: (type: string) => getApi('/export', { type }),
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user