first commit

This commit is contained in:
nBiqoz
2025-10-05 16:10:35 +02:00
parent 201fca4e68
commit 13cd637391
70 changed files with 7287 additions and 130 deletions

34
hooks/useMetrics.ts Normal file
View File

@@ -0,0 +1,34 @@
"use client";
import { useState, useEffect, useCallback } from 'react';
import { DashboardMetrics } from '@/lib/types';
export function useMetrics() {
const [metrics, setMetrics] = useState<DashboardMetrics | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const fetchMetrics = useCallback(async () => {
try {
setLoading(true);
const response = await fetch('/api/metrics');
if (!response.ok) throw new Error('Erreur lors du chargement des métriques');
const data = await response.json();
setMetrics(data);
} catch (err) {
setError(err instanceof Error ? err.message : 'Erreur inconnue');
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
fetchMetrics();
}, [fetchMetrics]);
const refetch = useCallback(() => {
return fetchMetrics();
}, [fetchMetrics]);
return { metrics, loading, error, refetch };
}