sokko-g/website/src/features/cards/admin/AdminPanel.jsx
Shinuwa 4d05d812c5 Split the Guild administration into tabs and sell Éclats and openings by quantity in the shop
The Guild administration now has a tab per quest. The expedition settings sit behind a status band (open or close, today's activity) and four themed tabs, with units inside the fields, the default value shown, and one sticky apply bar that lists every change before confirming.

The Pont des Veilleurs leaves the expedition page and becomes the « Éclats d’étoile » shop item, priced from Administration › Boutique. Openings and Éclats are bought by quantity: a number field capped by the stardust the player actually has, and a full-width button that shows the total cost. Stardust and Éclats get their own SVG icons, aligned with the text around them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 15:39:45 +01:00

96 lines
4.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Rôle : assemble la navigation et les sections du tableau de bord d'administration Sokko TCG.
import { useEffect, useState } from "react";
import { CardsAccount, CardsDashboardLayout } from "../CardsDashboard.jsx";
import { formatRelative } from "./adminFormat.js";
import { AdminCollections } from "./AdminCollections.jsx";
import { AdminDistributions } from "./AdminDistributions.jsx";
import { AdminGuild } from "./AdminGuild.jsx";
import { AdminHistory } from "./AdminHistory.jsx";
import { AdminOverview } from "./AdminOverview.jsx";
import { AdminShop } from "./AdminShop.jsx";
import { AdminVisualLab } from "./AdminVisualLab.jsx";
import { useCatalogLookup } from "./catalogLookup.js";
import { useAdminDashboard } from "./useAdminDashboard.js";
// Les sections qui agissent sur le jeu, l'Atelier visuel à part (un bac à sable où rien n'est enregistré), puis le journal de ces actions.
const ADMIN_NAVIGATION = [
[["overview", "Vue d’ensemble"], ["collections", "Collections"], ["codes", "Codes cadeaux"], ["shop", "Boutique"], ["guild", "Guilde"]],
[["visual-lab", "Atelier visuel"]],
[["history", "Historique"]]
];
const SECTION_IDS = new Set(ADMIN_NAVIGATION.flat().map(([id]) => id));
// Anciennes adresses conservées pour les favoris existants.
const SECTION_ALIASES = { players: "overview", cards: "collections", catalog: "collections", packs: "collections", distributions: "codes", "mythic-styles": "visual-lab", "opening-effects": "visual-lab" };
function resolveAdminSection(section) {
const resolved = SECTION_ALIASES[section] || section;
return SECTION_IDS.has(resolved) ? resolved : "overview";
}
function useNow(intervalMs) {
const [now, setNow] = useState(() => Date.now());
useEffect(() => {
const timer = window.setInterval(() => setNow(Date.now()), intervalMs);
return () => window.clearInterval(timer);
}, [intervalMs]);
return now;
}
export function AdminPanel({ catalog, state, runMutation, busy, section, subsection = "", onCatalogChange, backLabel = "Retour au jeu", onLogout = null }) {
const activeSection = resolveAdminSection(section);
const lookup = useCatalogLookup(catalog);
const { dashboard, loading, error, refresh } = useAdminDashboard();
const now = useNow(30_000);
async function mutateCatalog(action) {
const result = await runMutation(action);
if (result?.catalog) {
onCatalogChange?.(result.catalog);
void refresh();
}
return result;
}
// Les campagnes vivent dans les données du tableau de bord : on les recharge après chaque modification.
async function mutateCampaigns(action) {
const result = await runMutation(action);
if (result) void refresh();
return result;
}
const shared = { catalog, lookup, state, dashboard, dashboardLoading: loading, refreshDashboard: refresh, runMutation, busy, now };
return <section className="nebula-dashboard" aria-labelledby="nebula-admin-title">
<header className="nds-panel nebula-admin-heading">
<div className="nebula-admin-title">
<span className="nebula-admin-title-icon" aria-hidden="true"><span className="ui-icon nav-icon-cards" /></span>
<div>
<p className="eyebrow">Sokko TCG · Administration</p>
<h1 id="nebula-admin-title">Tableau de bord Sokko TCG</h1>
<p className="nebula-admin-refresh">
<span role="status">{loading ? "Actualisation…" : dashboard?.generatedAt ? `Données mises à jour ${formatRelative(dashboard.generatedAt, Math.max(now, dashboard.generatedAt))}` : "Chargement des données…"}</span>
<button className="nds-button" data-size="xs" data-variant="secondary" type="button" disabled={loading} onClick={refresh}>Actualiser</button>
</p>
</div>
</div>
<CardsAccount player={state.player} onLogout={onLogout} />
</header>
{error && <p className="nds-inline-notice" data-variant="danger" role="alert">{error}</p>}
<CardsDashboardLayout
label="Sections de l’administration"
groups={ADMIN_NAVIGATION}
active={activeSection}
hrefFor={(id) => `#/cards/admin/${id}`}
switchLink={{ href: "#/cards", label: backLabel }}
busy={loading}
>
{activeSection === "overview" && <AdminOverview {...shared} />}
{activeSection === "collections" && <AdminCollections {...shared} mutateCatalog={mutateCatalog} collectionId={subsection} />}
{activeSection === "visual-lab" && <AdminVisualLab catalog={catalog} lookup={lookup} />}
{activeSection === "history" && <AdminHistory catalog={catalog} refreshedAt={dashboard?.generatedAt} />}
{activeSection === "codes" && <AdminDistributions {...shared} mutateCampaigns={mutateCampaigns} />}
{activeSection === "shop" && <AdminShop {...shared} refreshDashboard={refresh} />}
{activeSection === "guild" && <AdminGuild {...shared} refreshDashboard={refresh} tab={subsection} />}
</CardsDashboardLayout>
</section>;
}