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 (
);
}
/** 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 ? : ;
}
function NoCardYet() {
const c = useColors();
const { me, logout, reload } = useSession();
const isManager = me?.role === 'MANAGER';
return (
{me?.store.name}
{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.'}
{isManager &&
);
}
function Counter() {
const c = useColors();
const { me, logout } = useSession();
const store = useStore();
const [summary, setSummary] = useState(null);
const [refreshing, setRefreshing] = useState(false);
const [tab, setTab] = useState<'scan' | 'config'>('scan');
const load = useCallback(async () => {
try {
setSummary(await api.get('/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 (
{
setRefreshing(true);
await load();
setRefreshing(false);
}}
/>
}
>
{store.name}
{me?.displayName} · {isManager ? 'Dirigeant' : 'Employé'}
Alert.alert('Se déconnecter ?', undefined, [
{ text: 'Annuler', style: 'cancel' },
{ text: 'Se déconnecter', style: 'destructive', onPress: logout },
])
}
>
Déconnexion
{isManager && (
{(
[
['scan', 'Scan'],
['config', 'Configuration'],
] as const
).map(([k, label]) => (
setTab(k)}
style={{ flex: 1, paddingVertical: 10, borderRadius: 10, alignItems: 'center', backgroundColor: tab === k ? c.primary : 'transparent' }}
>
{label}
))}
)}
{tab === 'config' && isManager ? (
) : (
<>
router.push('/scan')}
style={({ pressed }) => ({
backgroundColor: pressed ? c.primaryPressed : c.primary,
borderRadius: 24,
paddingVertical: 48,
alignItems: 'center',
gap: 14,
})}
>
Scanner une carte
QR code du Wallet du client
{isManager ? "Aujourd'hui au magasin" : "Mes opérations aujourd'hui"}
{[
[summary?.operations ?? '—', 'opérations'],
[summary?.pointsGiven ?? '—', `${u} donnés`],
[summary?.rewards ?? '—', 'récompenses'],
].map(([n, l]) => (
{n}
{l}
))}
{isManager && router.push('/campaigns')} />}
{isManager && router.push('/stats')} />}
router.push('/history')} />
{!isManager && router.push('/account')} />}
>
)}
);
}
/** 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 (
{rows.map(([title, sub, go]) => (
{({ pressed }) => (
{title}
›
{sub}
)}
))}
);
}