App : page Mon compte retravaillée
Profil (initiale, nom, rôle, magasin), changement de mot de passe avec affichage facultatif et indicateur de solidité, bouton de déconnexion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c5e5ffc720
commit
9c5695758d
1 changed files with 81 additions and 15 deletions
|
|
@ -1,17 +1,18 @@
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { ScrollView, TextInput } from 'react-native';
|
import { Alert, Pressable, ScrollView, TextInput, View } from 'react-native';
|
||||||
import { api } from '../src/api';
|
import { api } from '../src/api';
|
||||||
import { describe } from '../src/errors';
|
import { describe } from '../src/errors';
|
||||||
import { useSession } from '../src/session';
|
import { useSession } from '../src/session';
|
||||||
import { Banner, Button, T } from '../src/ui';
|
import { Banner, Button, Card, T } from '../src/ui';
|
||||||
import { font, useColors } from '../src/theme';
|
import { font, useColors } from '../src/theme';
|
||||||
|
|
||||||
/** Mon compte : changement du mot de passe (tous les rôles). */
|
/** Mon compte : profil, changement du mot de passe, déconnexion (tous les rôles). */
|
||||||
export default function Account() {
|
export default function Account() {
|
||||||
const c = useColors();
|
const c = useColors();
|
||||||
const { me } = useSession();
|
const { me, logout } = useSession();
|
||||||
const [current, setCurrent] = useState('');
|
const [current, setCurrent] = useState('');
|
||||||
const [next, setNext] = useState('');
|
const [next, setNext] = useState('');
|
||||||
|
const [show, setShow] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [done, setDone] = useState(false);
|
const [done, setDone] = useState(false);
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
@ -32,20 +33,85 @@ export default function Account() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const input = { borderWidth: 1, borderColor: c.border, borderRadius: 14, padding: 14, backgroundColor: c.surface, color: c.text, fontFamily: font.regular, fontSize: 16 } as const;
|
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 (
|
return (
|
||||||
<ScrollView contentContainerStyle={{ padding: 20, gap: 14 }} keyboardShouldPersistTaps="handled">
|
<ScrollView contentContainerStyle={{ padding: 20, gap: 18, flexGrow: 1 }} keyboardShouldPersistTaps="handled" bounces={false} overScrollMode="never">
|
||||||
<T v="muted">
|
{/* Profil */}
|
||||||
{me?.displayName} · {me?.role === 'MANAGER' ? 'Dirigeant' : 'Employé'}
|
<View style={{ alignItems: 'center', gap: 8, paddingVertical: 8 }}>
|
||||||
</T>
|
<View style={{ width: 84, height: 84, borderRadius: 42, backgroundColor: c.primarySoft, alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
<T style={{ fontFamily: font.extrabold, fontSize: 34, color: c.primary }}>{me?.displayName.charAt(0).toUpperCase()}</T>
|
||||||
|
</View>
|
||||||
|
<T v="h1" style={{ textAlign: 'center' }}>{me?.displayName}</T>
|
||||||
|
<View style={{ flexDirection: 'row', gap: 6, alignItems: 'center' }}>
|
||||||
|
<View style={{ paddingHorizontal: 10, paddingVertical: 3, borderRadius: 999, backgroundColor: manager ? c.primarySoft : c.surface2 }}>
|
||||||
|
<T style={{ fontSize: 13, fontFamily: font.semibold, color: manager ? c.primary : c.text3 }}>{manager ? 'Dirigeant' : 'Employé'}</T>
|
||||||
|
</View>
|
||||||
|
<T v="muted" style={{ fontSize: 14 }}>{me?.store.name}</T>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
{error && <Banner tone="error">{error}</Banner>}
|
{error && <Banner tone="error">{error}</Banner>}
|
||||||
{done && <Banner tone="ok">Mot de passe modifié.</Banner>}
|
{done && <Banner tone="ok">Mot de passe modifié.</Banner>}
|
||||||
<T v="label">Mot de passe actuel</T>
|
|
||||||
<TextInput value={current} onChangeText={setCurrent} secureTextEntry autoComplete="current-password" accessibilityLabel="Mot de passe actuel" style={input} />
|
{/* Mot de passe */}
|
||||||
<T v="label">Nouveau mot de passe</T>
|
<Card style={{ gap: 12 }}>
|
||||||
<TextInput value={next} onChangeText={setNext} secureTextEntry autoComplete="new-password" accessibilityLabel="Nouveau mot de passe" style={input} />
|
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||||
<T v="muted" style={{ fontSize: 13 }}>10 caractères minimum.</T>
|
<T v="h2">Mot de passe</T>
|
||||||
|
<Pressable accessibilityRole="button" hitSlop={10} onPress={() => setShow(!show)}>
|
||||||
|
<T style={{ color: c.primary, fontFamily: font.semibold, fontSize: 14 }}>{show ? 'Masquer' : 'Afficher'}</T>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
<TextInput
|
||||||
|
value={current}
|
||||||
|
onChangeText={setCurrent}
|
||||||
|
secureTextEntry={!show}
|
||||||
|
autoComplete="current-password"
|
||||||
|
placeholder="Mot de passe actuel"
|
||||||
|
placeholderTextColor={c.text3}
|
||||||
|
accessibilityLabel="Mot de passe actuel"
|
||||||
|
style={input}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
value={next}
|
||||||
|
onChangeText={setNext}
|
||||||
|
secureTextEntry={!show}
|
||||||
|
autoComplete="new-password"
|
||||||
|
placeholder="Nouveau mot de passe"
|
||||||
|
placeholderTextColor={c.text3}
|
||||||
|
accessibilityLabel="Nouveau mot de passe"
|
||||||
|
style={input}
|
||||||
|
/>
|
||||||
|
{next.length > 0 && (
|
||||||
|
<View style={{ gap: 6 }}>
|
||||||
|
<View style={{ flexDirection: 'row', gap: 4 }}>
|
||||||
|
{[0, 1, 2].map((i) => (
|
||||||
|
<View key={i} style={{ flex: 1, height: 5, borderRadius: 3, backgroundColor: i <= strength ? strengthColor : c.surface2 }} />
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
<T style={{ fontSize: 13, color: strengthColor, fontFamily: font.semibold }}>{strengthLabel}</T>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
<Button label="Changer le mot de passe" onPress={save} loading={busy} disabled={!current || next.length < 10} />
|
<Button label="Changer le mot de passe" onPress={save} loading={busy} disabled={!current || next.length < 10} />
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<View style={{ flex: 1 }} />
|
||||||
|
<Button
|
||||||
|
label="Se déconnecter"
|
||||||
|
variant="secondary"
|
||||||
|
onPress={() =>
|
||||||
|
Alert.alert('Se déconnecter ?', undefined, [
|
||||||
|
{ text: 'Annuler', style: 'cancel' },
|
||||||
|
{ text: 'Se déconnecter', style: 'destructive', onPress: logout },
|
||||||
|
])
|
||||||
|
}
|
||||||
|
/>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue