- API /staff : profil, scan d'une carte, crédit (montant ou tampon), récompenses, historique (gérant : tout le magasin, employé : le sien), résumé du jour - Anti-triche côté serveur : carte du bon magasin, plafond de montant, délai minimum entre deux crédits (atomique, scans simultanés compris), tentatives refusées journalisées avec l'employé - App Expo SDK 54 / Expo Router : connexion, accueil, scanner QR avec lampe, fiche client, pavé numérique, récompenses, confirmation, erreurs, historique ; icônes générées depuis le logo Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
3.6 KiB
TypeScript
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 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 Pro 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 },
|
|
});
|