import { useRef, useState } from 'react'; import { KeyboardAvoidingView, Linking, Platform, Pressable, ScrollView, TextInput, View } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { useSession } from '../src/session'; import { api } from '../src/api'; import { describe } from '../src/errors'; import { Banner, BrandSymbol, Button, Card, T } from '../src/ui'; import { font, useColors } from '../src/theme'; /** Connexion (Dirigeant et employés) : mêmes identifiants que l'espace web. */ export default function Login() { const c = useColors(); const { login } = useSession(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [show, setShow] = useState(false); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const pwdRef = useRef(null); const [forgot, setForgot] = useState(false); const [forgotDone, setForgotDone] = useState(false); const [forgotBusy, setForgotBusy] = useState(false); /** Envoie un lien pour choisir un nouveau mot de passe (même réponse que le compte existe ou non). */ async function sendReset() { setForgotBusy(true); setError(null); try { await api.postPublic('/api/public/mot-de-passe/oubli', { email: email.trim() }); setForgotDone(true); } catch (e) { setError(describe(e).detail); } finally { setForgotBusy(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: c.border, borderRadius: 14, paddingHorizontal: 16, fontSize: 17, fontFamily: font.regular, color: c.text, backgroundColor: c.bg, }; return ( {/* Bandeau de marque */} MonEspacePro La fidélité de vos clients, au comptoir Connexion {error && {error}} E-mail pwdRef.current?.focus()} /> Mot de passe setShow(!show)}> {show ? 'Masquer' : 'Afficher'}