refactor(admin): replace static dashboard stats with dynamic widget registry

This commit is contained in:
2026-04-15 20:43:10 -04:00
parent 371a69c499
commit 41edccc1a3
11 changed files with 198 additions and 69 deletions
+22
View File
@@ -0,0 +1,22 @@
/**
* Auth Feature — Contribution serveur au tableau de bord
*
* Ce module s'auto-enregistre auprès du registre admin en side effect.
* Dépendance correcte : auth → admin (feature → core).
*/
import { registerServerWidget } from '../admin/dashboard/registry.js';
import { query } from '@zen/core/database';
import { fail } from '@zen/core/shared/logger';
async function getDashboardData() {
try {
const result = await query(`SELECT COUNT(*) as count FROM zen_auth_users`);
return { totalUsers: parseInt(result.rows[0].count) || 0 };
} catch (error) {
fail(`Auth dashboard data error: ${error.message}`);
return { totalUsers: 0 };
}
}
registerServerWidget('auth', getDashboardData);
+33
View File
@@ -0,0 +1,33 @@
'use client';
/**
* Auth Feature — Widget client pour le tableau de bord
*
* Ce module s'auto-enregistre auprès du registre admin en side effect.
* Dépendance correcte : auth → admin (feature → core).
*
* Props du composant :
* data — { totalUsers: number } retourné par getDashboardData(), ou null
* loading — true tant que les données serveur ne sont pas disponibles
*/
import { registerClientWidget } from '../admin/dashboard/clientRegistry.js';
import { StatCard } from '@zen/core/shared/components';
import { UserMultiple02Icon } from '@zen/core/shared/icons';
function AuthDashboardWidget({ data, loading }) {
return (
<StatCard
title="Nombre d'utilisateurs"
value={loading ? '-' : String(data?.totalUsers ?? 0)}
icon={UserMultiple02Icon}
color="text-purple-400"
bgColor="bg-purple-500/10"
loading={loading}
/>
);
}
registerClientWidget('auth', AuthDashboardWidget, 10);
export default AuthDashboardWidget;