From f2d4bb3c5fd1139c3306c242aa69210f1116ccda Mon Sep 17 00:00:00 2001 From: soufiane Date: Mon, 1 Dec 2025 15:55:29 +0100 Subject: [PATCH] fix: hide empty demographic data in marketing page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Filter out NOT_SPECIFIED and empty values from charts - Show placeholder message when no demographic data available - Hide city/gender filters when no valid data - Remove debug console.log statements 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/admin/marketing-data/page.tsx | 250 +++++++++++++++++------------- 1 file changed, 143 insertions(+), 107 deletions(-) diff --git a/app/admin/marketing-data/page.tsx b/app/admin/marketing-data/page.tsx index 3627512..d753166 100644 --- a/app/admin/marketing-data/page.tsx +++ b/app/admin/marketing-data/page.tsx @@ -66,10 +66,6 @@ export default function MarketingPage() { setLoading(true); const token = localStorage.getItem('auth_token') || localStorage.getItem('token'); - console.log('Loading marketing stats...'); - console.log('API URL:', API_BASE_URL); - console.log('Token present:', !!token); - const response = await fetch( `${API_BASE_URL}/admin/marketing/stats`, { @@ -80,22 +76,18 @@ export default function MarketingPage() { } ); - console.log('Response status:', response.status); - if (!response.ok) { let errorMessage = 'Erreur lors du chargement'; try { const errorData = await response.json(); errorMessage = errorData.error || errorData.message || errorMessage; - console.error('Error from API:', errorData); - } catch (e) { - console.error('Failed to parse error response'); + } catch { + // Ignore parse error } throw new Error(errorMessage); } const data = await response.json(); - console.log('Marketing stats loaded:', data); setStats(data.data); } catch (error: any) { console.error('Error loading marketing stats:', error); @@ -216,6 +208,22 @@ export default function MarketingPage() { ); } + // Filtrer les données vides/non spécifiées pour les graphiques + const filteredGenderData = stats.byGender.filter( + (g) => g.gender && !g.gender.toLowerCase().includes('not_specified') && !g.gender.toLowerCase().includes('non spécifié') && g.count > 0 + ); + + const filteredAgeData = stats.byAge.filter( + (a) => a.range && !a.range.toLowerCase().includes('non spécifié') && a.count > 0 + ); + + const filteredCityData = stats.byCity.filter( + (c) => c.city && c.city.trim() !== '' && !c.city.toLowerCase().includes('non spécifié') && c.count > 0 + ); + + // Vérifier s'il y a des données démographiques valides + const hasDemographicData = filteredGenderData.length > 0 || filteredAgeData.length > 0 || filteredCityData.length > 0; + return (
{/* En-tête */} @@ -287,73 +295,95 @@ export default function MarketingPage() {
- {/* Graphiques */} -
- {/* Répartition par genre */} - -

- - Répartition par Genre -

- - - `${entry.gender}: ${entry.count}`} - > - {stats.byGender.map((entry, index) => ( - + {/* Graphiques - Affichés uniquement s'il y a des données valides */} + {hasDemographicData ? ( + <> +
+ {/* Répartition par genre */} + {filteredGenderData.length > 0 && ( + +

+ + Répartition par Genre +

+ + + `${entry.gender}: ${entry.count}`} + > + {filteredGenderData.map((entry, index) => ( + + ))} + + + + + +
+ )} + + {/* Répartition par âge */} + {filteredAgeData.length > 0 && ( + +

+ + Répartition par Âge +

+ + + + + + + + + + +
+ )} +
+ + {/* Top villes */} + {filteredCityData.length > 0 && ( + +

+ + Top Villes ({filteredCityData.length}) +

+
+ {filteredCityData.slice(0, 10).map((city, index) => ( +
+

#{index + 1}

+

{city.city}

+

{city.count}

+
))} - - - - - +
+
+ )} + + ) : ( + +
+ +

+ Données démographiques non disponibles +

+

+ Les informations sur le genre, l'âge et la ville des participants ne sont pas encore renseignées. +

+
- - {/* Répartition par âge */} - -

- - Répartition par Âge -

- - - - - - - - - - -
-
- - {/* Top villes */} - -

- - Top Villes ({stats.byCity.length}) -

-
- {stats.byCity.slice(0, 10).map((city, index) => ( -
-

#{index + 1}

-

{city.city}

-

{city.count}

-
- ))} -
-
+ )} {/* Section Export */} @@ -385,40 +415,46 @@ export default function MarketingPage() { - {/* Filtres additionnels */} -
-
- - -
+ {/* Filtres additionnels - Affichés uniquement si données disponibles */} + {(filteredCityData.length > 0 || filteredGenderData.length > 0) && ( +
+ {filteredCityData.length > 0 && ( +
+ + +
+ )} -
- - + {filteredGenderData.length > 0 && ( +
+ + +
+ )}
-
+ )} {/* Boutons d'action */}