import { useState } from 'react'; import { Alert, Pressable, ScrollView, TextInput, View } from 'react-native'; import { api } from '../src/api'; import { describe } from '../src/errors'; import { useSession } from '../src/session'; import { Banner, Button, Card, T } from '../src/ui'; import { font, useColors } from '../src/theme'; /** Mon compte : profil, changement du mot de passe, déconnexion (tous les rôles). */ export default function Account() { const c = useColors(); const { me, logout } = useSession(); const [current, setCurrent] = useState(''); const [next, setNext] = useState(''); const [show, setShow] = useState(false); const [error, setError] = useState(null); const [done, setDone] = useState(false); const [busy, setBusy] = useState(false); async function save() { setBusy(true); setError(null); setDone(false); try { await api.post('/api/staff/password', { current, next }); setCurrent(''); setNext(''); setDone(true); } catch (e) { setError(describe(e).detail); } finally { setBusy(false); } } const manager = me?.role === 'MANAGER'; // Indication simple : longueur, puis variété (chiffres, majuscules, symboles). const variety = [/\d/, /[A-Z]/, /[^A-Za-z0-9]/].filter((r) => r.test(next)).length; const strength = next.length < 10 ? 0 : variety >= 2 || next.length >= 14 ? 2 : 1; const strengthLabel = ['Trop court (10 caractères minimum)', 'Correct', 'Solide'][strength]; const strengthColor = [c.err, c.warn, c.ok][strength]; const input = { borderWidth: 1, borderColor: c.border, borderRadius: 14, padding: 14, backgroundColor: c.bg, color: c.text, fontFamily: font.regular, fontSize: 16 } as const; return ( {/* Profil */} {me?.displayName.charAt(0).toUpperCase()} {me?.displayName} {manager ? 'Dirigeant' : 'Employé'} {me?.store.name} {error && {error}} {done && Mot de passe modifié.} {/* Mot de passe */} Mot de passe setShow(!show)}> {show ? 'Masquer' : 'Afficher'} {next.length > 0 && ( {[0, 1, 2].map((i) => ( ))} {strengthLabel} )}