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 { Banner, Button, Card, T } from '../src/ui'; import { font, useColors } from '../src/theme'; interface Reminders { allowed: boolean; settings: { enabled: boolean; days: number; message: string | null }; defaultMessage: string; dayChoices: number[]; stats: { pending: number; sentLast30Days: number; cameBack: number; totalReminded: number }; } /** Relance automatique des clients inactifs (gérants, formule Pro). */ export default function RemindersScreen() { const c = useColors(); const [data, setData] = useState(null); const [enabled, setEnabled] = useState(false); const [days, setDays] = useState(45); const [message, setMessage] = useState(''); const [error, setError] = useState(null); const [saved, setSaved] = useState(false); const [busy, setBusy] = useState(false); const apply = (d: Reminders) => { setData(d); setEnabled(d.settings.enabled); setDays(d.settings.days); setMessage(d.settings.message ?? ''); }; useFocusEffect( useCallback(() => { api.get('/api/staff/reminders').then(apply).catch((e) => setError(describe(e).detail)); }, []), ); async function save() { setBusy(true); setError(null); setSaved(false); try { apply(await api.put('/api/staff/reminders', { enabled, days, message: message.trim() || null })); setSaved(true); } catch (e) { setError(describe(e).detail); } finally { setBusy(false); } } if (!data) return {error ? {error} : Chargement…}; const s = data.stats; return ( {error && {error}} {saved && Réglages enregistrés.} {!data.allowed && La relance automatique est incluse dans la formule Pro. Contactez MonEspacePro pour changer de formule.} Un client qui n'est pas revenu depuis le délai choisi reçoit une notification sur sa carte, entre 10 h et 19 h. Une seule relance par absence. Relance automatique Relancer après {data.dayChoices.map((d) => ( setDays(d)} style={{ paddingVertical: 10, paddingHorizontal: 16, borderRadius: 999, borderWidth: 1, borderColor: days === d ? c.primary : c.border, backgroundColor: days === d ? c.primarySoft : c.surface }} > {d} jours ))} Message Vide = texte par défaut. {'{prenom}'} et {'{solde}'} sont remplacés automatiquement.