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:
parent
567d9fb877
commit
53a598080e
2 changed files with 148 additions and 92 deletions
|
|
@ -1,5 +1,5 @@
|
|||
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 { useStore } from '../../../src/session';
|
||||
import { useCard } from '../../../src/useCard';
|
||||
|
|
@ -28,7 +28,6 @@ export default function ClientCard() {
|
|||
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;
|
||||
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 (
|
||||
<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' })}
|
||||
{/* En-tête : initiale, prénom, ancienneté */}
|
||||
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 14 }}>
|
||||
<View style={{ width: 56, height: 56, borderRadius: 28, backgroundColor: c.primarySoft, alignItems: 'center', justifyContent: 'center' }}>
|
||||
<T style={{ fontFamily: font.extrabold, fontSize: 24, color: c.primary }}>{card.firstName.charAt(0).toUpperCase()}</T>
|
||||
</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>
|
||||
</View>
|
||||
</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} »
|
||||
{/* Carte aux couleurs du magasin : solde et progression */}
|
||||
<View style={{ backgroundColor: store.design.backgroundColor, borderRadius: 22, padding: 22, gap: 14 }}>
|
||||
<T style={{ color: fg, opacity: 0.8, fontFamily: font.semibold, fontSize: 13, letterSpacing: 1 }} numberOfLines={1}>
|
||||
{store.design.programName.toUpperCase()}
|
||||
</T>
|
||||
) : null}
|
||||
|
||||
{card.gifts?.map((g) => (
|
||||
<Card key={g.id} style={{ padding: 14, gap: 10, borderColor: c.ok }}>
|
||||
<View style={{ 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' })}
|
||||
<View style={{ flexDirection: 'row', alignItems: 'flex-end', gap: 8 }}>
|
||||
<T v="big" style={{ color: fg }}>{card.balance}</T>
|
||||
<T style={{ color: fg, fontFamily: font.semibold, fontSize: 18, marginBottom: 10 }}>{unit(mode, card.balance)}</T>
|
||||
</View>
|
||||
{target && (
|
||||
<View style={{ gap: 8 }}>
|
||||
<View style={{ height: 8, borderRadius: 4, backgroundColor: fg.length === 7 ? `${fg}40` : 'rgba(127,127,127,0.3)', overflow: 'hidden' }}>
|
||||
<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>
|
||||
</View>
|
||||
<Button label="Marquer comme remis" variant="secondary" loading={giving === g.id} onPress={() => give(g)} />
|
||||
</Card>
|
||||
))}
|
||||
)}
|
||||
</View>
|
||||
|
||||
{card.nextCreditAt && (
|
||||
<Banner tone="warn">
|
||||
|
|
@ -93,6 +103,33 @@ export default function ClientCard() {
|
|||
</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 }} />
|
||||
<Button
|
||||
large
|
||||
|
|
@ -100,12 +137,12 @@ export default function ClientCard() {
|
|||
onPress={() => router.push({ pathname: '/client/[serial]/credit', params: { serial } })}
|
||||
/>
|
||||
<Button
|
||||
label="Utiliser une récompense"
|
||||
label={reachable > 0 ? 'Utiliser une récompense' : 'Voir les récompenses'}
|
||||
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>
|
||||
<T v="muted" style={{ textAlign: 'center', fontSize: 12 }}>Carte {serial}</T>
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { useCallback, useEffect, useState } from 'react';
|
|||
import { ActivityIndicator, FlatList, Pressable, View } from 'react-native';
|
||||
import { api, Operation } from '../src/api';
|
||||
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';
|
||||
|
||||
type Period = 'today' | 'week';
|
||||
|
|
@ -51,81 +51,100 @@ export default function History() {
|
|||
|
||||
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 (
|
||||
<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) => (
|
||||
<Pressable
|
||||
key={p}
|
||||
accessibilityRole="button"
|
||||
accessibilityRole="tab"
|
||||
accessibilityState={{ selected: period === p }}
|
||||
onPress={() => setPeriod(p)}
|
||||
style={{
|
||||
height: 44,
|
||||
paddingHorizontal: 18,
|
||||
borderRadius: 22,
|
||||
justifyContent: 'center',
|
||||
backgroundColor: period === p ? c.primary : c.surface,
|
||||
borderWidth: 1,
|
||||
borderColor: period === p ? c.primary : c.border,
|
||||
}}
|
||||
style={{ flex: 1, paddingVertical: 10, borderRadius: 10, alignItems: 'center', backgroundColor: period === p ? c.primary : 'transparent' }}
|
||||
>
|
||||
<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>
|
||||
))}
|
||||
</View>
|
||||
<T v="muted" style={{ paddingHorizontal: 16, paddingBottom: 8 }}>
|
||||
{isManager ? 'Toutes les opérations du magasin' : 'Vos opérations'}
|
||||
</T>
|
||||
<View style={{ flexDirection: 'row', gap: 10 }}>
|
||||
{[
|
||||
[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>}
|
||||
<FlatList
|
||||
data={items}
|
||||
keyExtractor={(o) => o.id}
|
||||
contentContainerStyle={{ paddingHorizontal: 16, paddingBottom: 32 }}
|
||||
contentContainerStyle={{ paddingHorizontal: 16, paddingBottom: 32, gap: 8 }}
|
||||
onEndReached={() => cursor && !loading && load(false)}
|
||||
onEndReachedThreshold={0.5}
|
||||
bounces={false}
|
||||
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}
|
||||
ItemSeparatorComponent={() => <View style={{ height: 1, backgroundColor: c.border }} />}
|
||||
renderItem={({ item: o }) => {
|
||||
renderItem={({ item: o, index }) => {
|
||||
const rejected = o.type === 'REJECTED';
|
||||
const time = new Date(o.createdAt).toLocaleString('fr-FR', {
|
||||
...(period === 'week' && { weekday: 'short' }),
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
const what =
|
||||
o.type === 'REDEEM'
|
||||
const redeem = o.type === 'REDEEM';
|
||||
const time = new Date(o.createdAt).toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' });
|
||||
// Sur 7 jours : un intertitre à chaque nouveau jour.
|
||||
const newDay = period === 'week' && (index === 0 || dayOf(items[index - 1].createdAt) !== dayOf(o.createdAt));
|
||||
const what = redeem
|
||||
? o.reward?.label ?? 'Récompense'
|
||||
: rejected
|
||||
? REASON[o.rejectReason ?? ''] ?? 'Refusé'
|
||||
: o.amountCents
|
||||
? euros(o.amountCents)
|
||||
: 'Passage';
|
||||
const [iconBg, iconFg, icon] = rejected ? [c.errBg, c.err, '!'] : redeem ? [c.warnBg, c.warn, '★'] : [c.okBg, c.ok, '+'];
|
||||
return (
|
||||
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 12, paddingVertical: 14 }}>
|
||||
<View style={{ width: 54 }}>
|
||||
<T v="muted" style={{ fontSize: 14 }}>{time}</T>
|
||||
<View style={{ gap: 8 }}>
|
||||
{newDay && (
|
||||
<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 style={{ flex: 1, gap: 2 }}>
|
||||
<T v="label" numberOfLines={1}>{o.customerFirstName}</T>
|
||||
<T v="muted" numberOfLines={1} style={{ fontSize: 14, color: rejected ? c.err : c.text3 }}>
|
||||
{what}
|
||||
<T v="muted" numberOfLines={1} style={{ fontSize: 13, color: rejected ? c.err : c.text3 }}>
|
||||
{time} · {what}
|
||||
{isManager ? ` · ${o.staff.displayName}` : ''}
|
||||
</T>
|
||||
</View>
|
||||
<T
|
||||
style={{
|
||||
fontFamily: font.bold,
|
||||
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)}.`}
|
||||
<View style={{ paddingHorizontal: 10, paddingVertical: 4, borderRadius: 999, backgroundColor: rejected ? c.surface2 : o.points > 0 ? c.okBg : c.warnBg }}>
|
||||
<T style={{ fontFamily: font.bold, fontSize: 15, color: rejected ? c.text3 : o.points > 0 ? c.ok : c.warn }}>
|
||||
{rejected ? '—' : `${o.points > 0 ? '+' : '−'}${Math.abs(o.points)}`}
|
||||
</T>
|
||||
</View>
|
||||
</Card>
|
||||
</View>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue