App : page Employés retravaillée
Bouton « + Nouvel employé » qui déplie le formulaire, choix du rôle en boutons radio, identifiants provisoires mis en valeur, comptes en cartes (initiale, rôle et état en pastilles), actions regroupées dans un menu. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f07e899d8a
commit
c5e5ffc720
1 changed files with 112 additions and 73 deletions
123
pro/app/team.tsx
123
pro/app/team.tsx
|
|
@ -28,6 +28,7 @@ export default function Team() {
|
|||
const { me } = useSession();
|
||||
const [list, setList] = useState<Member[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [name, setName] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
const [role, setRole] = useState<Role>('EMPLOYEE');
|
||||
|
|
@ -65,30 +66,60 @@ export default function Team() {
|
|||
setName('');
|
||||
setEmail('');
|
||||
setRole('EMPLOYEE');
|
||||
setAdding(false);
|
||||
});
|
||||
setBusy(false);
|
||||
}
|
||||
|
||||
const input = { borderWidth: 1, borderColor: c.border, borderRadius: 14, padding: 14, backgroundColor: c.surface, color: c.text, fontFamily: font.regular, fontSize: 16 } as const;
|
||||
/** Actions d'un compte, regroupées dans un menu pour garder la liste lisible. */
|
||||
function actions(m: Member) {
|
||||
Alert.alert(m.displayName, m.email, [
|
||||
{
|
||||
text: m.role === 'MANAGER' ? 'Passer Employé' : 'Passer Dirigeant',
|
||||
onPress: () => run(() => api.patch(`/api/staff/team/${m.id}`, { role: m.role === 'MANAGER' ? 'EMPLOYEE' : 'MANAGER' })),
|
||||
},
|
||||
{
|
||||
text: 'Nouveau mot de passe',
|
||||
onPress: () => run(async () => setCreated(await api.post<Member>(`/api/staff/team/${m.id}/reset-password`))),
|
||||
},
|
||||
{
|
||||
text: m.active ? 'Désactiver le compte' : 'Réactiver le compte',
|
||||
style: m.active ? 'destructive' : 'default',
|
||||
onPress: () => run(() => api.patch(`/api/staff/team/${m.id}`, { active: !m.active })),
|
||||
},
|
||||
{ text: 'Annuler', style: 'cancel' },
|
||||
]);
|
||||
}
|
||||
|
||||
const input = { borderWidth: 1, borderColor: c.border, borderRadius: 14, padding: 14, backgroundColor: c.bg, color: c.text, fontFamily: font.regular, fontSize: 16 } as const;
|
||||
const activeCount = list?.filter((m) => m.active).length ?? 0;
|
||||
const sorted = [...(list ?? [])].sort((a, b) => Number(b.active) - Number(a.active) || a.role.localeCompare(b.role) || a.displayName.localeCompare(b.displayName));
|
||||
|
||||
return (
|
||||
<ScrollView contentContainerStyle={{ padding: 20, gap: 16 }} keyboardShouldPersistTaps="handled">
|
||||
<ScrollView contentContainerStyle={{ padding: 20, gap: 16 }} keyboardShouldPersistTaps="handled" bounces={false} overScrollMode="never">
|
||||
{error && <Banner tone="error">{error}</Banner>}
|
||||
|
||||
{/* Identifiants à transmettre (création ou nouveau mot de passe) */}
|
||||
{created?.provisionalPassword && (
|
||||
<Card style={{ padding: 16, gap: 8, borderColor: c.ok }}>
|
||||
<T v="label">Compte créé pour {created.displayName}</T>
|
||||
<T v="muted">Identifiant : {created.email}</T>
|
||||
<T style={{ fontFamily: font.bold, fontSize: 22, letterSpacing: 1 }} selectable>{created.provisionalPassword}</T>
|
||||
<T v="muted" style={{ fontSize: 13 }}>Mot de passe provisoire : il ne sera plus affiché ensuite.</T>
|
||||
<View style={{ backgroundColor: c.okBg, borderRadius: 20, padding: 18, gap: 10 }}>
|
||||
<T v="label" style={{ color: c.ok }}>✓ Identifiants de {created.displayName}</T>
|
||||
<View style={{ backgroundColor: c.surface, borderRadius: 14, padding: 14, gap: 4 }}>
|
||||
<T v="muted" style={{ fontSize: 13 }}>Identifiant</T>
|
||||
<T v="label" selectable>{created.email}</T>
|
||||
<T v="muted" style={{ fontSize: 13, marginTop: 6 }}>Mot de passe provisoire</T>
|
||||
<T style={{ fontFamily: font.extrabold, fontSize: 24, letterSpacing: 1.5 }} selectable>{created.provisionalPassword}</T>
|
||||
</View>
|
||||
<T v="muted" style={{ fontSize: 13 }}>Il ne sera plus affiché ensuite : transmettez-le maintenant.</T>
|
||||
<Button
|
||||
label="Partager les identifiants"
|
||||
variant="secondary"
|
||||
onPress={() => Share.share({ message: `MonEspacePro\nIdentifiant : ${created.email}\nMot de passe : ${created.provisionalPassword}` })}
|
||||
/>
|
||||
</Card>
|
||||
</View>
|
||||
)}
|
||||
|
||||
<View style={{ gap: 10 }}>
|
||||
{/* Nouveau compte : formulaire déplié à la demande */}
|
||||
{adding ? (
|
||||
<Card style={{ gap: 12 }}>
|
||||
<T v="h2">Nouvel employé</T>
|
||||
<TextInput value={name} onChangeText={setName} placeholder="Prénom Nom" placeholderTextColor={c.text3} accessibilityLabel="Prénom et nom" style={input} maxLength={80} />
|
||||
<TextInput
|
||||
|
|
@ -102,57 +133,65 @@ export default function Team() {
|
|||
keyboardType="email-address"
|
||||
style={input}
|
||||
/>
|
||||
<T v="label">Rôle</T>
|
||||
{(['EMPLOYEE', 'MANAGER'] as const).map((r) => (
|
||||
<Pressable key={r} accessibilityRole="radio" accessibilityState={{ checked: role === r }} onPress={() => setRole(r)}>
|
||||
<Card style={{ padding: 14, gap: 2, borderWidth: 2, borderColor: role === r ? c.primary : c.border }}>
|
||||
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 12, padding: 14, borderRadius: 14, borderWidth: 2, borderColor: role === r ? c.primary : c.border, backgroundColor: role === r ? c.primarySoft : c.surface }}>
|
||||
<View style={{ width: 22, height: 22, borderRadius: 11, borderWidth: 2, borderColor: role === r ? c.primary : c.border, alignItems: 'center', justifyContent: 'center' }}>
|
||||
{role === r && <View style={{ width: 10, height: 10, borderRadius: 5, backgroundColor: c.primary }} />}
|
||||
</View>
|
||||
<View style={{ flex: 1 }}>
|
||||
<T v="label">{ROLE[r][0]}</T>
|
||||
<T v="muted" style={{ fontSize: 13 }}>{ROLE[r][1]}</T>
|
||||
</Card>
|
||||
</View>
|
||||
</View>
|
||||
</Pressable>
|
||||
))}
|
||||
<Button label="Créer le compte" onPress={create} loading={busy} disabled={name.trim().length < 2 || !email.includes('@')} />
|
||||
</View>
|
||||
<Button label="Annuler" variant="secondary" onPress={() => setAdding(false)} />
|
||||
</Card>
|
||||
) : (
|
||||
<Button label="+ Nouvel employé" onPress={() => setAdding(true)} />
|
||||
)}
|
||||
|
||||
<View style={{ gap: 10, marginTop: 8 }}>
|
||||
<T v="h2">Comptes</T>
|
||||
{list?.map((m) => {
|
||||
{/* Comptes */}
|
||||
{list && (
|
||||
<T v="label" style={{ color: c.text3, marginTop: 4 }}>
|
||||
{activeCount} compte{activeCount > 1 ? 's' : ''} actif{activeCount > 1 ? 's' : ''}
|
||||
</T>
|
||||
)}
|
||||
{sorted.map((m) => {
|
||||
const self = m.id === me?.id;
|
||||
return (
|
||||
<Card key={m.id} style={{ padding: 14, gap: 8, opacity: m.active ? 1 : 0.6 }}>
|
||||
<View>
|
||||
<T v="label">
|
||||
<Pressable key={m.id} accessibilityRole="button" disabled={self} onPress={() => actions(m)}>
|
||||
{({ pressed }) => (
|
||||
<Card style={{ padding: 14, flexDirection: 'row', alignItems: 'center', gap: 12, opacity: pressed ? 0.7 : m.active ? 1 : 0.55 }}>
|
||||
<View style={{ width: 46, height: 46, borderRadius: 23, backgroundColor: m.role === 'MANAGER' ? c.primarySoft : c.surface2, alignItems: 'center', justifyContent: 'center' }}>
|
||||
<T style={{ fontFamily: font.extrabold, fontSize: 18, color: m.role === 'MANAGER' ? c.primary : c.text3 }}>{m.displayName.charAt(0).toUpperCase()}</T>
|
||||
</View>
|
||||
<View style={{ flex: 1, gap: 2 }}>
|
||||
<T v="label" numberOfLines={1}>
|
||||
{m.displayName}
|
||||
{self ? ' (vous)' : ''}
|
||||
</T>
|
||||
<T v="muted" style={{ fontSize: 13 }}>
|
||||
{m.email} · {ROLE[m.role][0]}
|
||||
{m.active ? '' : ' · désactivé'}
|
||||
</T>
|
||||
<T v="muted" style={{ fontSize: 13 }} numberOfLines={1}>{m.email}</T>
|
||||
<View style={{ flexDirection: 'row', gap: 6, marginTop: 2 }}>
|
||||
<View style={{ paddingHorizontal: 8, paddingVertical: 2, borderRadius: 999, backgroundColor: m.role === 'MANAGER' ? c.primarySoft : c.surface2 }}>
|
||||
<T style={{ fontSize: 12, fontFamily: font.semibold, color: m.role === 'MANAGER' ? c.primary : c.text3 }}>{ROLE[m.role][0]}</T>
|
||||
</View>
|
||||
{!self && (
|
||||
<View style={{ flexDirection: 'row', gap: 8, flexWrap: 'wrap' }}>
|
||||
<Button
|
||||
label={m.role === 'MANAGER' ? 'Passer Employé' : 'Passer Dirigeant'}
|
||||
variant="secondary"
|
||||
onPress={() => run(() => api.patch(`/api/staff/team/${m.id}`, { role: m.role === 'MANAGER' ? 'EMPLOYEE' : 'MANAGER' }))}
|
||||
/>
|
||||
<Button label={m.active ? 'Désactiver' : 'Réactiver'} variant="secondary" onPress={() => run(() => api.patch(`/api/staff/team/${m.id}`, { active: !m.active }))} />
|
||||
<Button
|
||||
label="Nouveau mot de passe"
|
||||
variant="secondary"
|
||||
onPress={() =>
|
||||
Alert.alert('Nouveau mot de passe ?', `${m.displayName} sera déconnecté(e) de ses appareils.`, [
|
||||
{ text: 'Annuler', style: 'cancel' },
|
||||
{ text: 'Générer', onPress: () => run(async () => setCreated(await api.post<Member>(`/api/staff/team/${m.id}/reset-password`))) },
|
||||
])
|
||||
}
|
||||
/>
|
||||
{!m.active && (
|
||||
<View style={{ paddingHorizontal: 8, paddingVertical: 2, borderRadius: 999, backgroundColor: c.errBg }}>
|
||||
<T style={{ fontSize: 12, fontFamily: font.semibold, color: c.err }}>Désactivé</T>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
{!self && <T style={{ color: c.text3, fontSize: 22 }}>⋯</T>}
|
||||
</Card>
|
||||
)}
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue