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(null); const [enabled, setEnabled] = useState(false); const [points, setPoints] = useState(0); const [message, setMessage] = useState(''); const [error, setError] = useState(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('/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('/api/staff/birthday', { enabled, points, message: message.trim() || null })); setSaved(true); } catch (e) { setError(describe(e).detail); } finally { setBusy(false); } } if (!data) return {error ? {error} : Chargement…}; const step = (d: number) => setPoints((p) => Math.max(0, Math.min(data.maxPoints, p + d))); const stepper = (label: string, d: number) => ( 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' }} > {label} ); return ( {error && {error}} {saved && Réglages enregistrés.} {!data.allowed && L'offre d'anniversaire est incluse dans la formule Pro. Contactez MonEspacePro pour changer de formule.} 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. Offre d'anniversaire Cadeau {stepper('−', -1)} {points} {stepper('+', 1)} {points === 0 ? 'message seulement' : `${unit(store.design.pointsMode, points)} offert${points > 1 ? 's' : ''}`} Message Vide = texte par défaut. {'{prenom}'} et {'{cadeau}'} sont remplacés automatiquement.