Admin : onglet Employés retravaillé

Comptes en cartes (initiale, e-mail, rôle, état, ancienneté), Dirigeants en
tête, changement de rôle Employé / Dirigeant, alerte quand aucun Dirigeant
n'est actif, état vide avec création du premier compte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tony AVERTY 2026-10-07 15:14:43 +02:00
parent 55a0e62a3a
commit 5119d0ea24
7 changed files with 90 additions and 58 deletions

View file

@ -40,48 +40,70 @@ export function StaffTab({ storeId }: { storeId: string }) {
}
}
async function switchRole(u: StaffUser) {
const next: StaffRole = u.role === 'MANAGER' ? 'EMPLOYEE' : 'MANAGER';
if (!window.confirm(`${u.displayName} devient ${ROLE_LABEL[next]}. Ses sessions ouvertes seront fermées.`)) return;
try {
await api.patch(`${base}/${u.id}`, { role: next });
reload();
} catch (e) {
setError((e as Error).message);
}
}
const active = staff.filter((u) => u.active);
const managers = active.filter((u) => u.role === 'MANAGER').length;
// Actifs d'abord, Dirigeants en tête.
const sorted = [...staff].sort((a, b) => Number(b.active) - Number(a.active) || a.role.localeCompare(b.role) || a.displayName.localeCompare(b.displayName));
return (
<>
<div className="row between">
<div>
<h2>Employés</h2>
<p className="muted" style={{ margin: 0 }}>
{active.length} compte{active.length > 1 ? 's' : ''} actif{active.length > 1 ? 's' : ''} · {managers} dirigeant{managers > 1 ? 's' : ''}
</p>
</div>
<button className="btn" onClick={() => formDialog.current?.showModal()}>+ Nouvel employé</button>
</div>
{error && <div className="alert error" role="alert">{error}</div>}
<div className="table-wrap">
<div className="table-scroll">
<table style={{ minWidth: 720 }}>
<thead>
<tr>
<th scope="col" style={{ paddingLeft: 24 }}>Nom</th>
<th scope="col">E-mail</th>
<th scope="col">Rôle</th>
<th scope="col">Statut</th>
<th scope="col"><span className="sr-only">Actions</span></th>
</tr>
</thead>
<tbody>
{staff.map((u) => (
<tr key={u.id} style={{ opacity: u.active ? 1 : 0.6 }}>
<td style={{ paddingLeft: 24, fontWeight: 600 }}>{u.displayName}</td>
<td>{u.email}</td>
<td>{ROLE_LABEL[u.role]}</td>
<td>{u.active ? <span className="badge ACTIVE">Actif</span> : <span className="badge DRAFT">Désactivé</span>}</td>
<td style={{ textAlign: 'right', whiteSpace: 'nowrap' }}>
<button className="btn secondary small" onClick={() => reset(u)}>Nouveau mot de passe</button>{' '}
<button className="btn secondary small" onClick={() => toggle(u)}>{u.active ? 'Désactiver' : 'Réactiver'}</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
{staff.length === 0 && (
<p className="muted" style={{ padding: 24, margin: 0, textAlign: 'center' }}>
Aucun employé. Créez au moins un dirigeant pour que le magasin puisse utiliser l'app Pro.
</p>
{staff.length > 0 && managers === 0 && (
<div className="alert warn">Aucun Dirigeant actif : personne ne peut configurer le magasin depuis l’app. Créez un compte Dirigeant ou changez le rôle d’un employé.</div>
)}
{staff.length === 0 ? (
<section className="card" style={{ textAlign: 'center', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 12, padding: 40 }}>
<span className="staff-avatar big" aria-hidden="true">👥</span>
<h3 style={{ margin: 0 }}>Aucun compte pour l’instant</h3>
<p className="muted" style={{ margin: 0, maxWidth: 420 }}>Créez au moins un Dirigeant : il pourra ensuite ajouter lui-même son équipe depuis l’app MonEspacePro.</p>
<button className="btn" onClick={() => formDialog.current?.showModal()}>Créer le premier compte</button>
</section>
) : (
<div className="staff-grid">
{sorted.map((u) => (
<article key={u.id} className={`card staff-card${u.active ? '' : ' off'}`}>
<div className="row" style={{ gap: 12, flexWrap: 'nowrap' }}>
<span className={`staff-avatar${u.role === 'MANAGER' ? ' mgr' : ''}`} aria-hidden="true">{u.displayName.charAt(0).toUpperCase()}</span>
<div style={{ minWidth: 0 }}>
<strong style={{ display: 'block', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{u.displayName}</strong>
<span className="muted" style={{ fontSize: 14, display: 'block', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{u.email}</span>
</div>
</div>
<div className="row" style={{ gap: 6 }}>
<span className={`role-pill${u.role === 'MANAGER' ? ' mgr' : ''}`}>{ROLE_LABEL[u.role]}</span>
{u.active ? <span className="badge ACTIVE">Actif</span> : <span className="badge DRAFT">Désactivé</span>}
<span className="muted" style={{ fontSize: 13 }}>depuis le {new Date(u.createdAt).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short', year: 'numeric' })}</span>
</div>
<div className="row" style={{ gap: 8 }}>
<button className="btn secondary small" onClick={() => switchRole(u)}>{u.role === 'MANAGER' ? 'Passer Employé' : 'Passer Dirigeant'}</button>
<button className="btn secondary small" onClick={() => reset(u)}>Nouveau mot de passe</button>
<button className="btn secondary small" onClick={() => toggle(u)}>{u.active ? 'Désactiver' : 'Réactiver'}</button>
</div>
</article>
))}
</div>
)}
<dialog ref={formDialog} aria-labelledby="new-staff-title">
<NewStaffForm

View file

@ -252,3 +252,13 @@ tr.clickable:hover td { background: var(--primary-soft); }
.open-steps li.done { background: var(--ok-bg); color: var(--ok); }
.copy-line { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.copy-line code { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; word-break: break-all; }
/* ── Onglet Employés ── */
.staff-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.staff-card { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.staff-card.off { opacity: .6; }
.staff-avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--surface-2); color: var(--text-3); font-weight: 800; font-size: 18px; display: grid; place-items: center; flex: none; }
.staff-avatar.mgr { background: var(--primary-soft); color: var(--primary); }
.staff-avatar.big { width: 64px; height: 64px; font-size: 30px; background: var(--primary-soft); }
.role-pill { display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border-radius: 999px; font-size: 14px; font-weight: 700; background: var(--surface-2); color: var(--text-2); }
.role-pill.mgr { background: var(--primary-soft); color: var(--primary); }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -8,8 +8,8 @@
<title>Affichette — MonEspacePro</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link href="https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700;800&display=swap" rel="stylesheet" />
<script type="module" crossorigin src="/assets/espace/index-DOsOn4Cf.js"></script>
<link rel="stylesheet" crossorigin href="/assets/espace/index-Bj5p9Bgz.css">
<script type="module" crossorigin src="/assets/espace/index-CCcRvX8Z.js"></script>
<link rel="stylesheet" crossorigin href="/assets/espace/index-MkZ3X9Gx.css">
</head>
<body>
<div id="root"></div>

View file

@ -8,8 +8,8 @@
<title>Mon espace — MonEspacePro</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link href="https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700;800&display=swap" rel="stylesheet" />
<script type="module" crossorigin src="/assets/espace/index-DOsOn4Cf.js"></script>
<link rel="stylesheet" crossorigin href="/assets/espace/index-Bj5p9Bgz.css">
<script type="module" crossorigin src="/assets/espace/index-CCcRvX8Z.js"></script>
<link rel="stylesheet" crossorigin href="/assets/espace/index-MkZ3X9Gx.css">
</head>
<body>
<div id="root"></div>

View file

@ -7,8 +7,8 @@
<title>Créer mon programme de fidélité — MonEspacePro</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link href="https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700;800&display=swap" rel="stylesheet" />
<script type="module" crossorigin src="/assets/espace/index-DOsOn4Cf.js"></script>
<link rel="stylesheet" crossorigin href="/assets/espace/index-Bj5p9Bgz.css">
<script type="module" crossorigin src="/assets/espace/index-CCcRvX8Z.js"></script>
<link rel="stylesheet" crossorigin href="/assets/espace/index-MkZ3X9Gx.css">
</head>
<body>
<div id="root"></div>