sokko-g/website/src/features/cards/admin/ShopPackContent.jsx
Shinuwa 22b397ebfa Document Sokko G's architecture and folders, and move JavaScript file headers to JSDoc @file blocks
Add ARCHITECTURE.md (layers, flows, folder map, glossary), CONTRIBUTING.md
(setup and step-by-step recipes) and a README in each main folder, with an
index of docs/. Convert the 511 JavaScript headers from "// Rôle :" lines to
JSDoc @file blocks, define a three-level header template in website/AGENTS.md
and check the header in tests/file-headers.test.mjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 09:42:13 +01:00

55 lines
3.6 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.

/**
* @file Sur la page du paquet de la boutique, rappelle d'où il tire ses cartes et règle la part de ses
* propres légendaires et mythiques.
*/
import { useState } from "react";
import { ApplyActions } from "./adminSettingForm.jsx";
import { inRange, parse, shopSettingSaver } from "./adminSettings.js";
// Mêmes règles que shopPackPools côté serveur : les collections ouvertes hors boutique, puis ses légendaires et mythiques tirables.
function shopPackSources(catalog, collection) {
const sources = catalog.collections.filter((item) => item.active && item.packCategory !== "shop");
const ownCards = new Set(catalog.cards.filter((card) => card.collectionId === collection.id).map((card) => card.id));
const own = catalog.editions.filter((edition) => ownCards.has(edition.cardId) && !edition.promotional && !edition.retired);
return { sources, legendaries: own.filter((edition) => edition.rarity === "legendary").length, mythics: own.filter((edition) => edition.rarity === "mythic").length };
}
function ShareForm({ setting, busy, save }) {
const [draft, setDraft] = useState(() => String(setting.shopPackShare));
const shopPackShare = parse(draft);
const valid = inRange(shopPackShare, 0, 100);
const changed = valid && shopPackShare !== setting.shopPackShare;
return <>
<label className="nebula-admin-shop-pack-share"><span>Part de ses cartes parmi les légendaires et mythiques (%)</span><input className="nds-input" type="number" inputMode="numeric" min="0" max="100" step="1" value={draft} disabled={busy} onChange={(event) => setDraft(event.target.value)} /></label>
{valid
? <p className="nebula-form-help" role="status">Quand une légendaire ou une mythique sort, {shopPackShare} % des tirages reviennent à ses propres cartes, quel que soit leur nombre, et {100 - shopPackShare} % aux collections ouvertes.</p>
: <p className="nebula-form-help" role="alert">Part entière de 0 à 100.</p>}
<ApplyActions
busy={busy}
changed={changed}
onCancel={() => setDraft(String(setting.shopPackShare))}
onApply={() => save({ shopPackShare })}
confirmTitle="Appliquer la nouvelle part ?"
confirmMessage="La part s’applique immédiatement aux prochains paquets achetés. Les cartes déjà obtenues ne changent pas."
/>
</>;
}
export function ShopPackContent({ catalog, collection, dashboard, busy, runMutation, refreshDashboard }) {
const setting = dashboard?.shopSetting;
const save = shopSettingSaver(setting, runMutation, refreshDashboard);
const { sources, legendaries, mythics } = shopPackSources(catalog, collection);
const plural = (count, word) => `${count} ${word}${count > 1 ? "s" : ""}`;
return <section className="nds-panel nebula-admin-shop-pack-content" aria-labelledby="nebula-admin-shop-pack-content-title">
<h3 id="nebula-admin-shop-pack-content-title">Contenu du paquet</h3>
<p className="nebula-form-help">Ce paquet est vendu dans la Boutique. Il tire ses cartes parmi toutes les collections ouvertes en ce moment, plus ses propres légendaires et mythiques.</p>
<dl className="nebula-admin-shop-pack-sources">
<div><dt>Collections ouvertes</dt><dd>{sources.length ? sources.map((item) => item.name).join(", ") : "Aucune : seules ses propres cartes peuvent sortir."}</dd></div>
<div><dt>Ses cartes tirables</dt><dd>{plural(legendaries, "légendaire")} et {plural(mythics, "mythique")}</dd></div>
</dl>
{setting
? <ShareForm key={setting.shopPackShare} setting={setting} busy={busy} save={save} />
: <p className="nebula-form-help" aria-busy="true">Chargement du réglage…</p>}
</section>;
}