11import { useEffect , useState } from 'react' ;
22import { useAdminAuth } from '@/hooks/useAdminAuth' ;
33import { useServiceHealth } from '@/hooks/useServiceHealth' ;
4- import { useFirestoreMonitoring } from '@/hooks/useFirestoreMonitoring ' ;
4+ import { useSupabaseMonitoring } from '@/hooks/useSupabaseMonitoring ' ;
55import { useProductionDBMonitoring } from '@/hooks/useProductionDBMonitoring' ;
6- import { collection , getDocs , getCountFromServer } from 'firebase/firestore' ;
7- import { db } from '@/lib/firebase' ;
6+ // Suppression des imports Firebase - utilisation de Supabase maintenant
7+ // import { collection, getDocs, getCountFromServer } from 'firebase/firestore';
8+ // import { db } from '@/lib/firebase';
89import Logger from '@/utils/logger' ;
910import { AdminHeader } from './admin/AdminHeader' ;
1011import { SystemStatusCard } from './admin/SystemStatusCard' ;
1112import { SystemMetricsGrid } from './admin/SystemMetricsGrid' ;
1213import { ServiceHealthList } from './admin/ServiceHealthList' ;
1314import { AdminActions } from './admin/AdminActions' ;
14- import { FirestoreMetricsCard } from './admin/FirestoreMetricsCard ' ;
15+ import { SupabaseMetricsCard } from './admin/SupabaseMetricsCard ' ;
1516import { ProductionDBCard } from './admin/ProductionDBCard' ;
1617
1718interface SystemStats {
@@ -32,7 +33,7 @@ interface SystemHealth {
3233export const AdminDashboard = ( ) => {
3334 const { currentEmail, adminEmail } = useAdminAuth ( ) ;
3435 const { healthChecks, isChecking, lastUpdate, runHealthChecks } = useServiceHealth ( ) ;
35- const { metrics : firestoreMetrics , isLoading : isFirestoreLoading , refreshMetrics } = useFirestoreMonitoring ( ) ;
36+ const { metrics : supabaseMetrics , isLoading : isSupabaseLoading , refreshMetrics } = useSupabaseMonitoring ( ) ;
3637 const { metrics : productionMetrics , isLoading : isProductionLoading , refreshMetrics : refreshProductionMetrics } = useProductionDBMonitoring ( ) ;
3738 const [ systemStats , setSystemStats ] = useState < SystemStats > ( {
3839 totalCollections : 0 ,
@@ -56,45 +57,21 @@ export const AdminDashboard = () => {
5657
5758 const loadSystemStats = async ( ) => {
5859 try {
59- Logger . admin ( 'Loading real system statistics' ) ;
60-
61- // Compter les documents dans les collections principales
62- const collections = [ 'campaigns' , 'affiliates' , 'clicks' , 'conversions' ] ;
63- let totalDocs = 0 ;
64-
65- for ( const collectionName of collections ) {
66- try {
67- const countQuery = await getCountFromServer ( collection ( db , collectionName ) ) ;
68- totalDocs += countQuery . data ( ) . count ;
69- } catch ( error ) {
70- Logger . warning ( `Could not count ${ collectionName } , falling back to getDocs` ) ;
71- const snapshot = await getDocs ( collection ( db , collectionName ) ) ;
72- totalDocs += snapshot . size ;
73- }
74- }
75-
76- // Calculer les vraies métriques basées sur les health checks
77- const avgResponseTime = healthChecks . length > 0
78- ? Math . round ( healthChecks . reduce ( ( sum , check ) => sum + check . responseTime , 0 ) / healthChecks . length )
79- : 0 ;
80-
81- const healthyServices = healthChecks . filter ( check => check . status === 'operational' ) . length ;
82-
83- setSystemStats ( {
84- totalCollections : collections . length ,
85- totalDocuments : totalDocs ,
86- averageResponseTime : avgResponseTime ,
87- healthyServices,
60+ Logger . admin ( 'Loading system statistics from Supabase' ) ;
61+
62+ // Utiliser les métriques Supabase au lieu de Firebase
63+ const stats = {
64+ totalCollections : 4 , // campaigns, affiliates, clicks, conversions
65+ totalDocuments : supabaseMetrics . totalCampaigns + supabaseMetrics . totalAffiliates + supabaseMetrics . totalClicks + supabaseMetrics . totalConversions ,
66+ averageResponseTime : supabaseMetrics . avgResponseTime ,
67+ healthyServices : healthChecks . filter ( check => check . status === 'operational' ) . length ,
8868 totalServices : healthChecks . length ,
8969 lastUpdateTime : new Date ( ) ,
90- } ) ;
70+ } ;
71+
72+ setSystemStats ( stats ) ;
9173
92- Logger . admin ( 'Real system stats loaded' , {
93- totalDocuments : totalDocs ,
94- avgResponseTime,
95- healthyServices,
96- totalServices : healthChecks . length
97- } ) ;
74+ Logger . admin ( 'System stats loaded from Supabase' , stats ) ;
9875 } catch ( error ) {
9976 Logger . error ( 'ADMIN - Error loading system stats' , error ) ;
10077 } finally {
@@ -176,9 +153,9 @@ export const AdminDashboard = () => {
176153 onRefresh = { refreshProductionMetrics }
177154 />
178155
179- < FirestoreMetricsCard
180- metrics = { firestoreMetrics }
181- isLoading = { isFirestoreLoading }
156+ < SupabaseMetricsCard
157+ metrics = { supabaseMetrics }
158+ isLoading = { isSupabaseLoading }
182159 onRefresh = { refreshMetrics }
183160 />
184161
0 commit comments