Récompenses visibles sur l'affichette et sur les cartes

- Affichette A5/A6 : liste des récompenses sous le QR (QR réduit, 4 max en A5, 3 en A6)
- Apple Wallet : « Prochaine récompense » en face avant (notification quand elle devient disponible)
- Google Wallet : prochaine récompense puis liste complète
- Page web de la carte : toutes les récompenses avec barre de progression
- Page d'inscription : jusqu'à 4 récompenses annoncées
- Aperçu Wallet de l'admin aligné

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tony AVERTY 2026-10-07 09:37:47 +02:00
parent 9476da24cb
commit bc55f7148d
8 changed files with 136 additions and 11 deletions

View file

@ -12,16 +12,24 @@ export interface PosterProps {
backgroundColor: string;
foregroundColor: string;
labelColor: string;
/** Récompenses actives, de la moins chère à la plus chère. */
rewards?: { label: string; cost: number; active?: boolean }[];
pointsMode?: 'AMOUNT' | 'STAMP';
}
/** Dimensions en mm (impression) et tailles de texte, d'après la maquette « Affichette comptoir ». */
const SIZES = {
A5: { w: 148, h: 210, pad: 12, logo: 14, store: 6, eyebrow: 3.8, title: 10, qr: 66, body: 4.5, small: 4 },
A6: { w: 105, h: 148, pad: 8, logo: 10, store: 4.5, eyebrow: 3, title: 7, qr: 46, body: 3.4, small: 3.1 },
A5: { w: 148, h: 210, pad: 12, logo: 14, store: 6, eyebrow: 3.8, title: 10, qr: 66, qrWithRewards: 50, body: 4.5, small: 4, maxRewards: 4 },
A6: { w: 105, h: 148, pad: 8, logo: 10, store: 4.5, eyebrow: 3, title: 7, qr: 46, qrWithRewards: 34, body: 3.4, small: 3.1, maxRewards: 3 },
};
export function Poster(p: PosterProps) {
const s = SIZES[p.format];
const rewards = (p.rewards ?? []).filter((r) => r.active !== false && r.label.trim()).sort((a, b) => a.cost - b.cost);
const shown = rewards.slice(0, s.maxRewards);
const unit = p.pointsMode === 'STAMP' ? 'tampons' : 'points';
// Le QR rétrécit pour laisser la place aux récompenses (reste au-dessus de 3 cm, lisible à bout de bras).
const qrSize = shown.length ? s.qrWithRewards : s.qr;
const [svg, setSvg] = useState('');
useEffect(() => {
@ -64,9 +72,42 @@ export function Poster(p: PosterProps) {
<div
role="img"
aria-label="QR code d'inscription"
style={{ background: '#fff', borderRadius: mm(3.5), padding: mm(4), width: mm(s.qr), height: mm(s.qr), boxSizing: 'content-box' }}
style={{ background: '#fff', borderRadius: mm(3.5), padding: mm(4), width: mm(qrSize), height: mm(qrSize), boxSizing: 'content-box' }}
dangerouslySetInnerHTML={{ __html: svg }}
/>
{shown.length > 0 && (
<div style={{ width: '100%', display: 'flex', flexDirection: 'column', gap: mm(1.6) }}>
<span style={{ fontSize: mm(s.small), fontWeight: 700, letterSpacing: '0.1em', textTransform: 'uppercase', color: p.labelColor }}>
Vos récompenses
</span>
<ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: mm(1.2) }}>
{shown.map((r) => (
<li
key={`${r.label}-${r.cost}`}
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'baseline',
gap: mm(3),
padding: `${mm(1.4)} ${mm(3)}`,
borderRadius: mm(2.5),
background: 'rgba(255,255,255,0.12)',
fontSize: mm(s.body),
lineHeight: 1.25,
}}
>
<span style={{ fontWeight: 700, textAlign: 'left' }}>{r.label}</span>
<span style={{ whiteSpace: 'nowrap', color: p.labelColor, fontWeight: 600 }}>
{r.cost} {unit}
</span>
</li>
))}
</ul>
{rewards.length > shown.length && (
<span style={{ fontSize: mm(s.small), color: p.labelColor }}>et {rewards.length - shown.length} autre(s) à découvrir sur votre carte</span>
)}
</div>
)}
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: mm(1.5) }}>
<span style={{ fontSize: mm(s.body), lineHeight: 1.4, fontWeight: 600 }}>Ajoutez-la à Apple Wallet ou Google Wallet.</span>
<span style={{ fontSize: mm(s.small), lineHeight: 1.4, color: p.labelColor }}>Gratuit, sans application à télécharger.</span>

View file

@ -1,6 +1,6 @@
import { CardDesign } from '../api';
export type PreviewDesign = Omit<CardDesign, 'rewards'> & { storeName: string };
export type PreviewDesign = Omit<CardDesign, 'rewards'> & { storeName: string; rewards?: CardDesign['rewards'] };
/** QR factice (motif fixe) : l'aperçu ne doit pas laisser croire à un vrai code. */
function FakeQr({ size }: { size: number }) {
@ -34,6 +34,17 @@ function balanceLabel(d: PreviewDesign) {
return d.pointsMode === 'STAMP' ? { label: 'TAMPONS', value: '7' } : { label: 'POINTS', value: '120' };
}
/** Même règle que l'API (wallet.types.ts) appliquée au solde fictif de l'aperçu. */
function nextReward(d: PreviewDesign): string | null {
const balance = d.pointsMode === 'STAMP' ? 7 : 120;
const rewards = (d.rewards ?? []).filter((r) => r.active !== false && r.label.trim()).sort((a, b) => a.cost - b.cost);
if (!rewards.length) return null;
const reachable = rewards.filter((r) => r.cost <= balance);
if (reachable.length) return `${reachable[reachable.length - 1].label} : disponible !`;
const missing = rewards[0].cost - balance;
return `${rewards[0].label} : encore ${missing} ${d.pointsMode === 'STAMP' ? 'tampon' : 'point'}${missing > 1 ? 's' : ''}`;
}
/** Approximation fidèle du gabarit Apple « Store Card » (logo, bandeau 1125×432, champ principal, QR). */
export function ApplePreview({ d }: { d: PreviewDesign }) {
const b = balanceLabel(d);
@ -66,6 +77,12 @@ export function ApplePreview({ d }: { d: PreviewDesign }) {
<div style={{ fontSize: 14 }}>Camille</div>
</div>
</div>
{nextReward(d) && (
<div style={{ padding: '0 14px 6px' }}>
<div style={{ fontSize: 10, fontWeight: 600, color: d.labelColor }}>PROCHAINE RÉCOMPENSE</div>
<div style={{ fontSize: 14 }}>{nextReward(d)}</div>
</div>
)}
<div style={{ display: 'flex', justifyContent: 'center', padding: '14px 0 20px' }}>
<div style={{ background: '#fff', padding: 8, borderRadius: 6 }}>
<FakeQr size={120} />
@ -97,6 +114,12 @@ export function GooglePreview({ d }: { d: PreviewDesign }) {
<div style={{ fontSize: 18 }}>Camille</div>
</div>
</div>
{nextReward(d) && (
<div style={{ padding: '0 16px 12px' }}>
<div style={{ fontSize: 11, opacity: 0.8 }}>Prochaine récompense</div>
<div style={{ fontSize: 15 }}>{nextReward(d)}</div>
</div>
)}
<div style={{ display: 'flex', justifyContent: 'center', padding: '8px 0 16px' }}>
<div style={{ background: '#fff', padding: 10, borderRadius: 12 }}>
<FakeQr size={120} />

View file

@ -246,6 +246,8 @@ export function CardWizard({ store, onSaved }: { store: StoreDetail; onSaved: ()
backgroundColor={draft.backgroundColor}
foregroundColor={draft.foregroundColor}
labelColor={draft.labelColor}
rewards={draft.rewards}
pointsMode={draft.pointsMode}
/>
</div>
</div>

View file

@ -52,6 +52,8 @@ export function PosterPage() {
backgroundColor={design.backgroundColor}
foregroundColor={design.foregroundColor}
labelColor={design.labelColor}
rewards={design.rewards}
pointsMode={design.pointsMode}
/>
</div>
<p className="no-print muted" style={{ textAlign: 'center' }}>{store.enrollUrl}</p>

View file

@ -1,5 +1,5 @@
import type { CardDesign, Reward, Store } from '@prisma/client';
import type { CardWithContext } from '../wallet/wallet.types';
import { nextRewardText, type CardWithContext } from '../wallet/wallet.types';
/** Pages publiques (clients finaux), rendues côté serveur aux couleurs du magasin. */
@ -102,6 +102,15 @@ input:focus{outline:2px solid var(--brand);outline-offset:1px}
.pass .row{display:flex;justify-content:space-between;padding:10px 14px 14px}
.pass .qr{background:#fff;margin:0 auto 18px;width:200px;padding:12px;border-radius:12px}
.pass .qr svg{display:block;width:100%;height:auto}
.rws{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px}
.rw{background:var(--surface);border:1px solid var(--border);border-radius:14px;padding:12px 14px;display:flex;flex-direction:column;gap:6px}
.rw.ok{border-color:var(--brand);border-width:2px}
.rw-h{display:flex;justify-content:space-between;gap:12px;align-items:baseline}
.rw-h span{font-size:14px;color:var(--muted);white-space:nowrap}
.rw.ok .rw-h span{color:var(--ok);font-weight:700}
.rw-bar{height:8px;border-radius:999px;background:var(--border);overflow:hidden}
.rw-bar i{display:block;height:100%;background:var(--brand);border-radius:999px}
.rw small{font-size:13px;color:var(--muted)}
footer{padding:20px;display:flex;flex-direction:column;align-items:center;gap:10px;font-size:13px;color:var(--muted)}
footer nav{display:flex;gap:16px}
footer .powered{display:inline-flex;align-items:center;gap:6px;font-size:12px;text-decoration:none}
@ -136,10 +145,12 @@ function promises(store: StoreWithDesign) {
? 'Gagnez 1 point par euro dépensé'
: `Gagnez ${Number(d.pointsPerEuro).toLocaleString('fr-FR')} points par euro dépensé`;
const unit = d.pointsMode === 'STAMP' ? 'tampons' : 'points';
const reward = d.rewards[0];
const shown = d.rewards.slice(0, 4);
const more = d.rewards.length - shown.length;
return `<div class="promises">
<div><span class="dot"></span><span>${e(rule)}</span></div>
${reward ? `<div><span class="dot"></span><span>${e(reward.label)} à ${reward.cost} ${unit}</span></div>` : ''}
${shown.map((r) => `<div><span class="dot"></span><span>${e(r.label)} à ${r.cost} ${unit}</span></div>`).join('\n')}
${more > 0 ? `<div class="hint">et ${more} autre${more > 1 ? 's' : ''} récompense${more > 1 ? 's' : ''} à découvrir</div>` : ''}
</div>`;
}
@ -228,6 +239,27 @@ export function unavailablePage(store: StoreWithDesign) {
);
}
/** Liste des récompenses avec la progression du client (barre + « encore N »). */
function rewardsList(rewards: Reward[], balance: number, stamp: boolean) {
if (!rewards.length) return '';
const unit = (n: number) => (stamp ? (n > 1 ? 'tampons' : 'tampon') : n > 1 ? 'points' : 'point');
const items = rewards
.map((r) => {
const ok = balance >= r.cost;
const pct = Math.min(100, Math.round((balance / r.cost) * 100));
return `<li class="rw${ok ? ' ok' : ''}">
<div class="rw-h"><strong>${e(r.label)}</strong><span>${ok ? 'Disponible' : `encore ${r.cost - balance} ${unit(r.cost - balance)}`}</span></div>
<div class="rw-bar" role="progressbar" aria-valuemin="0" aria-valuemax="${r.cost}" aria-valuenow="${Math.min(balance, r.cost)}" aria-label="${e(r.label)}"><i style="width:${pct}%"></i></div>
<small>${r.cost} ${unit(r.cost)}</small>
</li>`;
})
.join('');
return `<section aria-labelledby="rw-title" style="display:flex;flex-direction:column;gap:10px">
<h2 id="rw-title" style="margin:0;font-size:20px">Vos récompenses</h2>
<ul class="rws">${items}</ul>
</section>`;
}
export function cardPage(
card: CardWithContext,
opts: { platform: Platform; isNew: boolean; apple: boolean; google: boolean; qrSvg: string },
@ -261,10 +293,11 @@ export function cardPage(
<div class="pass" aria-label="Aperçu de votre carte">
<div class="top">${t.logo ? `<img src="${e(t.logo)}" alt="">` : ''}<span>${e(d.programName)}</span></div>
<div class="band">${t.strip ? `<img src="${e(t.strip)}" alt="">` : ''}<div class="bal"><div class="lbl">${unit}</div><div class="big">${card.balance}</div></div></div>
<div class="row"><div><div class="lbl">Membre</div>${e(card.customer.firstName)}</div><div style="text-align:right"><div class="lbl">Récompense</div>${e(d.rewards[0]?.label ?? '—')}</div></div>
<div class="row"><div><div class="lbl">Membre</div>${e(card.customer.firstName)}</div><div style="text-align:right;max-width:60%"><div class="lbl">Prochaine récompense</div>${e(nextRewardText(card) ?? '—')}</div></div>
<div class="qr" role="img" aria-label="QR code de votre carte, à présenter au comptoir">${opts.qrSvg}</div>
</div>
<p class="hint" style="text-align:center">Présentez ce QR code au comptoir à chaque passage.</p>
${rewardsList(d.rewards, card.balance, d.pointsMode === 'STAMP')}
<div style="display:flex;flex-direction:column;gap:12px;align-items:stretch">
${buttons}
${

View file

@ -5,7 +5,7 @@ import { join } from 'path';
import { Jimp } from 'jimp';
import { PKPass } from 'passkit-generator';
import { UPLOADS_DIR } from '../card-design/card-design.service';
import { CardWithContext, rewardsText, unitLabel } from './wallet.types';
import { CardWithContext, nextRewardText, rewardsText, unitLabel } from './wallet.types';
type Certificates = { wwdr: Buffer; signerCert: Buffer; signerKey: Buffer; signerKeyPassphrase?: string };
@ -38,6 +38,7 @@ export class ApplePassService {
if (!design) throw new ServiceUnavailableException('Carte non conçue');
const unit = unitLabel(card);
const nextReward = nextRewardText(card);
const passJson = {
formatVersion: 1,
passTypeIdentifier: this.config.get('apple.passTypeId'),
@ -58,6 +59,10 @@ export class ApplePassService {
{ key: 'program', label: 'PROGRAMME', value: design.programName },
{ key: 'member', label: 'MEMBRE', value: card.customer.firstName, textAlignment: 'PKTextAlignmentRight' },
],
// Face avant : la prochaine récompense ; la notification s'affiche quand elle devient disponible.
...(nextReward && {
auxiliaryFields: [{ key: 'next-reward', label: 'PROCHAINE RÉCOMPENSE', value: nextReward, changeMessage: '%@' }],
}),
backFields: [
{ key: 'rewards', label: 'Récompenses', value: rewardsText(card) },
{

View file

@ -2,7 +2,7 @@ import { Injectable, Logger, ServiceUnavailableException } from '@nestjs/common'
import { ConfigService } from '@nestjs/config';
import { readFileSync } from 'fs';
import { importPKCS8, SignJWT } from 'jose';
import { CardWithContext, rewardsText, unitLabel } from './wallet.types';
import { CardWithContext, nextRewardText, rewardsText, unitLabel } from './wallet.types';
type ServiceAccount = { client_email: string; private_key: string };
@ -71,7 +71,10 @@ export class GoogleWalletService {
accountName: card.customer.firstName,
loyaltyPoints: { label: unitLabel(card), balance: { int: card.balance } },
barcode: { type: 'QR_CODE', value: card.serial },
textModulesData: [{ id: 'rewards', header: 'Récompenses', body: rewardsText(card) }],
textModulesData: [
...(nextRewardText(card) ? [{ id: 'next_reward', header: 'Prochaine récompense', body: nextRewardText(card)! }] : []),
{ id: 'rewards', header: 'Toutes les récompenses', body: rewardsText(card) },
],
linksModuleData: {
uris: [{ id: 'manage', uri: `${webUrl}/carte/${card.serial}?k=${card.accessKey}`, description: 'Ma carte' }],
},

View file

@ -14,6 +14,22 @@ export function unitLabel(card: CardWithContext, plural = true) {
return stamp ? 'Tampons' : 'Points';
}
/**
* Prochaine récompense pour la face avant de la carte :
* « Café offert : encore 3 tampons », ou « Café offert : disponible ! »
* si le client peut déjà l'obtenir (la plus chère accessible).
*/
export function nextRewardText(card: CardWithContext): string | null {
const rewards = card.store.cardDesign?.rewards ?? [];
if (!rewards.length) return null;
const stamp = card.store.cardDesign?.pointsMode === 'STAMP';
const reachable = rewards.filter((r) => r.cost <= card.balance);
if (reachable.length) return `${reachable[reachable.length - 1].label} : disponible !`;
const next = rewards[0];
const missing = next.cost - card.balance;
return `${next.label} : encore ${missing} ${stamp ? (missing > 1 ? 'tampons' : 'tampon') : missing > 1 ? 'points' : 'point'}`;
}
export function rewardsText(card: CardWithContext) {
const unit = card.store.cardDesign?.pointsMode === 'STAMP' ? 'tampons' : 'points';
const rewards = card.store.cardDesign?.rewards ?? [];