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(null); const [error, setError] = useState(null); const [notice, setNotice] = useState(null); const reload = useCallback(() => { api.get(`/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 ?
{error}
:

Chargement…

; return ( <> ← Magasins

{store.name}

{store.subscription?.stripeSubscriptionId && store.subscription.status !== 'CANCELED' && ( {PLAN_LABEL[store.subscription.plan]} )}

{store.city} · {store.counts.cards} clients · {store.counts.staff} employés · {store.contactName}

{/* Étapes d'ouverture : le magasin s'ouvre seul quand les deux premières sont faites */}
  • {store.subscription?.status === 'ACTIVE' ? '✓' : '○'} Abonnement payé
  • {store.hasCard ? '✓' : '○'} Carte conçue
  • {store.status === 'ACTIVE' ? '✓' : '○'} Programme ouvert
{(store.status === 'DRAFT' || store.status === 'CLOSED') && ( )} {store.status === 'SUSPENDED' && ( )} {store.status === 'ACTIVE' && ( )} {store.status !== 'CLOSED' && ( )}
Lien d’inscription : {store.enrollUrl}
{store.status === 'SUSPENDED' && (
Magasin suspendu{store.billingSuspended ? ' pour impayé' : ''} : les scans et les nouvelles inscriptions sont refusés. {store.billingSuspended && <> Voir l'onglet Facturation.}
)} {error &&
{error}
} {notice &&
{notice}
} } /> { 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(); }} /> } /> } /> } /> } /> } /> } /> ); }