App : page Modules retravaillée
- Liste : pictogramme par module, interrupteur d'activation directe, compteur de modules actifs, section « Non inclus dans votre formule » - Réglages : en-tête avec interrupteur, chiffres du module, champs regroupés (Réglages / Messages), bouton Enregistrer fixé en bas dès qu'une modification est faite Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
53a598080e
commit
98fd599f75
3 changed files with 138 additions and 43 deletions
|
|
@ -1,43 +1,88 @@
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { Pressable, ScrollView, View } from 'react-native';
|
import { Pressable, ScrollView, Switch, View } from 'react-native';
|
||||||
import { router, useFocusEffect } from 'expo-router';
|
import { router, useFocusEffect } from 'expo-router';
|
||||||
import { api } from '../src/api';
|
import { api } from '../src/api';
|
||||||
import { describe } from '../src/errors';
|
import { describe } from '../src/errors';
|
||||||
import { Banner, Card, T } from '../src/ui';
|
import { Banner, Card, T } from '../src/ui';
|
||||||
import { font, useColors } from '../src/theme';
|
import { font, useColors } from '../src/theme';
|
||||||
import type { ModuleInfo } from '../src/modules';
|
import { MODULE_ICON, ModuleInfo } from '../src/modules';
|
||||||
|
|
||||||
/** Modules complémentaires du magasin (dirigeants) : état et accès aux réglages. */
|
/** Modules complémentaires du magasin (dirigeants) : activation directe et accès aux réglages. */
|
||||||
export default function Modules() {
|
export default function Modules() {
|
||||||
const c = useColors();
|
const c = useColors();
|
||||||
const [list, setList] = useState<ModuleInfo[] | null>(null);
|
const [list, setList] = useState<ModuleInfo[] | null>(null);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [switching, setSwitching] = useState<string | null>(null);
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
api.get<ModuleInfo[]>('/api/staff/modules').then(setList).catch((e) => setError(describe(e).detail));
|
api.get<ModuleInfo[]>('/api/staff/modules').then(setList).catch((e) => setError(describe(e).detail));
|
||||||
}, []),
|
}, []),
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
/** Interrupteur de la liste : active ou désactive sans ouvrir les réglages. */
|
||||||
<ScrollView contentContainerStyle={{ padding: 20, gap: 12 }}>
|
async function toggle(m: ModuleInfo, enabled: boolean) {
|
||||||
<T v="muted">Faites revenir vos clients avec des messages sur leur carte Wallet. Chaque module se règle entièrement : textes, délais, heures d'envoi.</T>
|
setSwitching(m.id);
|
||||||
{error && <Banner tone="error">{error}</Banner>}
|
setError(null);
|
||||||
{list?.map((m) => {
|
try {
|
||||||
const state = !m.available ? ['Non inclus', c.text3] : m.config.enabled ? ['Activé', c.ok] : ['Désactivé', c.text3];
|
const next = await api.put<ModuleInfo>(`/api/staff/modules/${m.id}`, { enabled });
|
||||||
return (
|
setList((l) => l?.map((x) => (x.id === m.id ? next : x)) ?? null);
|
||||||
<Pressable key={m.id} accessibilityRole="button" onPress={() => router.push({ pathname: '/module/[id]', params: { id: m.id } })}>
|
} catch (e) {
|
||||||
|
setError(describe(e).detail);
|
||||||
|
} finally {
|
||||||
|
setSwitching(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const available = list?.filter((m) => m.available) ?? [];
|
||||||
|
const locked = list?.filter((m) => !m.available) ?? [];
|
||||||
|
const active = available.filter((m) => m.config.enabled).length;
|
||||||
|
|
||||||
|
const row = (m: ModuleInfo) => (
|
||||||
|
<Pressable key={m.id} accessibilityRole="button" accessibilityLabel={`Réglages ${m.name}`} onPress={() => router.push({ pathname: '/module/[id]', params: { id: m.id } })}>
|
||||||
{({ pressed }) => (
|
{({ pressed }) => (
|
||||||
<Card style={{ padding: 16, gap: 4, opacity: pressed ? 0.7 : 1 }}>
|
<Card style={{ padding: 14, flexDirection: 'row', alignItems: 'center', gap: 14, opacity: pressed ? 0.7 : m.available ? 1 : 0.6 }}>
|
||||||
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
|
<View style={{ width: 48, height: 48, borderRadius: 14, backgroundColor: m.available && m.config.enabled ? c.primarySoft : c.surface2, alignItems: 'center', justifyContent: 'center' }}>
|
||||||
<T style={{ fontFamily: font.bold, fontSize: 17 }}>{m.name}</T>
|
<T style={{ fontSize: 24 }}>{MODULE_ICON[m.id] ?? '🧩'}</T>
|
||||||
<T style={{ fontFamily: font.semibold, fontSize: 13, color: state[1] }}>{state[0]}</T>
|
|
||||||
</View>
|
</View>
|
||||||
<T v="muted" style={{ fontSize: 14 }}>{m.tagline}</T>
|
<View style={{ flex: 1, gap: 2 }}>
|
||||||
|
<T style={{ fontFamily: font.bold, fontSize: 17 }} numberOfLines={1}>{m.name}</T>
|
||||||
|
<T v="muted" style={{ fontSize: 13 }} numberOfLines={2}>{m.tagline}</T>
|
||||||
|
</View>
|
||||||
|
{m.available ? (
|
||||||
|
<Switch
|
||||||
|
value={m.config.enabled}
|
||||||
|
disabled={switching === m.id}
|
||||||
|
onValueChange={(v) => toggle(m, v)}
|
||||||
|
trackColor={{ true: c.primary }}
|
||||||
|
accessibilityLabel={`${m.name} : ${m.config.enabled ? 'activé' : 'désactivé'}`}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<View style={{ paddingHorizontal: 10, paddingVertical: 4, borderRadius: 999, backgroundColor: c.surface2 }}>
|
||||||
|
<T style={{ fontSize: 12, fontFamily: font.semibold, color: c.text3 }}>Non inclus</T>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
);
|
);
|
||||||
})}
|
|
||||||
|
return (
|
||||||
|
<ScrollView contentContainerStyle={{ padding: 20, gap: 12 }} bounces={false} overScrollMode="never">
|
||||||
|
<T v="muted">Activez un module d’un geste ; touchez-le pour régler ses textes, délais et récompenses.</T>
|
||||||
|
{error && <Banner tone="error">{error}</Banner>}
|
||||||
|
{list && (
|
||||||
|
<T v="label" style={{ color: c.text3, marginTop: 4 }}>
|
||||||
|
{active} module{active > 1 ? 's' : ''} actif{active > 1 ? 's' : ''} sur {available.length}
|
||||||
|
</T>
|
||||||
|
)}
|
||||||
|
{available.map(row)}
|
||||||
|
{locked.length > 0 && (
|
||||||
|
<>
|
||||||
|
<T v="label" style={{ color: c.text3, marginTop: 12 }}>Non inclus dans votre formule</T>
|
||||||
|
{locked.map(row)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { Pressable, ScrollView, Switch, TextInput, View } from 'react-native';
|
||||||
import { router, Stack, useFocusEffect, useLocalSearchParams } from 'expo-router';
|
import { router, Stack, useFocusEffect, useLocalSearchParams } from 'expo-router';
|
||||||
import { api } from '../../src/api';
|
import { api } from '../../src/api';
|
||||||
import { describe } from '../../src/errors';
|
import { describe } from '../../src/errors';
|
||||||
import { FieldDef, ModuleInfo, Value } from '../../src/modules';
|
import { FieldDef, isMessageField, MODULE_ICON, ModuleInfo, Value } from '../../src/modules';
|
||||||
import { Banner, Button, Card, T } from '../../src/ui';
|
import { Banner, Button, Card, T } from '../../src/ui';
|
||||||
import { font, useColors } from '../../src/theme';
|
import { font, useColors } from '../../src/theme';
|
||||||
|
|
||||||
|
|
@ -86,6 +86,7 @@ function Field({ f, value, onChange }: { f: FieldDef; value: Value; onChange: (v
|
||||||
|
|
||||||
/** Réglages complets d'un module (dirigeants). */
|
/** Réglages complets d'un module (dirigeants). */
|
||||||
export default function ModuleScreen() {
|
export default function ModuleScreen() {
|
||||||
|
const c = useColors();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>();
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
const [m, setM] = useState<ModuleInfo | null>(null);
|
const [m, setM] = useState<ModuleInfo | null>(null);
|
||||||
const [values, setValues] = useState<Record<string, Value>>({});
|
const [values, setValues] = useState<Record<string, Value>>({});
|
||||||
|
|
@ -120,34 +121,69 @@ export default function ModuleScreen() {
|
||||||
if (!m) return <View style={{ padding: 20 }}>{error ? <Banner tone="error">{error}</Banner> : <T v="muted">Chargement…</T>}</View>;
|
if (!m) return <View style={{ padding: 20 }}>{error ? <Banner tone="error">{error}</Banner> : <T v="muted">Chargement…</T>}</View>;
|
||||||
const dirty = JSON.stringify(values) !== JSON.stringify(m.config);
|
const dirty = JSON.stringify(values) !== JSON.stringify(m.config);
|
||||||
|
|
||||||
return (
|
const settings = m.fields.filter((f) => !isMessageField(f));
|
||||||
<ScrollView contentContainerStyle={{ padding: 20, gap: 16 }} keyboardShouldPersistTaps="handled">
|
const messages = m.fields.filter(isMessageField);
|
||||||
<Stack.Screen options={{ title: m.name }} />
|
const enabled = !!values.enabled;
|
||||||
{error && <Banner tone="error">{error}</Banner>}
|
const section = (title: string, fields: FieldDef[]) =>
|
||||||
{saved && <Banner tone="ok">Réglages enregistrés.</Banner>}
|
fields.length > 0 && (
|
||||||
{!m.available && <Banner tone="warn">Ce module n'est pas inclus dans votre formule. Contactez MonEspacePro pour l'ajouter.</Banner>}
|
<View style={{ gap: 14 }}>
|
||||||
<T v="muted">{m.description}</T>
|
<T v="label" style={{ color: c.text3, textTransform: 'uppercase', fontSize: 13, letterSpacing: 0.5 }}>{title}</T>
|
||||||
|
{fields.map((f) => (
|
||||||
{m.available && m.config.enabled && m.id === 'campaigns' && <Button label="Envoyer une campagne" onPress={() => router.push('/campaigns')} />}
|
|
||||||
{m.available && m.config.enabled && m.id === 'stats' && <Button label="Voir les statistiques" onPress={() => router.push('/stats')} />}
|
|
||||||
|
|
||||||
<Field f={{ key: 'enabled', type: 'boolean', label: 'Module activé', default: false }} value={values.enabled} onChange={(v) => setValues({ ...values, enabled: v })} />
|
|
||||||
{m.fields.map((f) => (
|
|
||||||
<Field key={f.key} f={f} value={values[f.key]} onChange={(v) => setValues({ ...values, [f.key]: v })} />
|
<Field key={f.key} f={f} value={values[f.key]} onChange={(v) => setValues({ ...values, [f.key]: v })} />
|
||||||
))}
|
))}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
<Button label="Enregistrer" onPress={save} loading={busy} disabled={!dirty} />
|
return (
|
||||||
|
<View style={{ flex: 1, backgroundColor: c.bg }}>
|
||||||
|
<Stack.Screen options={{ title: m.name }} />
|
||||||
|
<ScrollView contentContainerStyle={{ padding: 20, gap: 22, paddingBottom: 120 }} keyboardShouldPersistTaps="handled" bounces={false} overScrollMode="never">
|
||||||
|
{/* En-tête : pictogramme, description, interrupteur principal */}
|
||||||
|
<Card style={{ gap: 14 }}>
|
||||||
|
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 14 }}>
|
||||||
|
<View style={{ width: 52, height: 52, borderRadius: 16, backgroundColor: enabled ? c.primarySoft : c.surface2, alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
<T style={{ fontSize: 26 }}>{MODULE_ICON[m.id] ?? '🧩'}</T>
|
||||||
|
</View>
|
||||||
|
<View style={{ flex: 1 }}>
|
||||||
|
<T style={{ fontFamily: font.bold, fontSize: 18 }}>{m.name}</T>
|
||||||
|
<T style={{ fontFamily: font.semibold, fontSize: 13, color: !m.available ? c.text3 : enabled ? c.ok : c.text3 }}>
|
||||||
|
{!m.available ? 'Non inclus dans votre formule' : enabled ? 'Activé' : 'Désactivé'}
|
||||||
|
</T>
|
||||||
|
</View>
|
||||||
|
{m.available && (
|
||||||
|
<Switch value={enabled} onValueChange={(v) => setValues({ ...values, enabled: v })} trackColor={{ true: c.primary }} accessibilityLabel="Module activé" />
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
<T v="muted" style={{ fontSize: 14 }}>{m.description}</T>
|
||||||
|
{m.available && m.config.enabled && m.id === 'campaigns' && <Button label="Envoyer une campagne" onPress={() => router.push('/campaigns')} />}
|
||||||
|
{m.available && m.config.enabled && m.id === 'stats' && <Button label="Voir les statistiques" onPress={() => router.push('/stats')} />}
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{error && <Banner tone="error">{error}</Banner>}
|
||||||
|
{saved && !dirty && <Banner tone="ok">Réglages enregistrés.</Banner>}
|
||||||
|
{!m.available && <Banner tone="warn">Ce module n'est pas inclus dans votre formule. Contactez MonEspacePro pour l'ajouter.</Banner>}
|
||||||
|
|
||||||
{m.stats && (
|
{m.stats && (
|
||||||
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 12 }}>
|
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 10 }}>
|
||||||
{Object.entries(m.stats).map(([k, v]) => (
|
{Object.entries(m.stats).map(([k, v]) => (
|
||||||
<Card key={k} style={{ width: '47%', flexGrow: 1, padding: 14, gap: 2 }}>
|
<View key={k} style={{ width: '47%', flexGrow: 1, padding: 14, gap: 2, borderRadius: 14, backgroundColor: c.primarySoft }}>
|
||||||
<T style={{ fontFamily: font.extrabold, fontSize: 22 }}>{v ?? '—'}</T>
|
<T style={{ fontFamily: font.extrabold, fontSize: 22, color: c.primary }}>{v ?? '—'}</T>
|
||||||
<T v="muted" style={{ fontSize: 13 }}>{k}</T>
|
<T v="muted" style={{ fontSize: 13 }}>{k}</T>
|
||||||
</Card>
|
</View>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{section('Réglages', settings)}
|
||||||
|
{section('Messages', messages)}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
{/* Enregistrer toujours à portée de pouce, visible dès qu'il y a une modification */}
|
||||||
|
{dirty && (
|
||||||
|
<View style={{ position: 'absolute', left: 0, right: 0, bottom: 0, padding: 16, paddingBottom: 28, backgroundColor: c.bg, borderTopWidth: 1, borderTopColor: c.border }}>
|
||||||
|
<Button label="Enregistrer les modifications" onPress={save} loading={busy} />
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,3 +18,17 @@ export interface ModuleInfo {
|
||||||
config: Record<string, Value> & { enabled: boolean };
|
config: Record<string, Value> & { enabled: boolean };
|
||||||
stats?: Record<string, number | string | null> | null;
|
stats?: Record<string, number | string | null> | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Pictogramme et teinte de chaque module (liste et en-tête des réglages). */
|
||||||
|
export const MODULE_ICON: Record<string, string> = {
|
||||||
|
campaigns: '📣',
|
||||||
|
reminders: '⏰',
|
||||||
|
birthday: '🎂',
|
||||||
|
reviews: '⭐',
|
||||||
|
referral: '🤝',
|
||||||
|
stats: '📊',
|
||||||
|
whiteLabel: '🏷️',
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Champs regroupés par section sur l'écran de réglages. */
|
||||||
|
export const isMessageField = (f: FieldDef) => f.type === 'text' || f.type === 'textarea';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue