MonEspacePro/pro/app/index.tsx
Tony AVERTY 9096e799f4 Statistiques avancées et export CSV (formule Pro)
- Indicateurs sur 30 j / 3 mois / 12 mois : passages et nouvelles cartes (vs période
  précédente), clients actifs et fidèles, achats et panier moyen, récompenses, adoption Apple Wallet
- Courbe de fréquentation, heures d'affluence (jour × heure, heure de Paris), meilleurs clients
- Exports CSV clients et opérations (format Excel FR, formules neutralisées)
- Admin : onglet Statistiques avec téléchargement ; app Pro : écran gérant, export envoyé par e-mail

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 10:47:48 +02:00

121 lines
4.6 KiB
TypeScript

import { useCallback, useState } from 'react';
import { Alert, Pressable, RefreshControl, ScrollView, View } from 'react-native';
import { router, useFocusEffect } from 'expo-router';
import { SafeAreaView } from 'react-native-safe-area-context';
import Svg, { Path } from 'react-native-svg';
import { api, Summary } from '../src/api';
import { useSession, useStore } from '../src/session';
import { BrandSymbol, Button, Card, T, unit } from '../src/ui';
import { font, useColors } from '../src/theme';
function ScanIcon({ color }: { color: string }) {
return (
<Svg width={30} height={30} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth={2} strokeLinecap="round">
<Path d="M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3M7 12h10" />
</Svg>
);
}
export default function Home() {
const c = useColors();
const { me, logout } = useSession();
const store = useStore();
const [summary, setSummary] = useState<Summary | null>(null);
const [refreshing, setRefreshing] = useState(false);
const load = useCallback(async () => {
try {
setSummary(await api.get<Summary>('/api/staff/summary'));
} catch {
/* résumé indicatif : on garde l'ancien */
}
}, []);
useFocusEffect(
useCallback(() => {
load();
}, [load]),
);
const isManager = me?.role === 'MANAGER';
const u = unit(store.design.pointsMode);
return (
<SafeAreaView style={{ flex: 1, backgroundColor: c.bg }}>
<ScrollView
contentContainerStyle={{ padding: 20, gap: 20, flexGrow: 1 }}
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={async () => {
setRefreshing(true);
await load();
setRefreshing(false);
}}
/>
}
>
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 12 }}>
<BrandSymbol size={36} />
<View style={{ flex: 1 }}>
<T v="label" numberOfLines={1}>{store.name}</T>
<T v="muted" numberOfLines={1}>
{me?.displayName} · {isManager ? 'Gérant' : 'Employé'}
</T>
</View>
<Pressable
accessibilityRole="button"
hitSlop={12}
onPress={() =>
Alert.alert('Se déconnecter ?', undefined, [
{ text: 'Annuler', style: 'cancel' },
{ text: 'Se déconnecter', style: 'destructive', onPress: logout },
])
}
>
<T v="label" style={{ color: c.primary }}>Déconnexion</T>
</Pressable>
</View>
<Pressable
accessibilityRole="button"
accessibilityLabel="Scanner une carte"
onPress={() => router.push('/scan')}
style={({ pressed }) => ({
backgroundColor: pressed ? c.primaryPressed : c.primary,
borderRadius: 24,
paddingVertical: 48,
alignItems: 'center',
gap: 14,
})}
>
<View style={{ width: 64, height: 64, borderRadius: 32, backgroundColor: 'rgba(255,255,255,0.18)', alignItems: 'center', justifyContent: 'center' }}>
<ScanIcon color={c.onPrimary} />
</View>
<T style={{ color: c.onPrimary, fontFamily: font.bold, fontSize: 24 }}>Scanner une carte</T>
<T style={{ color: c.onPrimary, opacity: 0.85, fontSize: 15 }}>QR code du Wallet du client</T>
</Pressable>
<View style={{ gap: 10 }}>
<T v="h2">{isManager ? "Aujourd'hui au magasin" : "Mes opérations aujourd'hui"}</T>
<View style={{ flexDirection: 'row', gap: 12 }}>
{[
[summary?.operations ?? '—', 'opérations'],
[summary?.pointsGiven ?? '—', `${u} donnés`],
[summary?.rewards ?? '—', 'récompenses'],
].map(([n, l]) => (
<Card key={String(l)} style={{ flex: 1, padding: 14, gap: 2 }}>
<T style={{ fontFamily: font.extrabold, fontSize: 26 }}>{n}</T>
<T v="muted" style={{ fontSize: 13 }}>{l}</T>
</Card>
))}
</View>
</View>
<View style={{ flex: 1 }} />
{isManager && <Button label="Fidélisation" variant="secondary" onPress={() => router.push('/loyalty')} />}
{isManager && <Button label="Statistiques" variant="secondary" onPress={() => router.push('/stats')} />}
<Button label="Historique des opérations" variant="secondary" onPress={() => router.push('/history')} />
</ScrollView>
</SafeAreaView>
);
}