Compare commits

..

2 commits

Author SHA1 Message Date
6968d26ce6 Admin : onglet Modules retravaillé
Chiffres clés (activés, disponibles, sur mesure), pictogramme par module,
interrupteur d'activation en un clic, chiffres du module en tuiles, réglages
et messages regroupés, barre d'enregistrement fixe signalant les
modifications non enregistrées.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 15:19:27 +02:00
5119d0ea24 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>
2026-10-07 15:14:43 +02:00
9 changed files with 225 additions and 138 deletions

View file

@ -23,6 +23,10 @@ export interface ModuleInfo {
stats?: Record<string, number | string | null> | null;
}
/** Pictogramme de chaque module (même que dans l'app). */
const ICON: Record<string, string> = { campaigns: '📣', reminders: '⏰', birthday: '🎂', reviews: '⭐', referral: '🤝', stats: '📊', whiteLabel: '🏷️' };
const isMessage = (f: FieldDef) => f.type === 'text' || f.type === 'textarea';
/** Origine du module pour ce magasin. */
function Origin({ m }: { m: ModuleInfo }) {
const [label, tone] =
@ -131,15 +135,33 @@ function ModulePanel({ storeId, storeName, initial, onChanged }: { storeId: stri
return (
<section className="card" style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
<div className="row between" style={{ alignItems: 'flex-start', gap: 12 }}>
<div style={{ flex: '1 1 320px' }}>
<div className="row" style={{ gap: 10, alignItems: 'center' }}>
<h2 style={{ margin: 0 }}>{m.name}</h2>
<Origin m={m} />
{m.available && <span className={`badge ${m.config.enabled ? 'ACTIVE' : 'DRAFT'}`}>{m.config.enabled ? 'Activé' : 'Désactivé'}</span>}
<div style={{ flex: '1 1 320px', display: 'flex', gap: 14 }}>
<span className={`mod-ic${m.available && m.config.enabled ? ' on' : ''}`} aria-hidden="true">{ICON[m.id] ?? '🧩'}</span>
<div>
<div className="row" style={{ gap: 10, alignItems: 'center' }}>
<h2 style={{ margin: 0 }}>{m.name}</h2>
<Origin m={m} />
</div>
<p className="muted" style={{ margin: '6px 0 0' }}>{m.description}</p>
</div>
<p className="muted" style={{ margin: '6px 0 0' }}>{m.description}</p>
</div>
<div className="row" style={{ gap: 8 }}>
{/* Interrupteur : active ou désactive sans ouvrir les réglages */}
{m.available && (
<label className="switch" title={m.config.enabled ? 'Désactiver le module' : 'Activer le module'}>
<input
type="checkbox"
checked={m.config.enabled}
disabled={busy}
onChange={(e) => {
const enabled = e.target.checked;
run(() => api.put<ModuleInfo>(base, { enabled }), enabled ? 'Module activé.' : 'Module désactivé.');
}}
/>
<span aria-hidden="true" />
<span className="sr-only">Module activé</span>
</label>
)}
<label className="sr-only" htmlFor={`ov-${m.id}`}>Disponibilité du module</label>
<select
id={`ov-${m.id}`}
@ -168,25 +190,33 @@ function ModulePanel({ storeId, storeName, initial, onChanged }: { storeId: stri
{open && (
<>
{!m.available && <div className="alert warn">Module non disponible pour ce magasin : ajoutez-le sur mesure ou changez de formule pour l'activer. Vous pouvez déjà préparer ses réglages.</div>}
<label style={{ display: 'flex', alignItems: 'center', gap: 10, fontWeight: 700 }}>
<input type="checkbox" checked={!!values.enabled} onChange={(e) => setValues({ ...values, enabled: e.target.checked })} />
Module activé
</label>
{m.fields.map((f) => (
<Field key={f.key} f={f} value={values[f.key]} onChange={(v) => setValues({ ...values, [f.key]: v })} />
))}
{m.stats && (
<div className="row" style={{ gap: 24 }}>
<div className="kpis">
{Object.entries(m.stats).map(([k, v]) => (
<div key={k}>
<div style={{ fontSize: 22, fontWeight: 800 }}>{v ?? '—'}</div>
<div className="muted" style={{ fontSize: 14 }}>{k}</div>
</div>
<div key={k} className="kpi"><b>{v ?? '—'}</b><span>{k}</span></div>
))}
</div>
)}
{(
[
['Réglages', m.fields.filter((f) => !isMessage(f)), 'mod-grid'],
['Messages', m.fields.filter(isMessage), 'mod-stack'],
] as const
).map(([title, fields, layout]) =>
fields.length ? (
<fieldset key={title} className="mod-group">
<legend>{title}</legend>
<div className={layout}>
{fields.map((f) => (
<Field key={f.key} f={f} value={values[f.key]} onChange={(v) => setValues({ ...values, [f.key]: v })} />
))}
</div>
</fieldset>
) : null,
)}
{m.id === 'stats' && <Link to="../statistiques">Voir les statistiques du magasin →</Link>}
<div className="row" style={{ gap: 8, justifyContent: 'flex-end' }}>
<div className={`row mod-save${dirty ? ' dirty' : ''}`} style={{ gap: 8, justifyContent: 'flex-end' }}>
{dirty && <span className="muted" style={{ marginRight: 'auto', fontSize: 14 }}>Modifications non enregistrées</span>}
{dirty && <button type="button" className="btn secondary" disabled={busy} onClick={() => setValues(m.config)}>Annuler</button>}
<button type="button" className="btn" disabled={busy || !dirty} onClick={() => run(() => api.put<ModuleInfo>(base, values), 'Réglages enregistrés.')}>
{busy ? 'Enregistrement…' : 'Enregistrer'}
@ -210,11 +240,18 @@ export function ModulesTab({ storeId, storeName }: { storeId: string; storeName:
if (!list) return error ? <div className="alert error">{error}</div> : <p className="muted">Chargement…</p>;
const active = list.filter((m) => m.available && m.config.enabled).length;
const available = list.filter((m) => m.available).length;
const custom = list.filter((m) => m.override !== null).length;
return (
<>
<div className="kpis">
<div className="kpi ok"><b>{active}</b><span>modules activés</span></div>
<div className="kpi"><b>{available} / {list.length}</b><span>disponibles pour ce magasin</span></div>
<div className="kpi"><b>{custom}</b><span>ajout(s) ou retrait(s) sur mesure</span></div>
</div>
<p className="muted" style={{ margin: 0 }}>
{active} module(s) actif(s) sur {list.length}. Chaque module est inclus ou non dans la formule ; vous pouvez l'ajouter ou le retirer sur mesure,
et tous ses textes et réglages sont personnalisables. Le dirigeant peut aussi les régler depuis l'app Pro.
Chaque module est inclus ou non dans la formule ; vous pouvez l’ajouter ou le retirer sur mesure. L’interrupteur l’active d’un clic,
« Personnaliser » ouvre tous ses textes et réglages. Le dirigeant peut aussi les régler depuis l’app MonEspacePro.
</p>
{list.map((m) => (
<ModulePanel key={m.id} storeId={storeId} storeName={storeName} initial={m} onChanged={load} />

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">
<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>
</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">
<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>
{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>
{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">
<NewStaffForm

View file

@ -252,3 +252,31 @@ 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); }
/* ── Onglet Modules ── */
.mod-ic { width: 48px; height: 48px; border-radius: 14px; background: var(--surface-2); display: grid; place-items: center; font-size: 24px; flex: none; }
.mod-ic.on { background: var(--primary-soft); }
.mod-group { border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px 18px; margin: 0; }
.mod-group legend { padding: 0 6px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.mod-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px 24px; }
.mod-stack { display: flex; flex-direction: column; gap: 16px; }
.mod-save { position: sticky; bottom: 0; background: var(--surface); padding: 12px 0 0; border-top: 1px solid transparent; }
.mod-save.dirty { border-top-color: var(--border); }
.switch { position: relative; display: inline-block; width: 52px; height: 30px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span[aria-hidden] { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background .15s; }
.switch span[aria-hidden]::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgb(0 0 0 / .25); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(22px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch input:disabled + span { opacity: .5; }

File diff suppressed because one or more lines are too long

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-Cx3ijWuE.js"></script>
<link rel="stylesheet" crossorigin href="/assets/espace/index-DVd76xPZ.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-Cx3ijWuE.js"></script>
<link rel="stylesheet" crossorigin href="/assets/espace/index-DVd76xPZ.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-Cx3ijWuE.js"></script>
<link rel="stylesheet" crossorigin href="/assets/espace/index-DVd76xPZ.css">
</head>
<body>
<div id="root"></div>