'use client'; import React, { useState, useEffect } from 'react'; import { useTranslations } from 'next-intl'; import { Users, Clock, CalendarCheck, School, TrendingUp } from 'lucide-react'; import Loader from '@/components/Loader'; import ClasseDetails from '@/components/ClasseDetails'; import { fetchClasses } from '@/app/actions/schoolAction'; import StatCard from '@/components/StatCard'; import logger from '@/utils/logger'; import { fetchRegisterForms } from '@/app/actions/subscriptionAction'; import { fetchUpcomingEvents } from '@/app/actions/planningAction'; import { useEstablishment } from '@/context/EstablishmentContext'; import { useNotification } from '@/context/NotificationContext'; // Composant EventCard pour afficher les événements const EventCard = ({ title, date, description, type }) => (

{title}

{date}

{description}

); export default function DashboardPage() { const t = useTranslations('dashboard'); const [isLoading, setIsLoading] = useState(false); const [totalStudents, setTotalStudents] = useState(0); const [pendingRegistration, setPendingRegistration] = useState(0); const [structureCapacity, setStructureCapacity] = useState(0); const [upcomingEvents, setUpcomingEvents] = useState([]); const [monthlyStats, setMonthlyStats] = useState({ inscriptions: [], completionRate: 0, }); const [classes, setClasses] = useState([]); const { selectedEstablishmentId, selectedEstablishmentTotalCapacity } = useEstablishment(); const { showNotification } = useNotification(); useEffect(() => { if (!selectedEstablishmentId) return; setIsLoading(true); // Début du chargement // Fetch des classes fetchClasses(selectedEstablishmentId) .then((data) => { setClasses(data); logger.info('Classes fetched:', data); const nbMaxStudents = data.reduce( (acc, classe) => acc + classe.number_of_students, 0 ); const nbStudents = data.reduce( (acc, classe) => acc + classe.students.length, 0 ); setStructureCapacity(nbMaxStudents); setTotalStudents(nbStudents); }) .catch((error) => { logger.error('Error fetching classes:', error); showNotification( 'Error fetching classes: ' + error.message, 'error', 'Erreur' ); }); // Fetch des formulaires d'inscription fetchRegisterForms(selectedEstablishmentId) .then((data) => { logger.info('Pending registrations fetched:', data); setPendingRegistration(data.count); }) .catch((error) => { logger.error('Error fetching pending registrations:', error); }); // Fetch des événements à venir fetchUpcomingEvents(selectedEstablishmentId) .then((data) => { setUpcomingEvents(data); }) .catch((error) => { logger.error('Error fetching upcoming events:', error); }) .finally(() => { setIsLoading(false); // Fin du chargement }); }, [selectedEstablishmentId]); if (isLoading) return ; return (

{t('dashboard')}

{/* Statistiques principales */}
} /> } color="green" /> } color="emerald" /> } color="orange" />
{/* Événements et KPIs */}
{/* Graphique des inscriptions */}

{t('inscriptionTrends')}

{/* Insérer ici un composant de graphique */}
{/* Événements à venir */}

{t('upcomingEvents')}

{upcomingEvents.map((event, index) => ( ))}
); }