- Réglages par magasin : activation, délai (30/45/60/90 j), message avec {prenom} et {solde}
- Passage horaire entre 10 h et 19 h (Paris), une relance par période d'inactivité
- Apple : rubrique « Actualité » personnalisée ; Google : message sur la carte du client
- Admin : carte Relance dans l'onglet Campagnes et relances ; app Pro : écran gérant
- Statistiques : à relancer, relances sur 30 j, clients revenus
- Migration manuelle 2026-10-07-relance-inactifs.sql
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
4.6 KiB
TypeScript
116 lines
4.6 KiB
TypeScript
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<Reminders | null>(null);
|
|
const [enabled, setEnabled] = useState(false);
|
|
const [days, setDays] = useState(45);
|
|
const [message, setMessage] = useState('');
|
|
const [error, setError] = useState<string | null>(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<Reminders>('/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<Reminders>('/api/staff/reminders', { enabled, days, 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 s = data.stats;
|
|
|
|
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">La relance automatique est incluse dans la formule Pro. Contactez MonEspacePro pour changer de formule.</Banner>}
|
|
|
|
<T v="muted">
|
|
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.
|
|
</T>
|
|
|
|
<Card style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', padding: 16 }}>
|
|
<T v="label">Relance automatique</T>
|
|
<Switch value={enabled} onValueChange={setEnabled} disabled={!data.allowed && !enabled} accessibilityLabel="Relance automatique" />
|
|
</Card>
|
|
|
|
<T v="label">Relancer après</T>
|
|
<View style={{ flexDirection: 'row', gap: 8, flexWrap: 'wrap' }}>
|
|
{data.dayChoices.map((d) => (
|
|
<Pressable
|
|
key={d}
|
|
accessibilityRole="button"
|
|
accessibilityState={{ selected: days === d }}
|
|
onPress={() => 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 }}
|
|
>
|
|
<T style={{ fontFamily: font.semibold, color: days === d ? c.primary : c.text }}>{d} jours</T>
|
|
</Pressable>
|
|
))}
|
|
</View>
|
|
|
|
<T v="label">Message</T>
|
|
<TextInput
|
|
value={message}
|
|
onChangeText={setMessage}
|
|
multiline
|
|
maxLength={160}
|
|
placeholder={data.defaultMessage}
|
|
placeholderTextColor={c.text3}
|
|
accessibilityLabel="Message de relance"
|
|
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 {'{solde}'} sont remplacés automatiquement.</T>
|
|
|
|
<Button label="Enregistrer" onPress={save} loading={busy} />
|
|
|
|
<View style={{ flexDirection: 'row', gap: 12 }}>
|
|
{[
|
|
[s.pending, 'à relancer'],
|
|
[s.sentLast30Days, 'relances (30 j)'],
|
|
[`${s.cameBack}/${s.totalReminded}`, 'revenus'],
|
|
].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>
|
|
);
|
|
}
|