MonEspacePro/pro/app/login.tsx
Tony AVERTY 6725358a7c App Pro (Expo) et API du comptoir avec anti-triche
- 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>
2026-10-06 12:50:59 +02:00

84 lines
2.8 KiB
TypeScript

import { useState } from 'react';
import { KeyboardAvoidingView, Platform, TextInput, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useSession } from '../src/session';
import { Banner, BrandSymbol, Button, T } from '../src/ui';
import { font, useColors } from '../src/theme';
export default function Login() {
const c = useColors();
const { login } = useSession();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
async function submit() {
setBusy(true);
setError(null);
try {
await login(email.trim(), password);
} catch (e) {
setError((e as Error).message);
} finally {
setBusy(false);
}
}
const input = {
height: 56,
borderWidth: 1,
borderColor: '#8A897F',
borderRadius: 12,
paddingHorizontal: 16,
fontSize: 17,
fontFamily: font.regular,
color: c.text,
backgroundColor: c.surface,
};
return (
<SafeAreaView style={{ flex: 1, backgroundColor: c.bg }}>
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={{ flex: 1, padding: 24, justifyContent: 'center', gap: 28 }}>
<View style={{ alignItems: 'center', gap: 12 }}>
<BrandSymbol size={64} />
<T v="h1" style={{ textAlign: 'center' }}>
MonEspace<T v="h1" style={{ color: c.primary }}>Pro</T>
</T>
<T v="muted">Espace employés</T>
</View>
{error && <Banner tone="error">{error}</Banner>}
<View style={{ gap: 6 }}>
<T v="label" nativeID="l-email">E-mail</T>
<TextInput
accessibilityLabelledBy="l-email"
style={input}
value={email}
onChangeText={setEmail}
autoCapitalize="none"
autoComplete="email"
keyboardType="email-address"
textContentType="username"
returnKeyType="next"
/>
</View>
<View style={{ gap: 6 }}>
<T v="label" nativeID="l-pwd">Mot de passe</T>
<TextInput
accessibilityLabelledBy="l-pwd"
style={input}
value={password}
onChangeText={setPassword}
secureTextEntry
autoComplete="current-password"
textContentType="password"
returnKeyType="go"
onSubmitEditing={submit}
/>
</View>
<Button label="Se connecter" onPress={submit} loading={busy} disabled={!email || password.length < 8} />
<T v="muted" style={{ textAlign: 'center' }}>Identifiants fournis par votre gérant.</T>
</KeyboardAvoidingView>
</SafeAreaView>
);
}