MonEspacePro/pro/app/loyalty.tsx
Tony AVERTY 98fd599f75 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>
2026-10-07 14:16:38 +02:00

88 lines
3.8 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, View } from 'react-native';
import { router, useFocusEffect } from 'expo-router';
import { api } from '../src/api';
import { describe } from '../src/errors';
import { Banner, Card, T } from '../src/ui';
import { font, useColors } from '../src/theme';
import { MODULE_ICON, ModuleInfo } from '../src/modules';
/** Modules complémentaires du magasin (dirigeants) : activation directe et accès aux réglages. */
export default function Modules() {
const c = useColors();
const [list, setList] = useState<ModuleInfo[] | null>(null);
const [error, setError] = useState<string | null>(null);
const [switching, setSwitching] = useState<string | null>(null);
useFocusEffect(
useCallback(() => {
api.get<ModuleInfo[]>('/api/staff/modules').then(setList).catch((e) => setError(describe(e).detail));
}, []),
);
/** Interrupteur de la liste : active ou désactive sans ouvrir les réglages. */
async function toggle(m: ModuleInfo, enabled: boolean) {
setSwitching(m.id);
setError(null);
try {
const next = await api.put<ModuleInfo>(`/api/staff/modules/${m.id}`, { enabled });
setList((l) => l?.map((x) => (x.id === m.id ? next : x)) ?? null);
} 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 }) => (
<Card style={{ padding: 14, flexDirection: 'row', alignItems: 'center', gap: 14, opacity: pressed ? 0.7 : m.available ? 1 : 0.6 }}>
<View style={{ width: 48, height: 48, borderRadius: 14, backgroundColor: m.available && m.config.enabled ? c.primarySoft : c.surface2, alignItems: 'center', justifyContent: 'center' }}>
<T style={{ fontSize: 24 }}>{MODULE_ICON[m.id] ?? '🧩'}</T>
</View>
<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>
)}
</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>
);
}