MonEspacePro/pro/app/birthday.tsx
Tony AVERTY 166f7888cd Offre d'anniversaire (formule Pro)
- Anniversaire facultatif (jour + mois) à l'inscription ou sur la page de la carte
- Réglages par magasin : activation, points/tampons offerts, message {prenom} {cadeau}
- Passage horaire 9 h–19 h (Paris), un cadeau par an, 29 février fêté le 28
- Notification Apple (Actualité) et Google, solde mis à jour
- Admin : onglet Fidélisation ; app Pro : écran gérant
- Politique de confidentialité mise à jour
- Migration manuelle 2026-10-07-anniversaire.sql

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 10:33:15 +02:00

120 lines
4.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useCallback, useState } from 'react';
import { Pressable, ScrollView, Switch, TextInput, View } from 'react-native';
import { useFocusEffect } from 'expo-router';
import { api } from '../src/api';
import { describe } from '../src/errors';
import { useStore } from '../src/session';
import { Banner, Button, Card, T, unit } from '../src/ui';
import { font, useColors } from '../src/theme';
interface Birthday {
allowed: boolean;
settings: { enabled: boolean; points: number; message: string | null };
defaultMessage: string;
maxPoints: number;
stats: { cards: number; known: number; giftedThisYear: number };
}
/** Offre d'anniversaire (gérants, formule Pro). */
export default function BirthdayScreen() {
const c = useColors();
const store = useStore();
const [data, setData] = useState<Birthday | null>(null);
const [enabled, setEnabled] = useState(false);
const [points, setPoints] = useState(0);
const [message, setMessage] = useState('');
const [error, setError] = useState<string | null>(null);
const [saved, setSaved] = useState(false);
const [busy, setBusy] = useState(false);
const apply = (d: Birthday) => {
setData(d);
setEnabled(d.settings.enabled);
setPoints(d.settings.points);
setMessage(d.settings.message ?? '');
};
useFocusEffect(
useCallback(() => {
api.get<Birthday>('/api/staff/birthday').then(apply).catch((e) => setError(describe(e).detail));
}, []),
);
async function save() {
setBusy(true);
setError(null);
setSaved(false);
try {
apply(await api.put<Birthday>('/api/staff/birthday', { enabled, points, message: message.trim() || null }));
setSaved(true);
} catch (e) {
setError(describe(e).detail);
} finally {
setBusy(false);
}
}
if (!data) return <View style={{ padding: 20 }}>{error ? <Banner tone="error">{error}</Banner> : <T v="muted">Chargement…</T>}</View>;
const step = (d: number) => setPoints((p) => Math.max(0, Math.min(data.maxPoints, p + d)));
const stepper = (label: string, d: number) => (
<Pressable
accessibilityRole="button"
accessibilityLabel={d > 0 ? 'Plus' : 'Moins'}
onPress={() => step(d)}
style={{ width: 48, height: 48, borderRadius: 24, borderWidth: 1, borderColor: c.border, backgroundColor: c.surface, alignItems: 'center', justifyContent: 'center' }}
>
<T style={{ fontFamily: font.bold, fontSize: 22 }}>{label}</T>
</Pressable>
);
return (
<ScrollView contentContainerStyle={{ padding: 20, gap: 16 }} keyboardShouldPersistTaps="handled">
{error && <Banner tone="error">{error}</Banner>}
{saved && <Banner tone="ok">Réglages enregistrés.</Banner>}
{!data.allowed && <Banner tone="warn">L'offre d'anniversaire est incluse dans la formule Pro. Contactez MonEspacePro pour changer de formule.</Banner>}
<T v="muted">
Vos clients indiquent leur anniversaire à l'inscription ou sur la page de leur carte. Le jour J, ils reçoivent une notification et votre cadeau. Un cadeau par an.
</T>
<Card style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', padding: 16 }}>
<T v="label">Offre d'anniversaire</T>
<Switch value={enabled} onValueChange={setEnabled} disabled={!data.allowed && !enabled} accessibilityLabel="Offre d'anniversaire" />
</Card>
<T v="label">Cadeau</T>
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 16 }}>
{stepper('−', -1)}
<T style={{ fontFamily: font.extrabold, fontSize: 26, minWidth: 40, textAlign: 'center' }}>{points}</T>
{stepper('+', 1)}
<T v="muted" style={{ flex: 1 }}>{points === 0 ? 'message seulement' : `${unit(store.design.pointsMode, points)} offert${points > 1 ? 's' : ''}`}</T>
</View>
<T v="label">Message</T>
<TextInput
value={message}
onChangeText={setMessage}
multiline
maxLength={160}
placeholder={data.defaultMessage}
placeholderTextColor={c.text3}
accessibilityLabel="Message d'anniversaire"
style={{ minHeight: 90, borderWidth: 1, borderColor: c.border, borderRadius: 14, padding: 14, backgroundColor: c.surface, color: c.text, fontFamily: font.regular, fontSize: 16, textAlignVertical: 'top' }}
/>
<T v="muted" style={{ fontSize: 13 }}>Vide = texte par défaut. {'{prenom}'} et {'{cadeau}'} sont remplacés automatiquement.</T>
<Button label="Enregistrer" onPress={save} loading={busy} />
<View style={{ flexDirection: 'row', gap: 12 }}>
{[
[`${data.stats.known}/${data.stats.cards}`, 'anniversaires connus'],
[data.stats.giftedThisYear, 'cadeaux (12 mois)'],
].map(([n, l]) => (
<Card key={String(l)} style={{ flex: 1, padding: 14, gap: 2 }}>
<T style={{ fontFamily: font.extrabold, fontSize: 22 }}>{n}</T>
<T v="muted" style={{ fontSize: 13 }}>{l}</T>
</Card>
))}
</View>
</ScrollView>
);
}