App : fiche client et historique retravaillés

- Fiche client : initiale, carte aux couleurs du magasin avec barre de
  progression vers la prochaine récompense, section « Cadeaux à remettre »
- Historique : contrôle segmenté, résumé de la période, opérations en cartes
  avec icône et pastille de points, intertitres par jour sur 7 jours

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tony AVERTY 2026-10-07 14:14:26 +02:00
parent 567d9fb877
commit 53a598080e
2 changed files with 148 additions and 92 deletions

View file

@ -1,5 +1,5 @@
import { useState } from 'react'; import { useState } from 'react';
import { ActivityIndicator, Alert, View } from 'react-native'; import { ActivityIndicator, Alert, Pressable, View } from 'react-native';
import { router } from 'expo-router'; import { router } from 'expo-router';
import { useStore } from '../../../src/session'; import { useStore } from '../../../src/session';
import { useCard } from '../../../src/useCard'; import { useCard } from '../../../src/useCard';
@ -28,7 +28,6 @@ export default function ClientCard() {
if (!card) return <Screen style={{ justifyContent: 'center' }}><ActivityIndicator /></Screen>; if (!card) return <Screen style={{ justifyContent: 'center' }}><ActivityIndicator /></Screen>;
const mode = store.design.pointsMode; const mode = store.design.pointsMode;
const cheapest = store.design.rewards[0];
const reachable = store.design.rewards.filter((r) => r.cost <= card.balance).length; const reachable = store.design.rewards.filter((r) => r.cost <= card.balance).length;
const SOURCE = { BIRTHDAY: 'Anniversaire', REFERRAL: 'Parrainage', REFERRAL_FRIEND: 'Bienvenue (parrainage)' } as const; const SOURCE = { BIRTHDAY: 'Anniversaire', REFERRAL: 'Parrainage', REFERRAL_FRIEND: 'Bienvenue (parrainage)' } as const;
@ -50,41 +49,52 @@ export default function ClientCard() {
}, },
]); ]);
// Prochain palier : la première récompense pas encore atteinte (sinon la plus chère).
const sortedRewards = [...store.design.rewards].sort((a, b) => a.cost - b.cost);
const target = sortedRewards.find((r) => r.cost > card.balance) ?? sortedRewards[sortedRewards.length - 1];
const progress = target ? Math.min(card.balance / target.cost, 1) : 0;
const fg = store.design.foregroundColor;
const memberSince = new Date(card.memberSince).toLocaleDateString('fr-FR', { month: 'short', year: 'numeric' });
return ( return (
<Screen scroll> <Screen scroll>
<View style={{ gap: 4 }}> {/* En-tête : initiale, prénom, ancienneté */}
<T v="h1">{card.firstName}</T> <View style={{ flexDirection: 'row', alignItems: 'center', gap: 14 }}>
<T v="muted"> <View style={{ width: 56, height: 56, borderRadius: 28, backgroundColor: c.primarySoft, alignItems: 'center', justifyContent: 'center' }}>
{card.lastCreditAt ? `Dernière visite ${ago(card.lastCreditAt)}` : 'Première visite'} · client depuis le{' '} <T style={{ fontFamily: font.extrabold, fontSize: 24, color: c.primary }}>{card.firstName.charAt(0).toUpperCase()}</T>
{new Date(card.memberSince).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short', year: 'numeric' })} </View>
<View style={{ flex: 1, gap: 2 }}>
<T v="h1" numberOfLines={1}>{card.firstName}</T>
<T v="muted" style={{ fontSize: 14 }}>
{card.lastCreditAt ? `Dernière visite ${ago(card.lastCreditAt)}` : 'Première visite'} · client depuis {memberSince}
</T> </T>
</View> </View>
</View>
<Card style={{ alignItems: 'center', paddingVertical: 28, backgroundColor: store.design.backgroundColor, borderColor: store.design.backgroundColor }}> {/* Carte aux couleurs du magasin : solde et progression */}
<T style={{ color: store.design.foregroundColor, fontFamily: font.semibold, fontSize: 14, letterSpacing: 1 }}>SOLDE</T> <View style={{ backgroundColor: store.design.backgroundColor, borderRadius: 22, padding: 22, gap: 14 }}>
<T v="big" style={{ color: store.design.foregroundColor }}>{card.balance}</T> <T style={{ color: fg, opacity: 0.8, fontFamily: font.semibold, fontSize: 13, letterSpacing: 1 }} numberOfLines={1}>
<T style={{ color: store.design.foregroundColor, fontSize: 16 }}>{unit(mode, card.balance)}</T> {store.design.programName.toUpperCase()}
</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> </T>
) : null} <View style={{ flexDirection: 'row', alignItems: 'flex-end', gap: 8 }}>
<T v="big" style={{ color: fg }}>{card.balance}</T>
{card.gifts?.map((g) => ( <T style={{ color: fg, fontFamily: font.semibold, fontSize: 18, marginBottom: 10 }}>{unit(mode, card.balance)}</T>
<Card key={g.id} style={{ padding: 14, gap: 10, borderColor: c.ok }}> </View>
<View style={{ gap: 2 }}> {target && (
<T v="label">🎁 {g.label}</T> <View style={{ gap: 8 }}>
<T v="muted" style={{ fontSize: 13 }}> <View style={{ height: 8, borderRadius: 4, backgroundColor: fg.length === 7 ? `${fg}40` : 'rgba(127,127,127,0.3)', overflow: 'hidden' }}>
{SOURCE[g.source]} · {new Date(g.createdAt).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' })} <View style={{ width: `${Math.round(progress * 100)}%`, height: 8, borderRadius: 4, backgroundColor: c.accent }} />
</View>
<T style={{ color: fg, fontSize: 14 }}>
{reachable > 0
? reachable === 1
? '1 récompense disponible'
: `${reachable} récompenses disponibles`
: `Encore ${target.cost - card.balance} ${unit(mode, target.cost - card.balance)} avant « ${target.label} »`}
</T> </T>
</View> </View>
<Button label="Marquer comme remis" variant="secondary" loading={giving === g.id} onPress={() => give(g)} /> )}
</Card> </View>
))}
{card.nextCreditAt && ( {card.nextCreditAt && (
<Banner tone="warn"> <Banner tone="warn">
@ -93,6 +103,33 @@ export default function ClientCard() {
</Banner> </Banner>
)} )}
{/* Cadeaux en nature à remettre en caisse */}
{card.gifts?.length > 0 && (
<View style={{ gap: 10 }}>
<T v="h2">Cadeaux à remettre</T>
{card.gifts.map((g) => (
<Card key={g.id} style={{ padding: 14, flexDirection: 'row', alignItems: 'center', gap: 12 }}>
<View style={{ width: 44, height: 44, borderRadius: 22, backgroundColor: c.warnBg, alignItems: 'center', justifyContent: 'center' }}>
<T style={{ fontSize: 22 }}>🎁</T>
</View>
<View style={{ flex: 1, gap: 2 }}>
<T v="label">{g.label}</T>
<T v="muted" style={{ fontSize: 13 }}>
{SOURCE[g.source]} · {new Date(g.createdAt).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' })}
</T>
</View>
{giving === g.id ? (
<ActivityIndicator />
) : (
<Pressable accessibilityRole="button" hitSlop={8} onPress={() => give(g)}>
<T style={{ color: c.primary, fontFamily: font.bold }}>Remettre</T>
</Pressable>
)}
</Card>
))}
</View>
)}
<View style={{ flex: 1 }} /> <View style={{ flex: 1 }} />
<Button <Button
large large
@ -100,12 +137,12 @@ export default function ClientCard() {
onPress={() => router.push({ pathname: '/client/[serial]/credit', params: { serial } })} onPress={() => router.push({ pathname: '/client/[serial]/credit', params: { serial } })}
/> />
<Button <Button
label="Utiliser une récompense" label={reachable > 0 ? 'Utiliser une récompense' : 'Voir les récompenses'}
variant="secondary" variant="secondary"
disabled={store.design.rewards.length === 0} disabled={store.design.rewards.length === 0}
onPress={() => router.push({ pathname: '/client/[serial]/rewards', params: { serial } })} onPress={() => router.push({ pathname: '/client/[serial]/rewards', params: { serial } })}
/> />
<T v="muted" style={{ textAlign: 'center', color: c.text3, fontSize: 13 }}>Carte {serial}</T> <T v="muted" style={{ textAlign: 'center', fontSize: 12 }}>Carte {serial}</T>
</Screen> </Screen>
); );
} }

View file

@ -2,7 +2,7 @@ import { useCallback, useEffect, useState } from 'react';
import { ActivityIndicator, FlatList, Pressable, View } from 'react-native'; import { ActivityIndicator, FlatList, Pressable, View } from 'react-native';
import { api, Operation } from '../src/api'; import { api, Operation } from '../src/api';
import { useSession, useStore } from '../src/session'; import { useSession, useStore } from '../src/session';
import { Banner, T, euros, unit } from '../src/ui'; import { Banner, Card, T, euros, unit } from '../src/ui';
import { font, useColors } from '../src/theme'; import { font, useColors } from '../src/theme';
type Period = 'today' | 'week'; type Period = 'today' | 'week';
@ -51,81 +51,100 @@ export default function History() {
const mode = store.design.pointsMode; const mode = store.design.pointsMode;
// Résumé de la période (opérations chargées).
const done = items.filter((o) => o.type !== 'REJECTED');
const given = done.filter((o) => o.points > 0).reduce((n, o) => n + o.points, 0);
const rewards = done.filter((o) => o.type === 'REDEEM').length;
const dayOf = (iso: string) => new Date(iso).toLocaleDateString('fr-FR', { weekday: 'long', day: 'numeric', month: 'long' });
return ( return (
<View style={{ flex: 1, backgroundColor: c.bg }}> <View style={{ flex: 1, backgroundColor: c.bg }}>
<View style={{ flexDirection: 'row', gap: 8, padding: 16, paddingBottom: 8 }}> <View style={{ padding: 16, paddingBottom: 8, gap: 12 }}>
{/* Période : contrôle segmenté */}
<View accessibilityRole="tablist" style={{ flexDirection: 'row', backgroundColor: c.surface, borderRadius: 14, padding: 4, borderWidth: 1, borderColor: c.border }}>
{(['today', 'week'] as const).map((p) => ( {(['today', 'week'] as const).map((p) => (
<Pressable <Pressable
key={p} key={p}
accessibilityRole="button" accessibilityRole="tab"
accessibilityState={{ selected: period === p }} accessibilityState={{ selected: period === p }}
onPress={() => setPeriod(p)} onPress={() => setPeriod(p)}
style={{ style={{ flex: 1, paddingVertical: 10, borderRadius: 10, alignItems: 'center', backgroundColor: period === p ? c.primary : 'transparent' }}
height: 44,
paddingHorizontal: 18,
borderRadius: 22,
justifyContent: 'center',
backgroundColor: period === p ? c.primary : c.surface,
borderWidth: 1,
borderColor: period === p ? c.primary : c.border,
}}
> >
<T style={{ fontFamily: font.semibold, color: period === p ? c.onPrimary : c.text }}>{p === 'today' ? "Aujourd'hui" : '7 jours'}</T> <T style={{ fontFamily: font.bold, fontSize: 15, color: period === p ? c.onPrimary : c.text }}>{p === 'today' ? "Aujourd'hui" : '7 jours'}</T>
</Pressable> </Pressable>
))} ))}
</View> </View>
<T v="muted" style={{ paddingHorizontal: 16, paddingBottom: 8 }}> <View style={{ flexDirection: 'row', gap: 10 }}>
{isManager ? 'Toutes les opérations du magasin' : 'Vos opérations'} {[
</T> [done.length, 'opérations'],
[given, `${unit(mode)} donnés`],
[rewards, 'récompenses'],
].map(([n, l]) => (
<View key={String(l)} style={{ flex: 1, backgroundColor: c.primarySoft, borderRadius: 14, paddingVertical: 10, paddingHorizontal: 12 }}>
<T style={{ fontFamily: font.extrabold, fontSize: 20, color: c.primary }}>{n}</T>
<T v="muted" style={{ fontSize: 12 }}>{l}</T>
</View>
))}
</View>
<T v="muted" style={{ fontSize: 13 }}>{isManager ? 'Toutes les opérations du magasin' : 'Vos opérations'}</T>
</View>
{error && <View style={{ paddingHorizontal: 16 }}><Banner tone="error">{error}</Banner></View>} {error && <View style={{ paddingHorizontal: 16 }}><Banner tone="error">{error}</Banner></View>}
<FlatList <FlatList
data={items} data={items}
keyExtractor={(o) => o.id} keyExtractor={(o) => o.id}
contentContainerStyle={{ paddingHorizontal: 16, paddingBottom: 32 }} contentContainerStyle={{ paddingHorizontal: 16, paddingBottom: 32, gap: 8 }}
onEndReached={() => cursor && !loading && load(false)} onEndReached={() => cursor && !loading && load(false)}
onEndReachedThreshold={0.5} onEndReachedThreshold={0.5}
bounces={false} bounces={false}
overScrollMode="never" overScrollMode="never"
ListEmptyComponent={!loading ? <T v="muted" style={{ textAlign: 'center', marginTop: 40 }}>Aucune opération sur la période.</T> : null} ListEmptyComponent={
!loading ? (
<View style={{ alignItems: 'center', marginTop: 48, gap: 6 }}>
<T style={{ fontSize: 36 }}>🗒️</T>
<T v="muted" style={{ textAlign: 'center' }}>Aucune opération sur la période.</T>
</View>
) : null
}
ListFooterComponent={loading ? <ActivityIndicator style={{ margin: 16 }} /> : null} ListFooterComponent={loading ? <ActivityIndicator style={{ margin: 16 }} /> : null}
ItemSeparatorComponent={() => <View style={{ height: 1, backgroundColor: c.border }} />} renderItem={({ item: o, index }) => {
renderItem={({ item: o }) => {
const rejected = o.type === 'REJECTED'; const rejected = o.type === 'REJECTED';
const time = new Date(o.createdAt).toLocaleString('fr-FR', { const redeem = o.type === 'REDEEM';
...(period === 'week' && { weekday: 'short' }), const time = new Date(o.createdAt).toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' });
hour: '2-digit', // Sur 7 jours : un intertitre à chaque nouveau jour.
minute: '2-digit', const newDay = period === 'week' && (index === 0 || dayOf(items[index - 1].createdAt) !== dayOf(o.createdAt));
}); const what = redeem
const what =
o.type === 'REDEEM'
? o.reward?.label ?? 'Récompense' ? o.reward?.label ?? 'Récompense'
: rejected : rejected
? REASON[o.rejectReason ?? ''] ?? 'Refusé' ? REASON[o.rejectReason ?? ''] ?? 'Refusé'
: o.amountCents : o.amountCents
? euros(o.amountCents) ? euros(o.amountCents)
: 'Passage'; : 'Passage';
const [iconBg, iconFg, icon] = rejected ? [c.errBg, c.err, '!'] : redeem ? [c.warnBg, c.warn, '★'] : [c.okBg, c.ok, '+'];
return ( return (
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 12, paddingVertical: 14 }}> <View style={{ gap: 8 }}>
<View style={{ width: 54 }}> {newDay && (
<T v="muted" style={{ fontSize: 14 }}>{time}</T> <T v="label" style={{ marginTop: index === 0 ? 0 : 10, color: c.text3, textTransform: 'capitalize' }}>
{dayOf(o.createdAt)}
</T>
)}
<Card style={{ flexDirection: 'row', alignItems: 'center', gap: 12, padding: 12, opacity: rejected ? 0.85 : 1 }}>
<View style={{ width: 40, height: 40, borderRadius: 20, backgroundColor: iconBg, alignItems: 'center', justifyContent: 'center' }}>
<T style={{ fontFamily: font.extrabold, fontSize: 18, color: iconFg }}>{icon}</T>
</View> </View>
<View style={{ flex: 1, gap: 2 }}> <View style={{ flex: 1, gap: 2 }}>
<T v="label" numberOfLines={1}>{o.customerFirstName}</T> <T v="label" numberOfLines={1}>{o.customerFirstName}</T>
<T v="muted" numberOfLines={1} style={{ fontSize: 14, color: rejected ? c.err : c.text3 }}> <T v="muted" numberOfLines={1} style={{ fontSize: 13, color: rejected ? c.err : c.text3 }}>
{what} {time} · {what}
{isManager ? ` · ${o.staff.displayName}` : ''} {isManager ? ` · ${o.staff.displayName}` : ''}
</T> </T>
</View> </View>
<T <View style={{ paddingHorizontal: 10, paddingVertical: 4, borderRadius: 999, backgroundColor: rejected ? c.surface2 : o.points > 0 ? c.okBg : c.warnBg }}>
style={{ <T style={{ fontFamily: font.bold, fontSize: 15, color: rejected ? c.text3 : o.points > 0 ? c.ok : c.warn }}>
fontFamily: font.bold, {rejected ? '—' : `${o.points > 0 ? '+' : '−'}${Math.abs(o.points)}`}
fontSize: 17,
color: rejected ? c.text3 : o.points > 0 ? c.ok : c.text,
}}
>
{rejected ? '—' : `${o.points > 0 ? '+' : '−'}${Math.abs(o.points)} ${unit(mode, Math.abs(o.points)).slice(0, 3)}.`}
</T> </T>
</View> </View>
</Card>
</View>
); );
}} }}
/> />