App : page d'accueil retravaillée

En-tête avec logo du magasin, date et accès au compte ; salutation selon
l'heure ; bouton de scan mis en valeur ; chiffres du jour à pictogrammes ;
actions et réglages en lignes à pictogramme, regroupés par section ; écran
« Dernière étape » avant la conception de la carte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tony AVERTY 2026-10-07 14:43:29 +02:00
parent 0ac5dad9b2
commit 5d6e7692fa

View file

@ -1,16 +1,16 @@
import { useCallback, useState } from 'react'; import { useCallback, useState } from 'react';
import { Alert, Linking, Pressable, ScrollView, View } from 'react-native'; import { Image, Linking, Pressable, ScrollView, View } from 'react-native';
import { router, useFocusEffect } from 'expo-router'; import { router, useFocusEffect } from 'expo-router';
import { SafeAreaView } from 'react-native-safe-area-context'; import { SafeAreaView } from 'react-native-safe-area-context';
import Svg, { Path } from 'react-native-svg'; import Svg, { Path } from 'react-native-svg';
import { api, Summary } from '../src/api'; import { api, API_URL, Summary } from '../src/api';
import { useSession, useStore } from '../src/session'; import { useSession, useStore } from '../src/session';
import { Banner, BrandSymbol, Button, Card, T, unit } from '../src/ui'; import { BrandSymbol, Button, Card, T, unit } from '../src/ui';
import { font, useColors } from '../src/theme'; import { font, useColors } from '../src/theme';
function ScanIcon({ color }: { color: string }) { function ScanIcon({ color }: { color: string }) {
return ( return (
<Svg width={30} height={30} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth={2} strokeLinecap="round"> <Svg width={34} height={34} 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" /> <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> </Svg>
); );
@ -19,35 +19,91 @@ function ScanIcon({ color }: { color: string }) {
/** Adresse de l'espace web du Dirigeant (conception de la carte). */ /** Adresse de l'espace web du Dirigeant (conception de la carte). */
const ESPACE_URL = 'https://monespacepro.eu/espace'; const ESPACE_URL = 'https://monespacepro.eu/espace';
const greeting = () => (new Date().getHours() >= 18 ? 'Bonsoir' : 'Bonjour');
const today = () => new Date().toLocaleDateString('fr-FR', { weekday: 'long', day: 'numeric', month: 'long' });
export default function Home() { export default function Home() {
const { me } = useSession(); const { me } = useSession();
// Magasin inscrit en ligne : tant que la carte n'est pas conçue, pas de scan possible. // Magasin inscrit en ligne : tant que la carte n'est pas conçue, pas de scan possible.
return me?.store.cardDesign ? <Counter /> : <NoCardYet />; return me?.store.cardDesign ? <Counter /> : <NoCardYet />;
} }
/** En-tête commun : logo du magasin, date, accès au compte. */
function Header() {
const c = useColors();
const { me } = useSession();
const logo = me?.store.cardDesign?.logoUrl;
const first = me?.displayName.split(' ')[0] ?? '';
return (
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 12 }}>
<View style={{ width: 48, height: 48, borderRadius: 14, backgroundColor: c.surface, alignItems: 'center', justifyContent: 'center', overflow: 'hidden', borderWidth: 1, borderColor: c.border }}>
{logo ? <Image source={{ uri: `${API_URL}${logo}` }} style={{ width: 44, height: 44 }} resizeMode="contain" /> : <BrandSymbol size={32} />}
</View>
<View style={{ flex: 1 }}>
<T v="h2" numberOfLines={1}>{me?.store.name}</T>
<T v="muted" style={{ fontSize: 14 }} numberOfLines={1}>{today()}</T>
</View>
<Pressable accessibilityRole="button" accessibilityLabel={`Mon compte (${me?.displayName})`} hitSlop={8} onPress={() => router.push('/account')}>
{({ pressed }) => (
<View style={{ width: 44, height: 44, borderRadius: 22, backgroundColor: c.primarySoft, alignItems: 'center', justifyContent: 'center', opacity: pressed ? 0.7 : 1 }}>
<T style={{ fontFamily: font.extrabold, fontSize: 18, color: c.primary }}>{first.charAt(0).toUpperCase()}</T>
</View>
)}
</Pressable>
</View>
);
}
/** Ligne d'action ou de réglage : pictogramme, titre, sous-titre, chevron. */
function Row({ icon, title, sub, onPress }: { icon: string; title: string; sub?: string; onPress: () => void }) {
const c = useColors();
return (
<Pressable accessibilityRole="button" onPress={onPress}>
{({ pressed }) => (
<Card style={{ padding: 14, flexDirection: 'row', alignItems: 'center', gap: 14, opacity: pressed ? 0.7 : 1 }}>
<View style={{ width: 44, height: 44, borderRadius: 13, backgroundColor: c.primarySoft, alignItems: 'center', justifyContent: 'center' }}>
<T style={{ fontSize: 22 }}>{icon}</T>
</View>
<View style={{ flex: 1, gap: 2 }}>
<T style={{ fontFamily: font.bold, fontSize: 16 }}>{title}</T>
{!!sub && <T v="muted" style={{ fontSize: 13 }} numberOfLines={2}>{sub}</T>}
</View>
<T style={{ color: c.text3, fontSize: 22 }}>›</T>
</Card>
)}
</Pressable>
);
}
const sectionTitle = (c: ReturnType<typeof useColors>) => ({ color: c.text3, textTransform: 'uppercase' as const, fontSize: 13, letterSpacing: 0.5 });
function NoCardYet() { function NoCardYet() {
const c = useColors(); const c = useColors();
const { me, logout, reload } = useSession(); const { me, reload } = useSession();
const isManager = me?.role === 'MANAGER'; const isManager = me?.role === 'MANAGER';
return ( return (
<SafeAreaView style={{ flex: 1, backgroundColor: c.bg }}> <SafeAreaView style={{ flex: 1, backgroundColor: c.bg }}>
<ScrollView contentContainerStyle={{ padding: 20, gap: 16, flexGrow: 1 }}> <ScrollView contentContainerStyle={{ padding: 20, gap: 18, flexGrow: 1 }} bounces={false} overScrollMode="never">
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 12 }}> <Header />
<BrandSymbol size={36} /> <View style={{ alignItems: 'center', gap: 10, paddingVertical: 16 }}>
<T v="label" style={{ flex: 1 }} numberOfLines={1}>{me?.store.name}</T> <View style={{ width: 96, height: 96, borderRadius: 48, backgroundColor: c.primarySoft, alignItems: 'center', justifyContent: 'center' }}>
<T style={{ fontSize: 44 }}>🎨</T>
</View>
<T v="h1" style={{ textAlign: 'center' }}>{isManager ? 'Dernière étape' : 'Presque prêt'}</T>
<T v="muted" style={{ textAlign: 'center' }}>
{isManager
? 'Concevez votre carte de fidélité (logo, couleurs, récompenses) sur votre espace web. Le scan des cartes s’active ensuite.'
: 'La carte de fidélité du magasin n’est pas encore prête. Revenez un peu plus tard.'}
</T>
</View> </View>
<Banner tone="warn"> {isManager && <Button large label="Concevoir ma carte" onPress={() => Linking.openURL(ESPACE_URL)} />}
{isManager <Button label="C’est fait, actualiser" variant="secondary" onPress={reload} />
? 'Concevez votre carte de fidélité (logo, couleurs, récompenses) sur votre espace web : le scan des cartes s’active ensuite.' {isManager && (
: 'La carte de fidélité du magasin n’est pas encore prête. Revenez un peu plus tard.'} <View style={{ gap: 10, marginTop: 8 }}>
</Banner> <Row icon="👥" title="Employés" sub="Créez les comptes de votre équipe" onPress={() => router.push('/team')} />
{isManager && <Button label="Ouvrir mon espace web" onPress={() => Linking.openURL(ESPACE_URL)} />} <Row icon="🧩" title="Modules" sub="Préparez vos campagnes, relances et cadeaux" onPress={() => router.push('/loyalty')} />
<Button label="Actualiser" variant="secondary" onPress={reload} /> </View>
{isManager && <Button label="Employés" variant="secondary" onPress={() => router.push('/team')} />} )}
{isManager && <Button label="Modules" variant="secondary" onPress={() => router.push('/loyalty')} />}
<View style={{ flex: 1 }} />
<Button label="Mon compte" variant="secondary" onPress={() => router.push('/account')} />
<Button label="Se déconnecter" variant="secondary" onPress={logout} />
</ScrollView> </ScrollView>
</SafeAreaView> </SafeAreaView>
); );
@ -55,7 +111,7 @@ function NoCardYet() {
function Counter() { function Counter() {
const c = useColors(); const c = useColors();
const { me, logout } = useSession(); const { me } = useSession();
const store = useStore(); const store = useStore();
const [summary, setSummary] = useState<Summary | null>(null); const [summary, setSummary] = useState<Summary | null>(null);
const [tab, setTab] = useState<'scan' | 'config'>('scan'); const [tab, setTab] = useState<'scan' | 'config'>('scan');
@ -84,27 +140,7 @@ function Counter() {
bounces={false} bounces={false}
overScrollMode="never" overScrollMode="never"
> >
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 12 }}> <Header />
<BrandSymbol size={36} />
<View style={{ flex: 1 }}>
<T v="h2" numberOfLines={1}>{store.name}</T>
<T v="muted" numberOfLines={1}>
Bonjour {me?.displayName.split(' ')[0]} · {isManager ? 'Dirigeant' : '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>
{isManager && ( {isManager && (
<View accessibilityRole="tablist" style={{ flexDirection: 'row', backgroundColor: c.surface, borderRadius: 14, padding: 4, borderWidth: 1, borderColor: c.border }}> <View accessibilityRole="tablist" style={{ flexDirection: 'row', backgroundColor: c.surface, borderRadius: 14, padding: 4, borderWidth: 1, borderColor: c.border }}>
@ -131,46 +167,60 @@ function Counter() {
<ConfigTab /> <ConfigTab />
) : ( ) : (
<> <>
<T v="h1">
{greeting()} {me?.displayName.split(' ')[0]} 👋
</T>
{/* Action principale */}
<Pressable <Pressable
accessibilityRole="button" accessibilityRole="button"
accessibilityLabel="Scanner une carte" accessibilityLabel="Scanner une carte"
onPress={() => router.push('/scan')} onPress={() => router.push('/scan')}
style={({ pressed }) => ({ style={({ pressed }) => ({
backgroundColor: pressed ? c.primaryPressed : c.primary, backgroundColor: pressed ? c.primaryPressed : c.primary,
borderRadius: 24, borderRadius: 26,
paddingVertical: 48, paddingVertical: 40,
paddingHorizontal: 24,
alignItems: 'center', alignItems: 'center',
gap: 14, gap: 14,
shadowColor: c.primary,
shadowOpacity: 0.35,
shadowRadius: 16,
shadowOffset: { width: 0, height: 8 },
elevation: 6,
})} })}
> >
<View style={{ width: 64, height: 64, borderRadius: 32, backgroundColor: 'rgba(255,255,255,0.18)', alignItems: 'center', justifyContent: 'center' }}> <View style={{ width: 76, height: 76, borderRadius: 38, backgroundColor: 'rgba(255,255,255,0.18)', alignItems: 'center', justifyContent: 'center' }}>
<ScanIcon color={c.onPrimary} /> <ScanIcon color={c.onPrimary} />
</View> </View>
<T style={{ color: c.onPrimary, fontFamily: font.bold, fontSize: 24 }}>Scanner une carte</T> <T style={{ color: c.onPrimary, fontFamily: font.extrabold, fontSize: 26 }}>Scanner une carte</T>
<T style={{ color: c.onPrimary, opacity: 0.85, fontSize: 15 }}>QR code du Wallet du client</T> <T style={{ color: c.onPrimary, opacity: 0.85, fontSize: 15 }}>QR code du Wallet du client</T>
</Pressable> </Pressable>
{/* Chiffres du jour */}
<View style={{ gap: 10 }}> <View style={{ gap: 10 }}>
<T v="h2">{isManager ? "Aujourd'hui au magasin" : "Mes opérations aujourd'hui"}</T> <T v="label" style={sectionTitle(c)}>{isManager ? "Aujourd'hui au magasin" : "Mes opérations aujourd'hui"}</T>
<View style={{ flexDirection: 'row', gap: 12 }}> <View style={{ flexDirection: 'row', gap: 10 }}>
{[ {[
[summary?.operations ?? '—', 'opérations'], ['🧾', summary?.operations ?? '—', 'opérations'],
[summary?.pointsGiven ?? '—', `${u} donnés`], ['➕', summary?.pointsGiven ?? '—', `${u} donnés`],
[summary?.rewards ?? '—', 'récompenses'], ['🎁', summary?.rewards ?? '—', 'récompenses'],
].map(([n, l]) => ( ].map(([icon, n, l]) => (
<Card key={String(l)} style={{ flex: 1, padding: 14, gap: 2, backgroundColor: c.primarySoft, borderColor: c.primarySoft }}> <View key={String(l)} style={{ flex: 1, padding: 14, gap: 4, borderRadius: 18, backgroundColor: c.primarySoft }}>
<T style={{ fontSize: 16 }}>{icon}</T>
<T style={{ fontFamily: font.extrabold, fontSize: 26, color: c.primary }}>{n}</T> <T style={{ fontFamily: font.extrabold, fontSize: 26, color: c.primary }}>{n}</T>
<T v="muted" style={{ fontSize: 13 }}>{l}</T> <T v="muted" style={{ fontSize: 12 }} numberOfLines={1}>{l}</T>
</Card> </View>
))} ))}
</View> </View>
</View> </View>
<View style={{ flex: 1 }} /> {/* Autres actions */}
{isManager && <Button label="Envoyer une campagne" variant="secondary" onPress={() => router.push('/campaigns')} />} <View style={{ gap: 10 }}>
{isManager && <Button label="Statistiques" variant="secondary" onPress={() => router.push('/stats')} />} {isManager && <Row icon="📣" title="Envoyer une campagne" sub="Une notification à tous vos clients" onPress={() => router.push('/campaigns')} />}
<Button label="Historique des opérations" variant="secondary" onPress={() => router.push('/history')} /> {isManager && <Row icon="📊" title="Statistiques" sub="Passages, clients fidèles, exports" onPress={() => router.push('/stats')} />}
{!isManager && <Button label="Mon compte" variant="secondary" onPress={() => router.push('/account')} />} <Row icon="🕘" title="Historique des opérations" sub={isManager ? 'Toutes les opérations du magasin' : 'Vos opérations'} onPress={() => router.push('/history')} />
</View>
</> </>
)} )}
</ScrollView> </ScrollView>
@ -181,27 +231,14 @@ function Counter() {
/** Onglet Configuration (Dirigeant) : tout ce qui se règle. */ /** Onglet Configuration (Dirigeant) : tout ce qui se règle. */
function ConfigTab() { function ConfigTab() {
const c = useColors(); const c = useColors();
const rows: [string, string, () => void][] = [
['Modules', 'Campagnes, relances, anniversaire, avis Google, parrainage : activation, textes et récompenses', () => router.push('/loyalty')],
['Employés', 'Comptes, rôles Employé / Dirigeant, mots de passe', () => router.push('/team')],
['Carte de fidélité', 'Logo, couleurs, règle de points, récompenses (espace web)', () => Linking.openURL(ESPACE_URL)],
['Mon compte', 'Mot de passe', () => router.push('/account')],
];
return ( return (
<View style={{ gap: 12 }}> <View style={{ gap: 10 }}>
{rows.map(([title, sub, go]) => ( <T v="label" style={sectionTitle(c)}>Fidélisation</T>
<Pressable key={title} accessibilityRole="button" onPress={go}> <Row icon="🧩" title="Modules" sub="Campagnes, relances, anniversaire, avis Google, parrainage" onPress={() => router.push('/loyalty')} />
{({ pressed }) => ( <Row icon="🎨" title="Carte de fidélité" sub="Logo, couleurs, règle de points, récompenses (espace web)" onPress={() => Linking.openURL(ESPACE_URL)} />
<Card style={{ padding: 16, gap: 4, opacity: pressed ? 0.7 : 1 }}> <T v="label" style={[sectionTitle(c), { marginTop: 10 }]}>Équipe et compte</T>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}> <Row icon="👥" title="Employés" sub="Comptes, rôles Employé / Dirigeant, mots de passe" onPress={() => router.push('/team')} />
<T style={{ fontFamily: font.bold, fontSize: 17 }}>{title}</T> <Row icon="🔐" title="Mon compte" sub="Mot de passe, déconnexion" onPress={() => router.push('/account')} />
<T style={{ color: c.text3, fontSize: 20 }}>›</T>
</View>
<T v="muted" style={{ fontSize: 14 }}>{sub}</T>
</Card>
)}
</Pressable>
))}
</View> </View>
); );
} }