diff --git a/pro/app/stats.tsx b/pro/app/stats.tsx index 5213801..f89ca8c 100644 --- a/pro/app/stats.tsx +++ b/pro/app/stats.tsx @@ -1,9 +1,9 @@ import { useCallback, useState } from 'react'; -import { Alert, Pressable, ScrollView, View } from 'react-native'; +import { ActivityIndicator, Alert, Pressable, ScrollView, View } from 'react-native'; import { useFocusEffect } from 'expo-router'; import { api, ApiError } from '../src/api'; import { describe } from '../src/errors'; -import { Banner, Button, Card, T } from '../src/ui'; +import { Banner, Card, T } from '../src/ui'; import { font, useColors } from '../src/theme'; interface Stats { @@ -26,7 +26,7 @@ interface Stats { top: { firstName: string; visits: number; amountCents: number }[]; } -const PERIODS: [number, string][] = [[30, '30 j'], [90, '3 mois'], [365, '12 mois']]; +const PERIODS: [number, string][] = [[30, '30 jours'], [90, '3 mois'], [365, '12 mois']]; const euros = (c: number) => (c / 100).toLocaleString('fr-FR', { style: 'currency', currency: 'EUR', maximumFractionDigits: 0 }); const pctText = (n: number | null) => (n === null ? '' : `${n >= 0 ? '▲' : '▼'} ${Math.abs(n)} %`); @@ -77,74 +77,105 @@ export default function StatsScreen() { const k = data?.kpis; const max = Math.max(1, ...(data?.series.map((s) => s.visits) ?? [1])); - const tiles: [string, string, string?][] = k + // Le passage est mis en avant ; les autres indicateurs en tuiles. + const tiles: [string, string, string, string?][] = k ? [ - ['Passages', String(k.visits), pctText(k.visitsChange)], - ['Nouvelles cartes', String(k.newCards), `${k.cardsTotal} au total`], - ['Clients actifs', String(k.activeCustomers), `${k.visitsPerCustomer} passage(s)/client`], - ['Clients fidèles', k.returningRate === null ? '—' : `${k.returningRate} %`, 'venus 2 fois ou plus'], + ['🆕', 'Nouvelles cartes', String(k.newCards), `${k.cardsTotal} au total`], + ['👥', 'Clients actifs', String(k.activeCustomers), `${k.visitsPerCustomer} passage(s) / client`], + ['🔁', 'Clients fidèles', k.returningRate === null ? '—' : `${k.returningRate} %`, 'venus 2 fois ou plus'], + ['🎁', 'Récompenses', String(k.rewardsRedeemed), 'utilisées'], ...(data!.pointsMode === 'AMOUNT' - ? ([['Achats', euros(k.revenueCents), k.averageBasketCents === null ? '' : `panier ${euros(k.averageBasketCents)}`]] as [string, string, string][]) + ? ([ + ['💶', 'Achats', euros(k.revenueCents), k.averageBasketCents === null ? '' : `panier moyen ${euros(k.averageBasketCents)}`], + ] as [string, string, string, string][]) : []), - ['Récompenses', String(k.rewardsRedeemed)], ] : []; + const trend = k?.visitsChange ?? null; + const MEDAL = ['🥇', '🥈', '🥉']; return ( - - + + {/* Période : contrôle segmenté */} + {PERIODS.map(([d, label]) => ( setDays(d)} - style={{ paddingVertical: 10, paddingHorizontal: 16, borderRadius: 999, borderWidth: 1, borderColor: days === d ? c.primary : c.border, backgroundColor: days === d ? c.primarySoft : c.surface }} + style={{ flex: 1, paddingVertical: 10, borderRadius: 10, alignItems: 'center', backgroundColor: days === d ? c.primary : 'transparent' }} > - {label} + {label} ))} {error && {error}} - {!data ? ( + {!data || !k ? ( !error && Chargement… ) : ( <> + {/* Passages : chiffre clé, évolution et graphique */} + + + + Passages en magasin + {k.visits} + + {trend !== null && ( + + {pctText(trend)} + + )} + + + {data.series.map((s, i) => ( + + ))} + + + {data.series[0]?.label} + {data.series[data.series.length - 1]?.label} + + {data.busiest && ( + + ⏱ Créneau le plus fréquenté : {data.busiest} + + )} + + - {tiles.map(([label, value, hint]) => ( - - {label} - {value} + {tiles.map(([icon, label, value, hint]) => ( + + + {icon} + {label} + + {value} {!!hint && {hint}} ))} - - Passages - - {data.series.map((s, i) => ( - - ))} - - - {data.series[0]?.label} - {data.series[data.series.length - 1]?.label} - - {data.busiest && Créneau le plus fréquenté : {data.busiest}} - - {data.top.length > 0 && ( - - Meilleurs clients + + Meilleurs clients {data.top.slice(0, 5).map((t, i) => ( - - {i + 1}. {t.firstName} - + + + {MEDAL[i] ?? i + 1} + + {t.firstName} + {t.visits} passage{t.visits > 1 ? 's' : ''} {data.pointsMode === 'AMOUNT' ? ` · ${euros(t.amountCents)}` : ''} @@ -153,10 +184,29 @@ export default function StatsScreen() { )} - Exports - Le fichier CSV (ouvrable avec Excel) est envoyé uniquement par e-mail au dirigeant de la société. -