Add campaign filter and duplication, pack activity, and gift pack rate fallback
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
048d9a0c91
commit
99724cb6ba
8 changed files with 121 additions and 10 deletions
|
|
@ -30,6 +30,15 @@ function CollectionBadges({ collection }) {
|
|||
return <div className="nebula-admin-collection-badges"><span className="nds-badge" data-variant={collection.packCategory === "permanent" ? "neutral" : "gold"}>{{ event: "Événement", shop: "Boutique", expedition: "Expéditions" }[collection.packCategory] || "Permanente"}</span><span className="nds-badge" data-variant={collection.active ? "success" : "neutral"}>{collection.active ? "Ouverte" : "Fermée"}</span></div>;
|
||||
}
|
||||
|
||||
// Ouvertures du paquet sur 7 jours, en précisant la part des paquets offerts.
|
||||
function PackActivity({ activity }) {
|
||||
const openings = activity?.openings || 0;
|
||||
const gifted = activity?.gifted || 0;
|
||||
return <span className="nebula-admin-pack-activity" data-empty={openings ? undefined : ""}>
|
||||
<b>{openings.toLocaleString("fr-FR")}</b> {openings > 1 ? "ouvertures" : "ouverture"} sur 7 jours{gifted > 0 && <small> · dont {gifted.toLocaleString("fr-FR")} {gifted > 1 ? "offertes" : "offerte"}</small>}
|
||||
</span>;
|
||||
}
|
||||
|
||||
function CollectionsIndex({ catalog, lookup, dashboard, busy, runMutation, refreshDashboard }) {
|
||||
return <section className="nebula-admin-collections" aria-labelledby="nebula-admin-collections-title">
|
||||
<RechargeSetting key={dashboard?.rechargeSetting?.intervalMs || 0} setting={dashboard?.rechargeSetting} busy={busy} runMutation={runMutation} refreshDashboard={refreshDashboard} />
|
||||
|
|
@ -48,6 +57,7 @@ function CollectionsIndex({ catalog, lookup, dashboard, busy, runMutation, refre
|
|||
<span data-rarity="mythic"><b>{activeMythics}</b><small>{activeMythics > 1 ? "mythiques tirables" : "mythique tirable"}</small></span>
|
||||
</span>
|
||||
<span className="nebula-admin-rarity-counts" aria-label={`Variations par rareté de ${collection.name}`}>{byRarity.map(({ rarity, count }) => <span key={rarity.id} data-rarity={rarity.id}><small>{rarity.label}</small><b>{count}</b></span>)}</span>
|
||||
{collection.packCategory !== "expedition" && dashboard && <PackActivity activity={dashboard.packActivity7d?.[collection.id]} />}
|
||||
<span className="nebula-admin-collection-open" aria-hidden="true">Voir la collection →</span>
|
||||
</span>
|
||||
</a>;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ const plural = (count, singular, pluralForm = `${singular}s`) => `${count.toLoca
|
|||
|
||||
const isExpired = (campaign, now) => campaign.expiresAt != null && campaign.expiresAt <= now;
|
||||
|
||||
// Une campagne est terminée quand son code ne sert plus : révoquée, expirée ou épuisée.
|
||||
const isEnded = (campaign, now) => Boolean(campaign.revokedAt) || isExpired(campaign, now) || (campaign.maxClaims != null && campaign.claimedCount >= campaign.maxClaims);
|
||||
const CAMPAIGN_FILTERS = [["all", "Toutes"], ["active", "En cours"], ["ended", "Terminées"]];
|
||||
|
||||
function campaignStatus(campaign, now) {
|
||||
if (campaign.revokedAt) return ["Révoquée", "neutral"];
|
||||
if (isExpired(campaign, now)) return ["Expirée", "neutral"];
|
||||
|
|
@ -211,8 +215,31 @@ function initialDraft() {
|
|||
};
|
||||
}
|
||||
|
||||
function CampaignForm({ catalog, lookup, campaigns, mutateCampaigns, busy, now, onCreated, onCancel }) {
|
||||
const [draft, setDraft] = useState(initialDraft);
|
||||
// Brouillon d'une copie : même nom, même récompense, même limite et même durée de validité ; le code reste à choisir.
|
||||
function duplicateDraft(campaign, catalog) {
|
||||
const items = campaign.reward?.items || [];
|
||||
const cards = items.filter((item) => item.type === "card").map((item) => ({ editionId: item.editionId }));
|
||||
const packs = items.filter((item) => item.type === "pack").map((item) => {
|
||||
const pack = newPack(catalog);
|
||||
const guarantee = item.guarantee;
|
||||
return {
|
||||
...pack, collectionId: item.collectionId, quantity: clampQuantity(item.quantity),
|
||||
customRates: Boolean(item.rarityWeights),
|
||||
weights: item.rarityWeights ? { ...pack.weights, ...Object.fromEntries(Object.entries(item.rarityWeights).map(([id, weight]) => [id, String(weight)])) } : pack.weights,
|
||||
guaranteeType: guarantee?.type || "none", guaranteeCount: guarantee?.count ?? pack.guaranteeCount,
|
||||
guaranteeRarity: guarantee?.rarity ?? pack.guaranteeRarity, guaranteeEditionId: guarantee?.editionId ?? ""
|
||||
};
|
||||
});
|
||||
const duration = campaign.expiresAt == null ? null : Math.max(campaign.expiresAt - campaign.createdAt, 60 * 60 * 1000);
|
||||
return {
|
||||
...initialDraft(), name: campaign.name, cardsOpen: cards.length > 0, cards, packs,
|
||||
unlimited: campaign.maxClaims == null, maxClaims: String(campaign.maxClaims ?? 10),
|
||||
noExpiry: duration === null, expiresAt: toDateTimeLocal(Date.now() + (duration ?? DEFAULT_DURATION_MS))
|
||||
};
|
||||
}
|
||||
|
||||
function CampaignForm({ catalog, lookup, campaigns, mutateCampaigns, busy, now, source, onCreated, onCancel }) {
|
||||
const [draft, setDraft] = useState(() => (source ? duplicateDraft(source, catalog) : initialDraft()));
|
||||
const update = (patch) => setDraft((current) => ({ ...current, ...patch }));
|
||||
const reward = { items: [
|
||||
...draft.cards.map((card) => ({ type: "card", editionId: card.editionId, quantity: 1 })),
|
||||
|
|
@ -248,7 +275,7 @@ function CampaignForm({ catalog, lookup, campaigns, mutateCampaigns, busy, now,
|
|||
}
|
||||
}}>
|
||||
<div className="nds-section-heading nebula-admin-panel-heading">
|
||||
<h3 id="nebula-admin-create-title">Nouvelle campagne</h3>
|
||||
<h3 id="nebula-admin-create-title">{source ? `Copie de « ${source.name} »` : "Nouvelle campagne"}</h3>
|
||||
<button className="nds-button" data-size="sm" data-variant="secondary" type="button" onClick={onCancel}>Annuler</button>
|
||||
</div>
|
||||
<fieldset className="nebula-admin-campaign-step">
|
||||
|
|
@ -344,17 +371,29 @@ export function AdminDistributions({ catalog, lookup, dashboard, mutateCampaigns
|
|||
const [created, setCreated] = useState(null);
|
||||
const [openId, setOpenId] = useState(null);
|
||||
const [pendingRevoke, setPendingRevoke] = useState(null);
|
||||
const [filter, setFilter] = useState("all");
|
||||
const counts = { all: campaigns.length, ended: campaigns.filter((campaign) => isEnded(campaign, now)).length };
|
||||
counts.active = counts.all - counts.ended;
|
||||
const shown = filter === "all" ? campaigns : campaigns.filter((campaign) => isEnded(campaign, now) === (filter === "ended"));
|
||||
// `creating` vaut false, true (nouvelle campagne) ou la campagne à dupliquer ; la clé recrée le formulaire à chaque copie.
|
||||
const startCreating = (source) => { setCreating(source || true); setCreated(null); };
|
||||
|
||||
// La liste d'abord ; le formulaire s'ouvre à la demande et se referme après la création.
|
||||
return <>
|
||||
<div className="nds-section-heading nebula-admin-section-heading nebula-admin-distributions-heading">
|
||||
<h3 id="nebula-campaign-list-title">Campagnes <span className="nds-badge" data-variant="neutral">{campaigns.length}</span></h3>
|
||||
{!creating && <button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={() => { setCreating(true); setCreated(null); }}>+ Nouvelle campagne</button>}
|
||||
{!creating && <button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={() => startCreating(null)}>+ Nouvelle campagne</button>}
|
||||
</div>
|
||||
{created && <CreatedCampaign key={created.id} campaign={created} onClose={() => setCreated(null)} />}
|
||||
{creating && <CampaignForm catalog={catalog} lookup={lookup} campaigns={campaigns} mutateCampaigns={mutateCampaigns} busy={busy} now={now} onCancel={() => setCreating(false)} onCreated={(campaign) => { setCreating(false); setCreated(campaign); }} />}
|
||||
{creating && <CampaignForm key={creating === true ? "new" : `copy-${creating.id}`} catalog={catalog} lookup={lookup} campaigns={campaigns} mutateCampaigns={mutateCampaigns} busy={busy} now={now}
|
||||
source={creating === true ? null : creating} onCancel={() => setCreating(false)}
|
||||
onCreated={(campaign) => { setCreating(false); setCreated(campaign); if (filter === "ended") setFilter("all"); }} />}
|
||||
<section aria-labelledby="nebula-campaign-list-title">
|
||||
{campaigns.length ? <div className="nebula-campaign-list">{campaigns.map((campaign) => {
|
||||
{campaigns.length > 0 && <div className="nds-toolbar nebula-campaign-filter" role="group" aria-label="Afficher les campagnes">
|
||||
{CAMPAIGN_FILTERS.map(([id, label]) => <button key={id} className="nds-button" data-size="sm" data-variant={filter === id ? "primary" : "secondary"} type="button" aria-pressed={filter === id} onClick={() => setFilter(id)}>{label} ({counts[id].toLocaleString("fr-FR")})</button>)}
|
||||
</div>}
|
||||
{campaigns.length && !shown.length ? <div className="nds-empty-state"><p>{filter === "ended" ? "Aucune campagne terminée." : "Aucune campagne en cours."}</p></div>
|
||||
: campaigns.length ? <div className="nebula-campaign-list">{shown.map((campaign) => {
|
||||
const [statusLabel, statusVariant] = campaignStatus(campaign, now);
|
||||
const isOpen = openId === campaign.id;
|
||||
return <article key={campaign.id} className="nds-card nebula-campaign-card" data-open={isOpen || undefined} aria-label={campaign.name}>
|
||||
|
|
@ -375,6 +414,7 @@ export function AdminDistributions({ catalog, lookup, dashboard, mutateCampaigns
|
|||
<span className="nds-badge" data-variant={statusVariant}>{statusLabel}</span>
|
||||
<div className="nds-toolbar nebula-campaign-actions">
|
||||
<button className="nds-button" data-size="sm" data-variant="secondary" type="button" aria-expanded={isOpen} onClick={() => setOpenId(isOpen ? null : campaign.id)}>{isOpen ? "Masquer" : "Détails"}</button>
|
||||
<Tooltip as="button" className="nds-button" content="Créer une campagne avec la même récompense et les mêmes réglages" data-size="sm" data-variant="secondary" type="button" aria-label={`Dupliquer ${campaign.name}`} onClick={() => startCreating(campaign)}>Dupliquer</Tooltip>
|
||||
{!campaign.revokedAt && !isExpired(campaign, now) && <CopyCodeButton code={campaign.code} />}
|
||||
{!campaign.revokedAt && !isExpired(campaign, now) && <button className="nds-button" data-size="sm" data-variant="danger" type="button" disabled={busy} onClick={() => setPendingRevoke(campaign)}>Révoquer</button>}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue