MonEspacePro/pro/app/index.tsx
Tony AVERTY 567d9fb877 App : pastille de validation sous la Dynamic Island, bouton retour, finitions visuelles
- Écrans sans en-tête (confirmation, autorisation caméra) : marge haute de sécurité
- Récompenses : bouton « Retour » ; confirmation : « Retour à la fiche client »
- Fiche client rechargée à chaque affichage (solde à jour)
- Cartes à ombre légère, boutons plus arrondis, halo de validation,
  accueil avec salutation et chiffres du jour sur fond teinté

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

207 lines
8.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useCallback, useState } from 'react';
import { Alert, Linking, Pressable, 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 { Banner, 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>
);
}
/** Adresse de l'espace web du Dirigeant (conception de la carte). */
const ESPACE_URL = 'https://monespacepro.eu/espace';
export default function Home() {
const { me } = useSession();
// Magasin inscrit en ligne : tant que la carte n'est pas conçue, pas de scan possible.
return me?.store.cardDesign ? <Counter /> : <NoCardYet />;
}
function NoCardYet() {
const c = useColors();
const { me, logout, reload } = useSession();
const isManager = me?.role === 'MANAGER';
return (
<SafeAreaView style={{ flex: 1, backgroundColor: c.bg }}>
<ScrollView contentContainerStyle={{ padding: 20, gap: 16, flexGrow: 1 }}>
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 12 }}>
<BrandSymbol size={36} />
<T v="label" style={{ flex: 1 }} numberOfLines={1}>{me?.store.name}</T>
</View>
<Banner tone="warn">
{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.'}
</Banner>
{isManager && <Button label="Ouvrir mon espace web" onPress={() => Linking.openURL(ESPACE_URL)} />}
<Button label="Actualiser" variant="secondary" onPress={reload} />
{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>
</SafeAreaView>
);
}
function Counter() {
const c = useColors();
const { me, logout } = useSession();
const store = useStore();
const [summary, setSummary] = useState<Summary | null>(null);
const [tab, setTab] = useState<'scan' | 'config'>('scan');
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 }}
// Pas de « tirer pour actualiser » : les chiffres se rechargent à chaque retour sur l'écran.
bounces={false}
overScrollMode="never"
>
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 12 }}>
<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 && (
<View accessibilityRole="tablist" style={{ flexDirection: 'row', backgroundColor: c.surface, borderRadius: 14, padding: 4, borderWidth: 1, borderColor: c.border }}>
{(
[
['scan', 'Scan'],
['config', 'Configuration'],
] as const
).map(([k, label]) => (
<Pressable
key={k}
accessibilityRole="tab"
accessibilityState={{ selected: tab === k }}
onPress={() => setTab(k)}
style={{ flex: 1, paddingVertical: 10, borderRadius: 10, alignItems: 'center', backgroundColor: tab === k ? c.primary : 'transparent' }}
>
<T style={{ fontFamily: font.bold, fontSize: 15, color: tab === k ? c.onPrimary : c.text }}>{label}</T>
</Pressable>
))}
</View>
)}
{tab === 'config' && isManager ? (
<ConfigTab />
) : (
<>
<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, backgroundColor: c.primarySoft, borderColor: c.primarySoft }}>
<T style={{ fontFamily: font.extrabold, fontSize: 26, color: c.primary }}>{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')} />}
{isManager && <Button label="Statistiques" variant="secondary" onPress={() => router.push('/stats')} />}
<Button label="Historique des opérations" variant="secondary" onPress={() => router.push('/history')} />
{!isManager && <Button label="Mon compte" variant="secondary" onPress={() => router.push('/account')} />}
</>
)}
</ScrollView>
</SafeAreaView>
);
}
/** Onglet Configuration (Dirigeant) : tout ce qui se règle. */
function ConfigTab() {
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 (
<View style={{ gap: 12 }}>
{rows.map(([title, sub, go]) => (
<Pressable key={title} accessibilityRole="button" onPress={go}>
{({ pressed }) => (
<Card style={{ padding: 16, gap: 4, opacity: pressed ? 0.7 : 1 }}>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
<T style={{ fontFamily: font.bold, fontSize: 17 }}>{title}</T>
<T style={{ color: c.text3, fontSize: 20 }}>›</T>
</View>
<T v="muted" style={{ fontSize: 14 }}>{sub}</T>
</Card>
)}
</Pressable>
))}
</View>
);
}