MonEspacePro/pro/app/scan.tsx
Tony AVERTY 567d9fb877 App : pastille de validation sous la Dynamic Island, bouton retour, finitions visuelles
- Écrans sans en-tête (confirmation, autorisation caméra) : marge haute de sécurité
- Récompenses : bouton « Retour » ; confirmation : « Retour à la fiche client »
- Fiche client rechargée à chaque affichage (solde à jour)
- Cartes à ombre légère, boutons plus arrondis, halo de validation,
  accueil avec salutation et chiffres du jour sur fond teinté

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 14:12:46 +02:00

86 lines
3.6 KiB
TypeScript

import { useRef, useState } from 'react';
import { Pressable, StyleSheet, View } from 'react-native';
import { CameraView, useCameraPermissions } from 'expo-camera';
import { router } from 'expo-router';
import * as Haptics from 'expo-haptics';
import { SafeAreaView } from 'react-native-safe-area-context';
import { Button, Screen, T } from '../src/ui';
import { font } from '../src/theme';
/** Les numéros de carte commencent par « MEP » (voir le back-end). */
const SERIAL = /^MEP[A-Z2-9]{16}$/;
export default function Scan() {
const [permission, requestPermission] = useCameraPermissions();
const [torch, setTorch] = useState(false);
const [invalid, setInvalid] = useState(false);
const handled = useRef(false);
if (!permission) return null;
if (!permission.granted) {
return (
<Screen noHeader style={{ justifyContent: 'center' }}>
<T v="h1">Accès à la caméra</T>
<T v="muted">La caméra sert uniquement à lire le QR code de la carte de fidélité du client.</T>
{permission.canAskAgain ? (
<Button label="Autoriser la caméra" onPress={requestPermission} />
) : (
<T>Autorisez la caméra pour MonEspacePro dans les réglages du téléphone.</T>
)}
<Button label="Retour" variant="secondary" onPress={() => router.back()} />
</Screen>
);
}
return (
<View style={{ flex: 1, backgroundColor: '#000' }}>
<CameraView
style={StyleSheet.absoluteFill}
facing="back"
enableTorch={torch}
barcodeScannerSettings={{ barcodeTypes: ['qr'] }}
onBarcodeScanned={({ data }) => {
if (handled.current) return;
const serial = data.trim().toUpperCase();
if (!SERIAL.test(serial)) {
setInvalid(true);
return;
}
handled.current = true;
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
router.replace({ pathname: '/client/[serial]', params: { serial } });
}}
/>
<SafeAreaView style={{ flex: 1, justifyContent: 'space-between', padding: 20 }}>
<T style={{ color: '#fff', fontFamily: font.bold, fontSize: 22, textAlign: 'center' }}>Visez le QR code de la carte</T>
<View style={styles.frame} accessibilityElementsHidden />
<View style={{ gap: 12 }}>
{invalid && (
<T style={{ color: '#fff', textAlign: 'center', backgroundColor: 'rgba(184,50,42,0.9)', padding: 10, borderRadius: 10, overflow: 'hidden' }}>
Ce QR code n'est pas une carte MonEspacePro.
</T>
)}
<View style={{ flexDirection: 'row', gap: 12 }}>
<Pressable accessibilityRole="button" onPress={() => router.back()} style={styles.chip}>
<T style={styles.chipText}>Annuler</T>
</Pressable>
<Pressable
accessibilityRole="button"
accessibilityState={{ selected: torch }}
onPress={() => setTorch((t) => !t)}
style={[styles.chip, torch && { backgroundColor: '#F2B544' }]}
>
<T style={[styles.chipText, torch && { color: '#1C1C19' }]}>{torch ? 'Lampe allumée' : 'Lampe'}</T>
</Pressable>
</View>
</View>
</SafeAreaView>
</View>
);
}
const styles = StyleSheet.create({
frame: { alignSelf: 'center', width: 260, height: 260, borderRadius: 24, borderWidth: 4, borderColor: '#FFFFFF' },
chip: { flex: 1, height: 56, borderRadius: 14, backgroundColor: 'rgba(255,255,255,0.2)', alignItems: 'center', justifyContent: 'center' },
chipText: { color: '#fff', fontFamily: font.bold, fontSize: 17 },
});