import { getUsers } from '@/app/actions/admin' import { AdminMetrics } from '@/components/admin-metrics' import { Users, Activity, Database, Zap, CreditCard, Bot } from 'lucide-react' import prisma from '@/lib/prisma' import Link from 'next/link' async function getAdminDashboardStats() { const now = new Date() const dayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000) const monthStart = new Date(now.getFullYear(), now.getMonth(), 1) const [ userCount, noteCount, notebookCount, agentsEnabled, agentRunsToday, paidSubs, recentUsers, ] = await Promise.all([ prisma.user.count().catch(() => 0), prisma.note.count({ where: { trashedAt: null } }).catch(() => 0), prisma.notebook.count().catch(() => 0), prisma.agent.count({ where: { isEnabled: true } }).catch(() => 0), prisma.agentAction.count({ where: { createdAt: { gte: dayAgo } } }).catch(() => 0), prisma.subscription.count({ where: { tier: { in: ['PRO', 'BUSINESS', 'ENTERPRISE'] }, status: 'ACTIVE' }, }).catch(() => 0), prisma.user.findMany({ orderBy: { createdAt: 'desc' }, take: 8, select: { id: true, name: true, email: true, createdAt: true, role: true }, }).catch(() => []), ]) // AI usage this month let aiRequestsMonth = 0 try { aiRequestsMonth = await prisma.usageLog.aggregate({ where: { periodStart: { gte: monthStart } }, _sum: { requestsCount: true }, }).then((r) => r._sum.requestsCount ?? 0) } catch { try { aiRequestsMonth = await prisma.agentAction.count({ where: { createdAt: { gte: monthStart } }, }) } catch { aiRequestsMonth = 0 } } return { userCount, noteCount, notebookCount, agentsEnabled, agentRunsToday, paidSubs, aiRequestsMonth, recentUsers, } } export default async function AdminPage() { const [users, stats] = await Promise.all([getUsers(), getAdminDashboardStats()]) const metrics = [ { title: 'Utilisateurs', value: stats.userCount, trend: undefined as { value: number; isPositive: boolean } | undefined, icon: , }, { title: 'Notes', value: stats.noteCount.toLocaleString('fr-FR'), icon: , }, { title: 'Abonnements payants', value: stats.paidSubs, icon: , }, { title: 'Agents actifs', value: stats.agentsEnabled, icon: , }, { title: 'Exécutions agents (24h)', value: stats.agentRunsToday, icon: , }, { title: 'Usage IA (mois)', value: stats.aiRequestsMonth.toLocaleString('fr-FR'), icon: , }, ] return (

Administration

Vue d'ensemble en temps réel — {stats.notebookCount} carnets · {users.length} comptes listés

Facturation & quotas Config IA Utilisateurs Paramètres

Derniers utilisateurs

{stats.recentUsers.length === 0 ? (

Aucun utilisateur.

) : (
    {stats.recentUsers.map((u) => (
  • {u.name || u.email}

    {u.email}

    {u.role}

    {u.createdAt ? new Date(u.createdAt).toLocaleDateString('fr-FR') : '—'}

  • ))}
)}

Raccourcis ops

  • · Configurer les Price IDs Stripe dans Facturation
  • · Vérifier les quotas IA par feature (BASIC / PRO / BUSINESS)
  • · Tester les providers dans IA
  • · CRON_SECRET requis pour agents planifiés (entrypoint Docker)
  • · Notes indexées via embeddings + fragments (y compris notes courtes)
) }