Les pages des commerçants (/inscription, /espace) sont copiées dans le site vitrine par « npm --prefix admin run build:espace » ; liens des e-mails, de Stripe et de l'app Pro mis à jour. ADMIN_URL n'est plus nécessaire. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
161 lines
6.7 KiB
TypeScript
161 lines
6.7 KiB
TypeScript
import { useCallback, useState } from 'react';
|
||
import { Alert, Linking, 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 { 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 [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 ? '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>
|
||
|
||
<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="Modules" variant="secondary" onPress={() => router.push('/loyalty')} />}
|
||
{isManager && <Button label="Campagnes" variant="secondary" onPress={() => router.push('/campaigns')} />}
|
||
{isManager && <Button label="Employés" variant="secondary" onPress={() => router.push('/team')} />}
|
||
{isManager && <Button label="Statistiques" variant="secondary" onPress={() => router.push('/stats')} />}
|
||
<Button label="Historique des opérations" variant="secondary" onPress={() => router.push('/history')} />
|
||
<Button label="Mon compte" variant="secondary" onPress={() => router.push('/account')} />
|
||
</ScrollView>
|
||
</SafeAreaView>
|
||
);
|
||
}
|