App Pro : animations fluides (feuille de recherche client animée, bandeaux, formulaires, onglets, listes), navigation allégée (freezeOnBlur) ; script de création du magasin de démonstration
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6506055ae3
commit
1095c6a427
12 changed files with 222 additions and 51 deletions
104
backend/scripts/create-demo-store.ts
Normal file
104
backend/scripts/create-demo-store.ts
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
import * as argon2 from 'argon2';
|
||||||
|
import { randomBytes } from 'crypto';
|
||||||
|
import { createTransport } from 'nodemailer';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crée le magasin de démonstration pour App Review (Apple) : actif d'emblée, formule Pro,
|
||||||
|
* sans Stripe ni lien de paiement, abonnement valable 3 mois, dirigeant avec mot de passe aléatoire.
|
||||||
|
* Le mot de passe est envoyé par e-mail à NOTIFY_EMAIL (affiché ici si SMTP n'est pas configuré).
|
||||||
|
*
|
||||||
|
* Usage : npx ts-node scripts/create-demo-store.ts
|
||||||
|
* (le hachage argon2 ne peut pas être produit en SQL pur, d'où ce script plutôt qu'un .sql)
|
||||||
|
*/
|
||||||
|
const STAFF_EMAIL = 'demo.apple@gmail.com';
|
||||||
|
const NOTIFY_EMAIL = 'tony.prive35@gmail.com';
|
||||||
|
const SERIAL_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
||||||
|
const token = () => randomBytes(24).toString('base64url');
|
||||||
|
const serial = () => 'MEP' + [...randomBytes(8)].map((b) => SERIAL_ALPHABET[b % SERIAL_ALPHABET.length]).join('');
|
||||||
|
const password = () => [...randomBytes(16)].map((b) => SERIAL_ALPHABET[b % SERIAL_ALPHABET.length]).join('').replace(/(.{4})(?=.)/g, '$1-');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
try {
|
||||||
|
process.loadEnvFile();
|
||||||
|
} catch {
|
||||||
|
/* variables déjà dans l'environnement */
|
||||||
|
}
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
if (await prisma.staffUser.findUnique({ where: { email: STAFF_EMAIL } })) {
|
||||||
|
throw new Error(`${STAFF_EMAIL} existe déjà : rien créé.`);
|
||||||
|
}
|
||||||
|
const pwd = password();
|
||||||
|
const periodEnd = new Date();
|
||||||
|
periodEnd.setMonth(periodEnd.getMonth() + 3);
|
||||||
|
|
||||||
|
const store = await prisma.store.create({
|
||||||
|
data: {
|
||||||
|
slug: 'cafe-demo-' + randomBytes(2).toString('hex'),
|
||||||
|
name: 'Café Démo',
|
||||||
|
addressLine: '1 rue de la Démo',
|
||||||
|
postalCode: '35000',
|
||||||
|
city: 'Rennes',
|
||||||
|
siret: '35600000000048',
|
||||||
|
contactName: 'Tony Averty',
|
||||||
|
contactEmail: STAFF_EMAIL,
|
||||||
|
contactPhone: '0612345678',
|
||||||
|
status: 'ACTIVE',
|
||||||
|
maxAmountCents: 50000,
|
||||||
|
minScanIntervalSec: 300,
|
||||||
|
subscription: {
|
||||||
|
create: { status: 'ACTIVE', plan: 'PRO', interval: 'MONTH', currentPeriodEnd: periodEnd },
|
||||||
|
},
|
||||||
|
cardDesign: {
|
||||||
|
create: {
|
||||||
|
programName: 'Carte Café Démo',
|
||||||
|
pointsMode: 'STAMP',
|
||||||
|
backgroundColor: '#0E7A66',
|
||||||
|
rewards: { create: [{ label: 'Un café offert', cost: 10 }] },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
staff: {
|
||||||
|
create: {
|
||||||
|
email: STAFF_EMAIL,
|
||||||
|
displayName: 'Tony Averty',
|
||||||
|
role: 'MANAGER',
|
||||||
|
passwordHash: await argon2.hash(pwd),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const customer = await prisma.customer.create({
|
||||||
|
data: { firstName: 'Camille', email: 'camille.demo@example.com', consentAt: new Date() },
|
||||||
|
});
|
||||||
|
const card = await prisma.loyaltyCard.create({
|
||||||
|
data: { storeId: store.id, customerId: customer.id, serial: serial(), authToken: token(), accessKey: token() },
|
||||||
|
});
|
||||||
|
|
||||||
|
const summary = [
|
||||||
|
`Magasin : ${store.name} (${store.id}), actif, formule Pro, valable jusqu'au ${periodEnd.toLocaleDateString('fr-FR')}`,
|
||||||
|
`Connexion app : ${STAFF_EMAIL}`,
|
||||||
|
`Client de démo : Camille — carte ${card.serial.replace(/(.{4})/g, '$1 ').trim()}`,
|
||||||
|
`Mot de passe : ${pwd}`,
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
|
if (process.env.SMTP_HOST) {
|
||||||
|
const transport = createTransport({
|
||||||
|
host: process.env.SMTP_HOST,
|
||||||
|
port: Number(process.env.SMTP_PORT ?? 587),
|
||||||
|
secure: Number(process.env.SMTP_PORT) === 465,
|
||||||
|
auth: process.env.SMTP_USER ? { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS } : undefined,
|
||||||
|
});
|
||||||
|
await transport.sendMail({
|
||||||
|
from: process.env.MAIL_FROM,
|
||||||
|
to: NOTIFY_EMAIL,
|
||||||
|
subject: 'Compte de démonstration App Review',
|
||||||
|
text: summary,
|
||||||
|
});
|
||||||
|
console.log(summary.replace(/Mot de passe : .*/, 'Mot de passe : envoyé par e-mail à ' + NOTIFY_EMAIL));
|
||||||
|
} else {
|
||||||
|
console.log('SMTP non configuré — voici le récapitulatif (à noter) :\n' + summary);
|
||||||
|
}
|
||||||
|
await prisma.$disconnect();
|
||||||
|
}
|
||||||
|
main();
|
||||||
|
|
@ -37,6 +37,8 @@ function Navigator() {
|
||||||
headerTitleStyle: { fontFamily: font.bold },
|
headerTitleStyle: { fontFamily: font.bold },
|
||||||
headerBackButtonDisplayMode: 'minimal',
|
headerBackButtonDisplayMode: 'minimal',
|
||||||
contentStyle: { backgroundColor: c.bg },
|
contentStyle: { backgroundColor: c.bg },
|
||||||
|
// Les écrans masqués par une transition ne se re-rendent plus : navigation plus fluide.
|
||||||
|
freezeOnBlur: true,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Stack.Protected guard={!signedIn}>
|
<Stack.Protected guard={!signedIn}>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { Alert, Pressable, ScrollView, Switch, TextInput, View } from 'react-nat
|
||||||
import { api, ApiError } from '../src/api';
|
import { api, ApiError } from '../src/api';
|
||||||
import { describe } from '../src/errors';
|
import { describe } from '../src/errors';
|
||||||
import { useSession } from '../src/session';
|
import { useSession } from '../src/session';
|
||||||
import { Banner, Button, Card, T } from '../src/ui';
|
import { smooth, Banner, Button, Card, T } from '../src/ui';
|
||||||
import { font, useColors } from '../src/theme';
|
import { font, useColors } from '../src/theme';
|
||||||
import { useScanSound } from '../src/prefs';
|
import { useScanSound } from '../src/prefs';
|
||||||
import { confirmIdentity } from '../src/biometrics';
|
import { confirmIdentity } from '../src/biometrics';
|
||||||
|
|
@ -27,6 +27,7 @@ export default function Account() {
|
||||||
await api.post('/api/staff/password', { current, next });
|
await api.post('/api/staff/password', { current, next });
|
||||||
setCurrent('');
|
setCurrent('');
|
||||||
setNext('');
|
setNext('');
|
||||||
|
smooth();
|
||||||
setDone(true);
|
setDone(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(describe(e).detail);
|
setError(describe(e).detail);
|
||||||
|
|
@ -82,6 +83,7 @@ export default function Account() {
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
await api.post('/api/staff/me/deletion-request');
|
await api.post('/api/staff/me/deletion-request');
|
||||||
|
smooth();
|
||||||
setRequested(true);
|
setRequested(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(describe(e).detail);
|
setError(describe(e).detail);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { 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 { useStore } from '../src/session';
|
import { useStore } from '../src/session';
|
||||||
import { Banner, Button, Card, T } from '../src/ui';
|
import { smooth, Banner, Button, Card, T } from '../src/ui';
|
||||||
import { font, useColors } from '../src/theme';
|
import { font, useColors } from '../src/theme';
|
||||||
import { Icon } from '../src/icons';
|
import { Icon } from '../src/icons';
|
||||||
import { confirmIdentity } from '../src/biometrics';
|
import { confirmIdentity } from '../src/biometrics';
|
||||||
|
|
@ -35,7 +35,9 @@ export default function Campaigns() {
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
setData(await api.get<Overview>('/api/staff/campaigns'));
|
const next = await api.get<Overview>('/api/staff/campaigns');
|
||||||
|
smooth();
|
||||||
|
setData(next);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(describe(e).detail);
|
setError(describe(e).detail);
|
||||||
}
|
}
|
||||||
|
|
@ -61,6 +63,7 @@ export default function Campaigns() {
|
||||||
try {
|
try {
|
||||||
await api.post('/api/staff/campaigns', { message: text, title: (title ?? data!.defaultTitle).trim() });
|
await api.post('/api/staff/campaigns', { message: text, title: (title ?? data!.defaultTitle).trim() });
|
||||||
setMessage('');
|
setMessage('');
|
||||||
|
smooth();
|
||||||
setSent(true);
|
setSent(true);
|
||||||
await load();
|
await load();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { SafeAreaView } from 'react-native-safe-area-context';
|
||||||
import Svg, { Path } from 'react-native-svg';
|
import Svg, { Path } from 'react-native-svg';
|
||||||
import { api, API_URL, Summary } from '../src/api';
|
import { api, API_URL, Summary } from '../src/api';
|
||||||
import { useSession, useStore } from '../src/session';
|
import { useSession, useStore } from '../src/session';
|
||||||
import { BrandSymbol, Button, Card, T, unit } from '../src/ui';
|
import { smooth, BrandSymbol, Button, Card, T, unit } from '../src/ui';
|
||||||
import { font, useColors } from '../src/theme';
|
import { font, useColors } from '../src/theme';
|
||||||
import { Icon, IconName } from '../src/icons';
|
import { Icon, IconName } from '../src/icons';
|
||||||
|
|
||||||
|
|
@ -155,7 +155,7 @@ function Counter() {
|
||||||
key={k}
|
key={k}
|
||||||
accessibilityRole="tab"
|
accessibilityRole="tab"
|
||||||
accessibilityState={{ selected: tab === k }}
|
accessibilityState={{ selected: tab === k }}
|
||||||
onPress={() => setTab(k)}
|
onPress={() => { smooth(); setTab(k); }}
|
||||||
style={{ flex: 1, paddingVertical: 10, borderRadius: 10, alignItems: 'center', backgroundColor: tab === k ? c.primary : 'transparent' }}
|
style={{ flex: 1, paddingVertical: 10, borderRadius: 10, alignItems: 'center', backgroundColor: tab === k ? c.primary : 'transparent' }}
|
||||||
>
|
>
|
||||||
<T style={{ fontFamily: font.bold, fontSize: 15, color: tab === k ? c.onPrimary : c.text }}>{label}</T>
|
<T style={{ fontFamily: font.bold, fontSize: 15, color: tab === k ? c.onPrimary : c.text }}>{label}</T>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { SafeAreaView } from 'react-native-safe-area-context';
|
||||||
import { useSession } from '../src/session';
|
import { useSession } from '../src/session';
|
||||||
import { api } from '../src/api';
|
import { api } from '../src/api';
|
||||||
import { describe } from '../src/errors';
|
import { describe } from '../src/errors';
|
||||||
import { Banner, BrandSymbol, Button, Card, T } from '../src/ui';
|
import { smooth, Banner, BrandSymbol, Button, Card, T } from '../src/ui';
|
||||||
import { font, useColors } from '../src/theme';
|
import { font, useColors } from '../src/theme';
|
||||||
|
|
||||||
/** Connexion (Dirigeant et employés) : mêmes identifiants que l'espace web. */
|
/** Connexion (Dirigeant et employés) : mêmes identifiants que l'espace web. */
|
||||||
|
|
@ -27,6 +27,7 @@ export default function Login() {
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
await api.postPublic('/api/public/mot-de-passe/oubli', { email: email.trim() });
|
await api.postPublic('/api/public/mot-de-passe/oubli', { email: email.trim() });
|
||||||
|
smooth();
|
||||||
setForgotDone(true);
|
setForgotDone(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(describe(e).detail);
|
setError(describe(e).detail);
|
||||||
|
|
@ -118,7 +119,7 @@ export default function Login() {
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<Button large label="Se connecter" onPress={submit} loading={busy} disabled={!email || !password} />
|
<Button large label="Se connecter" onPress={submit} loading={busy} disabled={!email || !password} />
|
||||||
<Pressable accessibilityRole="button" hitSlop={8} onPress={() => { setForgot(!forgot); setForgotDone(false); }} style={{ alignSelf: 'center', paddingVertical: 4 }}>
|
<Pressable accessibilityRole="button" hitSlop={8} onPress={() => { smooth(); setForgot(!forgot); setForgotDone(false); }} style={{ alignSelf: 'center', paddingVertical: 4 }}>
|
||||||
<T style={{ color: c.primary, fontFamily: font.semibold, fontSize: 15 }}>Mot de passe oublié ?</T>
|
<T style={{ color: c.primary, fontFamily: font.semibold, fontSize: 15 }}>Mot de passe oublié ?</T>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
{forgot &&
|
{forgot &&
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ 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 { smooth, Banner, Card, T } from '../src/ui';
|
||||||
import { font, useColors } from '../src/theme';
|
import { font, useColors } from '../src/theme';
|
||||||
import { MODULE_ICON, ModuleInfo } from '../src/modules';
|
import { MODULE_ICON, ModuleInfo } from '../src/modules';
|
||||||
import { Icon } from '../src/icons';
|
import { Icon } from '../src/icons';
|
||||||
|
|
@ -17,7 +17,7 @@ export default function Modules() {
|
||||||
|
|
||||||
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((l) => { smooth(); setList(l); }).catch((e) => setError(describe(e).detail));
|
||||||
}, []),
|
}, []),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ 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, isMessageField, MODULE_ICON, ModuleInfo, Value } from '../../src/modules';
|
import { FieldDef, isMessageField, MODULE_ICON, ModuleInfo, Value } from '../../src/modules';
|
||||||
import { Banner, Button, Card, T } from '../../src/ui';
|
import { smooth, Banner, Button, Card, T } from '../../src/ui';
|
||||||
import { font, useColors } from '../../src/theme';
|
import { font, useColors } from '../../src/theme';
|
||||||
import { Icon } from '../../src/icons';
|
import { Icon } from '../../src/icons';
|
||||||
|
|
||||||
|
|
@ -96,6 +96,7 @@ export default function ModuleScreen() {
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
const apply = (next: ModuleInfo) => {
|
const apply = (next: ModuleInfo) => {
|
||||||
|
smooth();
|
||||||
setM(next);
|
setM(next);
|
||||||
setValues(next.config);
|
setValues(next.config);
|
||||||
};
|
};
|
||||||
|
|
@ -111,6 +112,7 @@ export default function ModuleScreen() {
|
||||||
setSaved(false);
|
setSaved(false);
|
||||||
try {
|
try {
|
||||||
apply(await api.put<ModuleInfo>(`/api/staff/modules/${id}`, values));
|
apply(await api.put<ModuleInfo>(`/api/staff/modules/${id}`, values));
|
||||||
|
smooth();
|
||||||
setSaved(true);
|
setSaved(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(describe(e).detail);
|
setError(describe(e).detail);
|
||||||
|
|
@ -121,6 +123,11 @@ 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);
|
||||||
|
// La barre « Enregistrer » glisse seulement quand elle apparaît ou disparaît (pas à chaque lettre tapée).
|
||||||
|
const change = (next: Record<string, Value>) => {
|
||||||
|
if ((JSON.stringify(next) !== JSON.stringify(m.config)) !== dirty) smooth();
|
||||||
|
setValues(next);
|
||||||
|
};
|
||||||
|
|
||||||
const settings = m.fields.filter((f) => !isMessageField(f));
|
const settings = m.fields.filter((f) => !isMessageField(f));
|
||||||
const messages = m.fields.filter(isMessageField);
|
const messages = m.fields.filter(isMessageField);
|
||||||
|
|
@ -130,7 +137,7 @@ export default function ModuleScreen() {
|
||||||
<View style={{ gap: 14 }}>
|
<View style={{ gap: 14 }}>
|
||||||
<T v="label" style={{ color: c.text3, textTransform: 'uppercase', fontSize: 13, letterSpacing: 0.5 }}>{title}</T>
|
<T v="label" style={{ color: c.text3, textTransform: 'uppercase', fontSize: 13, letterSpacing: 0.5 }}>{title}</T>
|
||||||
{fields.map((f) => (
|
{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) => change({ ...values, [f.key]: v })} />
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
@ -152,7 +159,7 @@ export default function ModuleScreen() {
|
||||||
</T>
|
</T>
|
||||||
</View>
|
</View>
|
||||||
{m.available && (
|
{m.available && (
|
||||||
<Switch value={enabled} onValueChange={(v) => setValues({ ...values, enabled: v })} trackColor={{ true: c.primary }} accessibilityLabel="Module activé" />
|
<Switch value={enabled} onValueChange={(v) => change({ ...values, enabled: v })} trackColor={{ true: c.primary }} accessibilityLabel="Module activé" />
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
<T v="muted" style={{ fontSize: 14 }}>{m.description}</T>
|
<T v="muted" style={{ fontSize: 14 }}>{m.description}</T>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { ActivityIndicator, Animated, Easing, KeyboardAvoidingView, Platform, Pressable, ScrollView, StyleSheet, TextInput, View } from 'react-native';
|
import { ActivityIndicator, Animated, Easing, Keyboard, KeyboardAvoidingView, Platform, Pressable, ScrollView, StyleSheet, TextInput, View } from 'react-native';
|
||||||
import { CameraView, useCameraPermissions } from 'expo-camera';
|
import { CameraView, useCameraPermissions } from 'expo-camera';
|
||||||
import { router } from 'expo-router';
|
import { router } from 'expo-router';
|
||||||
import * as Haptics from 'expo-haptics';
|
import * as Haptics from 'expo-haptics';
|
||||||
|
|
@ -27,26 +27,25 @@ interface Found {
|
||||||
balance: number;
|
balance: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Scan() {
|
/** Feuille « Rechercher un client » : glisse depuis le bas, clavier ouvert une fois en place. État local : taper ne re-rend pas la caméra. */
|
||||||
|
const SHEET_OFFSET = 520;
|
||||||
|
|
||||||
|
function ManualPanel({ onClose, onOpenCard }: { onClose: () => void; onOpenCard: (serial: string) => void }) {
|
||||||
const c = useColors();
|
const c = useColors();
|
||||||
const [permission, requestPermission] = useCameraPermissions();
|
const progress = useRef(new Animated.Value(0)).current;
|
||||||
const [torch, setTorch] = useState(false);
|
const inputRef = useRef<TextInput>(null);
|
||||||
const [invalid, setInvalid] = useState(false);
|
const closing = useRef(false);
|
||||||
const handled = useRef(false);
|
|
||||||
// Mode comptoir : l'écran ne se met pas en veille pendant le scan.
|
|
||||||
useKeepAwake();
|
|
||||||
const [manual, setManual] = useState(false);
|
|
||||||
const [typed, setTyped] = useState('');
|
const [typed, setTyped] = useState('');
|
||||||
const [found, setFound] = useState<Found[] | null>(null);
|
const [found, setFound] = useState<Found[] | null>(null);
|
||||||
const [searching, setSearching] = useState(false);
|
const [searching, setSearching] = useState(false);
|
||||||
const [searchError, setSearchError] = useState<string | null>(null);
|
const [searchError, setSearchError] = useState<string | null>(null);
|
||||||
const typedOk = SERIAL.test(normalize(typed));
|
const typedOk = SERIAL.test(normalize(typed));
|
||||||
const term = typed.trim();
|
const term = typed.trim();
|
||||||
const isSearch = !typedOk && !/^MEP[A-Z0-9s-]*$/i.test(term) && term.length >= 2;
|
const isSearch = !typedOk && !/^MEP[A-Z0-9\s-]*$/i.test(term) && term.length >= 2;
|
||||||
|
|
||||||
// Recherche par prénom ou e-mail, au fil de la frappe (300 ms après la dernière touche).
|
// Recherche par prénom ou e-mail, au fil de la frappe (300 ms après la dernière touche).
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!manual || !isSearch) {
|
if (!isSearch) {
|
||||||
setFound(null);
|
setFound(null);
|
||||||
setSearchError(null);
|
setSearchError(null);
|
||||||
return;
|
return;
|
||||||
|
|
@ -70,24 +69,33 @@ export default function Scan() {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
clearTimeout(t);
|
clearTimeout(t);
|
||||||
};
|
};
|
||||||
}, [manual, isSearch, term]);
|
}, [isSearch, term]);
|
||||||
|
|
||||||
function openCard(serial: string) {
|
|
||||||
handled.current = true;
|
useEffect(() => {
|
||||||
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
|
Animated.timing(progress, { toValue: 1, duration: 240, easing: Easing.out(Easing.cubic), useNativeDriver: true }).start(({ finished }) => {
|
||||||
playScanOk();
|
if (finished) inputRef.current?.focus();
|
||||||
router.replace({ pathname: '/client/[serial]', params: { serial } });
|
});
|
||||||
}
|
}, [progress]);
|
||||||
|
|
||||||
|
const close = useCallback(() => {
|
||||||
|
if (closing.current) return;
|
||||||
|
closing.current = true;
|
||||||
|
Keyboard.dismiss();
|
||||||
|
Animated.timing(progress, { toValue: 0, duration: 180, easing: Easing.in(Easing.cubic), useNativeDriver: true }).start(onClose);
|
||||||
|
}, [progress, onClose]);
|
||||||
|
|
||||||
/** Recherche d'un client : numéro de carte, prénom ou e-mail (si le scan échoue ou sans caméra). */
|
/** Recherche d'un client : numéro de carte, prénom ou e-mail (si le scan échoue ou sans caméra). */
|
||||||
const manualPanel = (
|
return (
|
||||||
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={StyleSheet.absoluteFill}>
|
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={StyleSheet.absoluteFill}>
|
||||||
<Pressable style={{ flex: 1, backgroundColor: 'rgba(0,0,0,0.5)' }} onPress={() => setManual(false)} accessibilityLabel="Fermer la recherche" />
|
<Animated.View style={{ flex: 1, backgroundColor: 'rgba(0,0,0,0.5)', opacity: progress }}>
|
||||||
<View style={{ backgroundColor: c.surface, padding: 20, paddingBottom: 36, gap: 12, borderTopLeftRadius: 24, borderTopRightRadius: 24, maxHeight: '85%' }}>
|
<Pressable style={{ flex: 1 }} onPress={close} accessibilityLabel="Fermer la recherche" />
|
||||||
|
</Animated.View>
|
||||||
|
<Animated.View style={{ backgroundColor: c.surface, padding: 20, paddingBottom: 36, gap: 12, borderTopLeftRadius: 24, borderTopRightRadius: 24, maxHeight: '85%', transform: [{ translateY: progress.interpolate({ inputRange: [0, 1], outputRange: [SHEET_OFFSET, 0] }) }] }}>
|
||||||
<T v="h2">Rechercher un client</T>
|
<T v="h2">Rechercher un client</T>
|
||||||
<T v="muted" style={{ fontSize: 14 }}>Prénom, e-mail, ou numéro inscrit sous le QR code de sa carte.</T>
|
<T v="muted" style={{ fontSize: 14 }}>Prénom, e-mail, ou numéro inscrit sous le QR code de sa carte.</T>
|
||||||
<TextInput
|
<TextInput
|
||||||
autoFocus
|
ref={inputRef}
|
||||||
value={typed}
|
value={typed}
|
||||||
onChangeText={setTyped}
|
onChangeText={setTyped}
|
||||||
placeholder="Camille, camille@… ou MEP XXXX…"
|
placeholder="Camille, camille@… ou MEP XXXX…"
|
||||||
|
|
@ -96,11 +104,11 @@ export default function Scan() {
|
||||||
autoCorrect={false}
|
autoCorrect={false}
|
||||||
maxLength={60}
|
maxLength={60}
|
||||||
returnKeyType={typedOk ? 'go' : 'search'}
|
returnKeyType={typedOk ? 'go' : 'search'}
|
||||||
onSubmitEditing={() => typedOk && openCard(normalize(typed))}
|
onSubmitEditing={() => typedOk && onOpenCard(normalize(typed))}
|
||||||
accessibilityLabel="Prénom, e-mail ou numéro de carte"
|
accessibilityLabel="Prénom, e-mail ou numéro de carte"
|
||||||
style={{ borderWidth: 1, borderColor: c.border, borderRadius: 14, padding: 14, fontSize: 17, color: c.text, backgroundColor: c.bg, fontFamily: font.semibold }}
|
style={{ borderWidth: 1, borderColor: c.border, borderRadius: 14, padding: 14, fontSize: 17, color: c.text, backgroundColor: c.bg, fontFamily: font.semibold }}
|
||||||
/>
|
/>
|
||||||
{typedOk && <Button large label="Ouvrir la carte" onPress={() => openCard(normalize(typed))} />}
|
{typedOk && <Button large label="Ouvrir la carte" onPress={() => onOpenCard(normalize(typed))} />}
|
||||||
{!typedOk && /^MEP/i.test(term) && <T style={{ color: c.text3, fontSize: 13 }}>{normalize(typed).length} / 11 caractères</T>}
|
{!typedOk && /^MEP/i.test(term) && <T style={{ color: c.text3, fontSize: 13 }}>{normalize(typed).length} / 11 caractères</T>}
|
||||||
{isSearch && (
|
{isSearch && (
|
||||||
<ScrollView style={{ maxHeight: 320 }} keyboardShouldPersistTaps="handled">
|
<ScrollView style={{ maxHeight: 320 }} keyboardShouldPersistTaps="handled">
|
||||||
|
|
@ -112,7 +120,7 @@ export default function Scan() {
|
||||||
key={f.serial}
|
key={f.serial}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel={`${f.firstName}, ${f.email}, solde ${f.balance}`}
|
accessibilityLabel={`${f.firstName}, ${f.email}, solde ${f.balance}`}
|
||||||
onPress={() => openCard(f.serial)}
|
onPress={() => onOpenCard(f.serial)}
|
||||||
style={({ pressed }) => ({ flexDirection: 'row', alignItems: 'center', gap: 12, paddingVertical: 12, borderBottomWidth: 1, borderBottomColor: c.border, opacity: pressed ? 0.6 : 1 })}
|
style={({ pressed }) => ({ flexDirection: 'row', alignItems: 'center', gap: 12, paddingVertical: 12, borderBottomWidth: 1, borderBottomColor: c.border, opacity: pressed ? 0.6 : 1 })}
|
||||||
>
|
>
|
||||||
<View style={{ width: 40, height: 40, borderRadius: 20, backgroundColor: c.primarySoft, alignItems: 'center', justifyContent: 'center' }}>
|
<View style={{ width: 40, height: 40, borderRadius: 20, backgroundColor: c.primarySoft, alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
|
@ -127,14 +135,34 @@ export default function Scan() {
|
||||||
))}
|
))}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
)}
|
)}
|
||||||
<Button label="Annuler" variant="secondary" onPress={() => setManual(false)} />
|
<Button label="Annuler" variant="secondary" onPress={close} />
|
||||||
</View>
|
</Animated.View>
|
||||||
</KeyboardAvoidingView>
|
</KeyboardAvoidingView>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Scan() {
|
||||||
|
const c = useColors();
|
||||||
|
const [permission, requestPermission] = useCameraPermissions();
|
||||||
|
const [torch, setTorch] = useState(false);
|
||||||
|
const [invalid, setInvalid] = useState(false);
|
||||||
|
const handled = useRef(false);
|
||||||
|
// Mode comptoir : l'écran ne se met pas en veille pendant le scan.
|
||||||
|
useKeepAwake();
|
||||||
|
const [manual, setManual] = useState(false);
|
||||||
|
|
||||||
|
function openCard(serial: string) {
|
||||||
|
handled.current = true;
|
||||||
|
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
|
||||||
|
playScanOk();
|
||||||
|
router.replace({ pathname: '/client/[serial]', params: { serial } });
|
||||||
|
}
|
||||||
|
|
||||||
const line = useRef(new Animated.Value(0)).current;
|
const line = useRef(new Animated.Value(0)).current;
|
||||||
|
|
||||||
// Ligne de balayage : montre que la lecture est en cours.
|
// Ligne de balayage : montre que la lecture est en cours.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (manual) return;
|
||||||
const anim = Animated.loop(
|
const anim = Animated.loop(
|
||||||
Animated.sequence([
|
Animated.sequence([
|
||||||
Animated.timing(line, { toValue: 1, duration: 1600, easing: Easing.inOut(Easing.quad), useNativeDriver: true }),
|
Animated.timing(line, { toValue: 1, duration: 1600, easing: Easing.inOut(Easing.quad), useNativeDriver: true }),
|
||||||
|
|
@ -143,7 +171,7 @@ export default function Scan() {
|
||||||
);
|
);
|
||||||
anim.start();
|
anim.start();
|
||||||
return () => anim.stop();
|
return () => anim.stop();
|
||||||
}, [line]);
|
}, [line, manual]);
|
||||||
|
|
||||||
// Le message « QR code inconnu » disparaît tout seul.
|
// Le message « QR code inconnu » disparaît tout seul.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -170,7 +198,7 @@ export default function Scan() {
|
||||||
)}
|
)}
|
||||||
<Button label="Rechercher un client" variant="secondary" onPress={() => setManual(true)} />
|
<Button label="Rechercher un client" variant="secondary" onPress={() => setManual(true)} />
|
||||||
<Button label="Retour" variant="secondary" onPress={() => router.back()} />
|
<Button label="Retour" variant="secondary" onPress={() => router.back()} />
|
||||||
{manual && manualPanel}
|
{manual && <ManualPanel onClose={() => setManual(false)} onOpenCard={openCard} />}
|
||||||
</Screen>
|
</Screen>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -184,7 +212,7 @@ export default function Scan() {
|
||||||
facing="back"
|
facing="back"
|
||||||
enableTorch={torch}
|
enableTorch={torch}
|
||||||
barcodeScannerSettings={{ barcodeTypes: ['qr'] }}
|
barcodeScannerSettings={{ barcodeTypes: ['qr'] }}
|
||||||
onBarcodeScanned={({ data }) => {
|
onBarcodeScanned={manual ? undefined : ({ data }) => {
|
||||||
if (handled.current) return;
|
if (handled.current) return;
|
||||||
const serial = data.trim().toUpperCase();
|
const serial = data.trim().toUpperCase();
|
||||||
if (!SERIAL.test(serial)) {
|
if (!SERIAL.test(serial)) {
|
||||||
|
|
@ -256,7 +284,7 @@ export default function Scan() {
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
{manual && manualPanel}
|
{manual && <ManualPanel onClose={() => setManual(false)} onOpenCard={openCard} />}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { ActivityIndicator, Alert, Pressable, ScrollView, View } from 'react-nat
|
||||||
import { useFocusEffect } from 'expo-router';
|
import { useFocusEffect } from 'expo-router';
|
||||||
import { api, ApiError } from '../src/api';
|
import { api, ApiError } from '../src/api';
|
||||||
import { describe } from '../src/errors';
|
import { describe } from '../src/errors';
|
||||||
import { Banner, Card, T } from '../src/ui';
|
import { smooth, Banner, Card, T } from '../src/ui';
|
||||||
import { font, useColors } from '../src/theme';
|
import { font, useColors } from '../src/theme';
|
||||||
import { Icon, IconName } from '../src/icons';
|
import { Icon, IconName } from '../src/icons';
|
||||||
|
|
||||||
|
|
@ -43,7 +43,9 @@ export default function StatsScreen() {
|
||||||
const load = useCallback(async (d: number) => {
|
const load = useCallback(async (d: number) => {
|
||||||
try {
|
try {
|
||||||
setError(null);
|
setError(null);
|
||||||
setData(await api.get<Stats>(`/api/staff/stats?days=${d}`));
|
const next = await api.get<Stats>(`/api/staff/stats?days=${d}`);
|
||||||
|
smooth();
|
||||||
|
setData(next);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const info = describe(e);
|
const info = describe(e);
|
||||||
if (e instanceof ApiError && (e.code === 'PLAN_REQUIRED' || e.code === 'MODULE_DISABLED')) setLocked(true);
|
if (e instanceof ApiError && (e.code === 'PLAN_REQUIRED' || e.code === 'MODULE_DISABLED')) setLocked(true);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { 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 { useSession } from '../src/session';
|
import { useSession } from '../src/session';
|
||||||
import { Banner, Button, Card, T } from '../src/ui';
|
import { smooth, Banner, Button, Card, T } from '../src/ui';
|
||||||
import { font, useColors } from '../src/theme';
|
import { font, useColors } from '../src/theme';
|
||||||
import { Icon } from '../src/icons';
|
import { Icon } from '../src/icons';
|
||||||
import { confirmIdentity } from '../src/biometrics';
|
import { confirmIdentity } from '../src/biometrics';
|
||||||
|
|
@ -49,8 +49,11 @@ export default function Team() {
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
setList(await api.get<Member[]>('/api/staff/team'));
|
const l = await api.get<Member[]>('/api/staff/team');
|
||||||
|
smooth();
|
||||||
|
setList(l);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
smooth();
|
||||||
setError(describe(e).detail);
|
setError(describe(e).detail);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
@ -66,12 +69,14 @@ export default function Team() {
|
||||||
await fn();
|
await fn();
|
||||||
await load();
|
await load();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
smooth();
|
||||||
setError(describe(e).detail);
|
setError(describe(e).detail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function create() {
|
async function create() {
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
|
smooth();
|
||||||
setNotice(null);
|
setNotice(null);
|
||||||
await run(async () => {
|
await run(async () => {
|
||||||
const m = await api.post<Member>('/api/staff/team', { displayName: name.trim(), email: email.trim(), role });
|
const m = await api.post<Member>('/api/staff/team', { displayName: name.trim(), email: email.trim(), role });
|
||||||
|
|
@ -79,6 +84,7 @@ export default function Team() {
|
||||||
setName('');
|
setName('');
|
||||||
setEmail('');
|
setEmail('');
|
||||||
setRole('EMPLOYEE');
|
setRole('EMPLOYEE');
|
||||||
|
smooth();
|
||||||
setAdding(false);
|
setAdding(false);
|
||||||
});
|
});
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
|
|
@ -187,10 +193,10 @@ export default function Team() {
|
||||||
</Pressable>
|
</Pressable>
|
||||||
))}
|
))}
|
||||||
<Button label="Créer le compte" onPress={create} loading={busy} disabled={name.trim().length < 2 || !email.includes('@')} />
|
<Button label="Créer le compte" onPress={create} loading={busy} disabled={name.trim().length < 2 || !email.includes('@')} />
|
||||||
<Button label="Annuler" variant="secondary" onPress={() => setAdding(false)} />
|
<Button label="Annuler" variant="secondary" onPress={() => { smooth(); setAdding(false); }} />
|
||||||
</Card>
|
</Card>
|
||||||
) : (
|
) : (
|
||||||
<Button label="+ Nouvel employé" onPress={() => setAdding(true)} />
|
<Button label="+ Nouvel employé" onPress={() => { smooth(); setAdding(true); }} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Comptes */}
|
{/* Comptes */}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,25 @@
|
||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, TextProps, View, ViewStyle } from 'react-native';
|
import { ActivityIndicator, LayoutAnimation, Platform, Pressable, ScrollView, StyleSheet, Text, TextProps, UIManager, View, ViewStyle } from 'react-native';
|
||||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||||
import Svg, { Circle, Path } from 'react-native-svg';
|
import Svg, { Circle, Path } from 'react-native-svg';
|
||||||
import { font, useColors } from './theme';
|
import { font, useColors } from './theme';
|
||||||
|
|
||||||
|
if (Platform.OS === 'android') UIManager.setLayoutAnimationEnabledExperimental?.(true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* À appeler juste avant un changement d'état qui fait apparaître, disparaître ou déplacer des éléments
|
||||||
|
* (bandeau, formulaire, liste chargée, onglet) : la mise en page glisse et les éléments apparaissent en fondu
|
||||||
|
* au lieu de sauter d'un coup.
|
||||||
|
*/
|
||||||
|
export function smooth() {
|
||||||
|
LayoutAnimation.configureNext({
|
||||||
|
duration: 220,
|
||||||
|
create: { type: 'easeInEaseOut', property: 'opacity' },
|
||||||
|
update: { type: 'easeInEaseOut' },
|
||||||
|
delete: { type: 'easeInEaseOut', property: 'opacity' },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Écran standard. `noHeader` : écran sans barre de titre, le contenu reste sous
|
* Écran standard. `noHeader` : écran sans barre de titre, le contenu reste sous
|
||||||
* la Dynamic Island / l'encoche (marge haute de sécurité).
|
* la Dynamic Island / l'encoche (marge haute de sécurité).
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue