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:
parent
55a0e62a3a
commit
5119d0ea24
7 changed files with 90 additions and 58 deletions
|
|
@ -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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="row between">
|
<div className="row between">
|
||||||
<h2>Employés</h2>
|
<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>
|
<button className="btn" onClick={() => formDialog.current?.showModal()}>+ Nouvel employé</button>
|
||||||
</div>
|
</div>
|
||||||
{error && <div className="alert error" role="alert">{error}</div>}
|
{error && <div className="alert error" role="alert">{error}</div>}
|
||||||
|
{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>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="table-wrap">
|
{staff.length === 0 ? (
|
||||||
<div className="table-scroll">
|
<section className="card" style={{ textAlign: 'center', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 12, padding: 40 }}>
|
||||||
<table style={{ minWidth: 720 }}>
|
<span className="staff-avatar big" aria-hidden="true">👥</span>
|
||||||
<thead>
|
<h3 style={{ margin: 0 }}>Aucun compte pour l’instant</h3>
|
||||||
<tr>
|
<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>
|
||||||
<th scope="col" style={{ paddingLeft: 24 }}>Nom</th>
|
<button className="btn" onClick={() => formDialog.current?.showModal()}>Créer le premier compte</button>
|
||||||
<th scope="col">E-mail</th>
|
</section>
|
||||||
<th scope="col">Rôle</th>
|
) : (
|
||||||
<th scope="col">Statut</th>
|
<div className="staff-grid">
|
||||||
<th scope="col"><span className="sr-only">Actions</span></th>
|
{sorted.map((u) => (
|
||||||
</tr>
|
<article key={u.id} className={`card staff-card${u.active ? '' : ' off'}`}>
|
||||||
</thead>
|
<div className="row" style={{ gap: 12, flexWrap: 'nowrap' }}>
|
||||||
<tbody>
|
<span className={`staff-avatar${u.role === 'MANAGER' ? ' mgr' : ''}`} aria-hidden="true">{u.displayName.charAt(0).toUpperCase()}</span>
|
||||||
{staff.map((u) => (
|
<div style={{ minWidth: 0 }}>
|
||||||
<tr key={u.id} style={{ opacity: u.active ? 1 : 0.6 }}>
|
<strong style={{ display: 'block', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{u.displayName}</strong>
|
||||||
<td style={{ paddingLeft: 24, fontWeight: 600 }}>{u.displayName}</td>
|
<span className="muted" style={{ fontSize: 14, display: 'block', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{u.email}</span>
|
||||||
<td>{u.email}</td>
|
</div>
|
||||||
<td>{ROLE_LABEL[u.role]}</td>
|
</div>
|
||||||
<td>{u.active ? <span className="badge ACTIVE">Actif</span> : <span className="badge DRAFT">Désactivé</span>}</td>
|
<div className="row" style={{ gap: 6 }}>
|
||||||
<td style={{ textAlign: 'right', whiteSpace: 'nowrap' }}>
|
<span className={`role-pill${u.role === 'MANAGER' ? ' mgr' : ''}`}>{ROLE_LABEL[u.role]}</span>
|
||||||
<button className="btn secondary small" onClick={() => reset(u)}>Nouveau mot de passe</button>{' '}
|
{u.active ? <span className="badge ACTIVE">Actif</span> : <span className="badge DRAFT">Désactivé</span>}
|
||||||
<button className="btn secondary small" onClick={() => toggle(u)}>{u.active ? 'Désactiver' : 'Réactiver'}</button>
|
<span className="muted" style={{ fontSize: 13 }}>depuis le {new Date(u.createdAt).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short', year: 'numeric' })}</span>
|
||||||
</td>
|
</div>
|
||||||
</tr>
|
<div className="row" style={{ gap: 8 }}>
|
||||||
))}
|
<button className="btn secondary small" onClick={() => switchRole(u)}>{u.role === 'MANAGER' ? 'Passer Employé' : 'Passer Dirigeant'}</button>
|
||||||
</tbody>
|
<button className="btn secondary small" onClick={() => reset(u)}>Nouveau mot de passe</button>
|
||||||
</table>
|
<button className="btn secondary small" onClick={() => toggle(u)}>{u.active ? 'Désactiver' : 'Réactiver'}</button>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
</div>
|
</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>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<dialog ref={formDialog} aria-labelledby="new-staff-title">
|
<dialog ref={formDialog} aria-labelledby="new-staff-title">
|
||||||
<NewStaffForm
|
<NewStaffForm
|
||||||
|
|
|
||||||
|
|
@ -252,3 +252,13 @@ tr.clickable:hover td { background: var(--primary-soft); }
|
||||||
.open-steps li.done { background: var(--ok-bg); color: var(--ok); }
|
.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 { 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; }
|
.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
|
|
@ -8,8 +8,8 @@
|
||||||
<title>Affichette — MonEspacePro</title>
|
<title>Affichette — MonEspacePro</title>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<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" />
|
<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>
|
<script type="module" crossorigin src="/assets/espace/index-CCcRvX8Z.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/espace/index-Bj5p9Bgz.css">
|
<link rel="stylesheet" crossorigin href="/assets/espace/index-MkZ3X9Gx.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
<title>Mon espace — MonEspacePro</title>
|
<title>Mon espace — MonEspacePro</title>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<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" />
|
<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>
|
<script type="module" crossorigin src="/assets/espace/index-CCcRvX8Z.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/espace/index-Bj5p9Bgz.css">
|
<link rel="stylesheet" crossorigin href="/assets/espace/index-MkZ3X9Gx.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
<title>Créer mon programme de fidélité — MonEspacePro</title>
|
<title>Créer mon programme de fidélité — MonEspacePro</title>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<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" />
|
<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>
|
<script type="module" crossorigin src="/assets/espace/index-CCcRvX8Z.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/espace/index-Bj5p9Bgz.css">
|
<link rel="stylesheet" crossorigin href="/assets/espace/index-MkZ3X9Gx.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue