- Modèle Campaign + migration manuelle 2026-10-07-campagnes.sql - Apple : champ « Actualité » au dos avec changeMessage, push APNs - Google : message de classe TEXT_AND_NOTIFY - 1 campagne par 24 h, magasin actif, message différent du précédent - Onglet Campagnes dans l'admin, écran Campagnes (gérants) dans l'app Pro - Site : « Bientôt » retiré des campagnes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
4.5 KiB
TypeScript
120 lines
4.5 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="Envoyer une campagne" variant="secondary" onPress={() => router.push('/campaigns')} />}
|
|
<Button label="Historique des opérations" variant="secondary" onPress={() => router.push('/history')} />
|
|
</ScrollView>
|
|
</SafeAreaView>
|
|
);
|
|
}
|