Liste : chiffres clés (ouverts, en cours d'ouverture, impayés, cartes clients), lignes entièrement cliquables avec survol. Fiche magasin : en-tête en carte avec initiale, contact, étapes d'ouverture (abonnement payé, carte conçue, programme ouvert) et lien d'inscription à copier. L'API indique si la carte est conçue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
136 lines
6.3 KiB
TypeScript
136 lines
6.3 KiB
TypeScript
import { useCallback, useEffect, useState } from 'react';
|
||
import { Link, NavLink, Navigate, Route, Routes, useParams } from 'react-router-dom';
|
||
import { api, PLAN_LABEL, StoreDetail, StoreStatus } from '../api';
|
||
import { StatusBadge } from '../components/Layout';
|
||
import { StoreForm } from '../components/StoreForm';
|
||
import { CardWizard } from './CardWizard';
|
||
import { StaffTab } from './StaffTab';
|
||
import { BillingTab } from './BillingTab';
|
||
import { ModulesTab } from './ModulesTab';
|
||
import { StatsTab } from './StatsTab';
|
||
|
||
const TABS = [
|
||
['infos', 'Infos'],
|
||
['carte', 'Carte de fidélité'],
|
||
['employes', 'Employés'],
|
||
['modules', 'Modules'],
|
||
['statistiques', 'Statistiques'],
|
||
['facturation', 'Facturation'],
|
||
] as const;
|
||
|
||
export function StorePage() {
|
||
const { id } = useParams<{ id: string }>();
|
||
const [store, setStore] = useState<StoreDetail | null>(null);
|
||
const [error, setError] = useState<string | null>(null);
|
||
const [notice, setNotice] = useState<string | null>(null);
|
||
|
||
const reload = useCallback(() => {
|
||
api.get<StoreDetail>(`/api/admin/stores/${id}`).then(setStore).catch((e) => setError(e.message));
|
||
}, [id]);
|
||
useEffect(reload, [reload]);
|
||
|
||
async function changeStatus(status: StoreStatus, confirmText?: string) {
|
||
if (confirmText && !window.confirm(confirmText)) return;
|
||
setError(null);
|
||
try {
|
||
await api.patch(`/api/admin/stores/${id}/status`, { status });
|
||
reload();
|
||
} catch (e) {
|
||
setError((e as Error).message);
|
||
}
|
||
}
|
||
|
||
if (!store) return error ? <div className="alert error">{error}</div> : <p className="muted">Chargement…</p>;
|
||
|
||
return (
|
||
<>
|
||
<Link to="/magasins">← Magasins</Link>
|
||
<section className="card store-head">
|
||
<div className="store-id">
|
||
<span className="store-avatar" aria-hidden="true">{store.name.charAt(0).toUpperCase()}</span>
|
||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||
<div className="row" style={{ gap: 12 }}>
|
||
<h1 style={{ fontSize: 28, lineHeight: '34px' }}>{store.name}</h1>
|
||
<StatusBadge status={store.status} />
|
||
{store.subscription?.stripeSubscriptionId && store.subscription.status !== 'CANCELED' && (
|
||
<NavLink to="facturation" className="badge DRAFT" style={{ textDecoration: 'none' }} title="Formule d'abonnement">
|
||
{PLAN_LABEL[store.subscription.plan]}
|
||
</NavLink>
|
||
)}
|
||
</div>
|
||
<p className="muted" style={{ margin: 0 }}>
|
||
{store.city} · {store.counts.cards} clients · {store.counts.staff} employés · {store.contactName}
|
||
</p>
|
||
{/* Étapes d'ouverture : le magasin s'ouvre seul quand les deux premières sont faites */}
|
||
<ul className="open-steps" aria-label="Étapes d’ouverture">
|
||
<li className={store.subscription?.status === 'ACTIVE' ? 'done' : ''}>{store.subscription?.status === 'ACTIVE' ? '✓' : '○'} Abonnement payé</li>
|
||
<li className={store.hasCard ? 'done' : ''}>{store.hasCard ? '✓' : '○'} Carte conçue</li>
|
||
<li className={store.status === 'ACTIVE' ? 'done' : ''}>{store.status === 'ACTIVE' ? '✓' : '○'} Programme ouvert</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div className="row" style={{ gap: 8 }}>
|
||
{(store.status === 'DRAFT' || store.status === 'CLOSED') && (
|
||
<button className="btn" onClick={() => changeStatus('ACTIVE')}>Activer</button>
|
||
)}
|
||
{store.status === 'SUSPENDED' && (
|
||
<button className="btn" onClick={() => changeStatus('ACTIVE')}>Réactiver</button>
|
||
)}
|
||
{store.status === 'ACTIVE' && (
|
||
<button className="btn secondary" onClick={() => changeStatus('SUSPENDED', 'Suspendre ce magasin ? Les employés ne pourront plus scanner.')}>
|
||
Suspendre
|
||
</button>
|
||
)}
|
||
{store.status !== 'CLOSED' && (
|
||
<button className="btn secondary" onClick={() => changeStatus('CLOSED', 'Fermer ce magasin ?')}>Fermer</button>
|
||
)}
|
||
</div>
|
||
<div className="copy-line" style={{ flexBasis: '100%' }}>
|
||
<span className="muted">Lien d’inscription :</span>
|
||
<code>{store.enrollUrl}</code>
|
||
<button type="button" className="btn secondary small" onClick={() => navigator.clipboard?.writeText(store.enrollUrl).then(() => setNotice('Lien copié.'))}>Copier</button>
|
||
</div>
|
||
</section>
|
||
|
||
{store.status === 'SUSPENDED' && (
|
||
<div className="alert warn" role="status">
|
||
Magasin suspendu{store.billingSuspended ? ' pour impayé' : ''} : les scans et les nouvelles inscriptions sont refusés.
|
||
{store.billingSuspended && <> Voir l'onglet <NavLink to="facturation">Facturation</NavLink>.</>}
|
||
</div>
|
||
)}
|
||
{error && <div className="alert error" role="alert">{error}</div>}
|
||
{notice && <div className="alert ok" role="status">{notice}</div>}
|
||
|
||
<nav className="tabs" aria-label="Sections du magasin">
|
||
{TABS.map(([path, label]) => (
|
||
<NavLink key={path} to={path}>{label}</NavLink>
|
||
))}
|
||
</nav>
|
||
|
||
<Routes>
|
||
<Route index element={<Navigate to="infos" replace />} />
|
||
<Route
|
||
path="infos"
|
||
element={
|
||
<StoreForm
|
||
key={store.id}
|
||
initial={store}
|
||
submitLabel="Enregistrer"
|
||
onSubmit={async (v) => {
|
||
const { name, siret, addressLine, postalCode, city, contactName, contactEmail, contactPhone, maxAmountEuros, minScanIntervalMin } = v;
|
||
await api.patch(`/api/admin/stores/${id}`, { name, siret, addressLine, postalCode, city, contactName, contactEmail, contactPhone, maxAmountEuros, minScanIntervalMin });
|
||
setNotice('Modifications enregistrées.');
|
||
reload();
|
||
}}
|
||
/>
|
||
}
|
||
/>
|
||
<Route path="carte" element={<CardWizard store={store} onSaved={reload} />} />
|
||
<Route path="employes" element={<StaffTab storeId={store.id} />} />
|
||
<Route path="modules" element={<ModulesTab storeId={store.id} storeName={store.name} />} />
|
||
<Route path="statistiques" element={<StatsTab storeId={store.id} storeSlug={store.slug} />} />
|
||
<Route path="facturation" element={<BillingTab storeId={store.id} contactEmail={store.contactEmail} onChange={reload} />} />
|
||
</Routes>
|
||
</>
|
||
);
|
||
}
|