MonEspacePro/pro/app/client/[serial]/index.tsx
Tony AVERTY 6725358a7c App Pro (Expo) et API du comptoir avec anti-triche
- API /staff : profil, scan d'une carte, crédit (montant ou tampon),
  récompenses, historique (gérant : tout le magasin, employé : le sien),
  résumé du jour
- Anti-triche côté serveur : carte du bon magasin, plafond de montant,
  délai minimum entre deux crédits (atomique, scans simultanés compris),
  tentatives refusées journalisées avec l'employé
- App Expo SDK 54 / Expo Router : connexion, accueil, scanner QR avec
  lampe, fiche client, pavé numérique, récompenses, confirmation, erreurs,
  historique ; icônes générées depuis le logo

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 12:50:59 +02:00

77 lines
3.3 KiB
TypeScript

import { ActivityIndicator, View } from 'react-native';
import { router } from 'expo-router';
import { useStore } from '../../../src/session';
import { useCard } from '../../../src/useCard';
import { ErrorScreen } from '../../../src/errors';
import { Banner, Button, Card, Screen, T, unit } from '../../../src/ui';
import { font, useColors } from '../../../src/theme';
function ago(iso: string) {
const min = Math.round((Date.now() - new Date(iso).getTime()) / 60000);
if (min < 1) return "à l'instant";
if (min < 60) return `il y a ${min} min`;
const h = Math.round(min / 60);
if (h < 24) return `il y a ${h} h`;
return `le ${new Date(iso).toLocaleDateString('fr-FR', { day: 'numeric', month: 'long' })}`;
}
/** Fiche client après scan (maquette 4). */
export default function ClientCard() {
const c = useColors();
const store = useStore();
const { serial, card, error, reload } = useCard();
if (error) return <ErrorScreen error={error} onRetry={reload} />;
if (!card) return <Screen style={{ justifyContent: 'center' }}><ActivityIndicator /></Screen>;
const mode = store.design.pointsMode;
const cheapest = store.design.rewards[0];
const reachable = store.design.rewards.filter((r) => r.cost <= card.balance).length;
return (
<Screen scroll>
<View style={{ gap: 4 }}>
<T v="h1">{card.firstName}</T>
<T v="muted">
{card.lastCreditAt ? `Dernière visite ${ago(card.lastCreditAt)}` : 'Première visite'} · client depuis le{' '}
{new Date(card.memberSince).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short', year: 'numeric' })}
</T>
</View>
<Card style={{ alignItems: 'center', paddingVertical: 28, backgroundColor: store.design.backgroundColor, borderColor: store.design.backgroundColor }}>
<T style={{ color: store.design.foregroundColor, fontFamily: font.semibold, fontSize: 14, letterSpacing: 1 }}>SOLDE</T>
<T v="big" style={{ color: store.design.foregroundColor }}>{card.balance}</T>
<T style={{ color: store.design.foregroundColor, fontSize: 16 }}>{unit(mode, card.balance)}</T>
</Card>
{reachable > 0 ? (
<Banner tone="ok">{reachable === 1 ? '1 récompense disponible' : `${reachable} récompenses disponibles`}</Banner>
) : cheapest ? (
<T v="muted" style={{ textAlign: 'center' }}>
Encore {cheapest.cost - card.balance} {unit(mode, cheapest.cost - card.balance)} avant « {cheapest.label} »
</T>
) : null}
{card.nextCreditAt && (
<Banner tone="warn">
Déjà créditée récemment : nouveau crédit possible à{' '}
{new Date(card.nextCreditAt).toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' })}.
</Banner>
)}
<View style={{ flex: 1 }} />
<Button
large
label={mode === 'STAMP' ? 'Ajouter un tampon' : 'Créditer'}
onPress={() => router.push({ pathname: '/client/[serial]/credit', params: { serial } })}
/>
<Button
label="Utiliser une récompense"
variant="secondary"
disabled={store.design.rewards.length === 0}
onPress={() => router.push({ pathname: '/client/[serial]/rewards', params: { serial } })}
/>
<T v="muted" style={{ textAlign: 'center', color: c.text3, fontSize: 13 }}>Carte {serial}</T>
</Screen>
);
}