feat(awards): polish Award Automation admin view styling
- Replace hand-rolled buttons with @payloadcms/ui Button (secondary dry run, primary apply) since the admin bundle has no Tailwind for shadcn - Real spacing values throughout: Payload defines no --spacing-* vars, so gaps used to collapse to zero; use px literals and var(--base) - Framed panels with theme-elevation borders, uppercase table headers, stats strip with collapsed line boxes so small caps sit evenly inside the card padding
This commit is contained in:
parent
db9248244d
commit
e987952a9b
1 changed files with 151 additions and 50 deletions
|
|
@ -1,11 +1,16 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@payloadcms/ui";
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
import { runAwardEvaluation, applyAwardGrants } from "@/lib/awards/automationActions";
|
import { runAwardEvaluation, applyAwardGrants } from "@/lib/awards/automationActions";
|
||||||
import type { EvaluationResult } from "@/lib/awards/automation";
|
import type { EvaluationResult } from "@/lib/awards/automation";
|
||||||
|
|
||||||
|
const panelStyle: React.CSSProperties = {
|
||||||
|
border: "1px solid var(--theme-elevation-150)",
|
||||||
|
borderRadius: "3px",
|
||||||
|
background: "var(--theme-elevation-50)",
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Admin view (award-rules collection): preview which members currently
|
* Admin view (award-rules collection): preview which members currently
|
||||||
* qualify under the active rules, then apply the grants. Both actions are
|
* qualify under the active rules, then apply the grants. Both actions are
|
||||||
|
|
@ -40,68 +45,164 @@ export default function AwardAutomationView() {
|
||||||
setResult(res.result);
|
setResult(res.result);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
const grantCount = result ? result.plans.filter((p) => p.kind === "grant").length : 0;
|
||||||
<div style={{ padding: "var(--spacing-6) var(--base)" }}>
|
const upgradeCount = result ? result.plans.filter((p) => p.kind === "upgrade").length : 0;
|
||||||
<h1>Award Automation</h1>
|
|
||||||
<p className="row-layout" style={{ color: "var(--theme-elevation-600)", maxWidth: 640 }}>
|
|
||||||
Evaluate every active award rule against all members. Preview first: nothing is written
|
|
||||||
until you apply. Applying is safe to repeat, members who already hold an award are skipped.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div style={{ display: "flex", gap: "var(--spacing-2)", margin: "var(--spacing-4) 0" }}>
|
return (
|
||||||
<Button onClick={runPreview} disabled={busy !== null}>
|
<div
|
||||||
|
style={{
|
||||||
|
padding: "var(--base) var(--base) calc(var(--base) * 2)",
|
||||||
|
maxWidth: "72rem",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
gap: "24px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<header style={{ display: "flex", flexDirection: "column", gap: "8px" }}>
|
||||||
|
<h1 style={{ margin: 0 }}>Award Automation</h1>
|
||||||
|
<p style={{ margin: 0, color: "var(--theme-elevation-600)", maxWidth: "44rem" }}>
|
||||||
|
Evaluate every active award rule against all members. Preview first: nothing is written
|
||||||
|
until you apply. Applying is safe to repeat, members who already hold an award are
|
||||||
|
skipped.
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div style={{ display: "flex", gap: "12px" }}>
|
||||||
|
<Button buttonStyle="secondary" onClick={runPreview} disabled={busy !== null}>
|
||||||
{busy === "preview" ? "Evaluating..." : "Evaluate now (dry run)"}
|
{busy === "preview" ? "Evaluating..." : "Evaluate now (dry run)"}
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={runApply} disabled={busy !== null || !result || result.plans.length === 0}>
|
<Button
|
||||||
|
buttonStyle="primary"
|
||||||
|
onClick={runApply}
|
||||||
|
disabled={busy !== null || !result || result.plans.length === 0}
|
||||||
|
>
|
||||||
{busy === "apply" ? "Applying..." : "Apply grants"}
|
{busy === "apply" ? "Applying..." : "Apply grants"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<p style={{ color: "var(--theme-error-500)" }}>{error}</p>
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
padding: "8px 12px",
|
||||||
|
color: "var(--theme-error-500)",
|
||||||
|
...panelStyle,
|
||||||
|
borderColor: "var(--theme-error-200)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{result && (
|
{result && (
|
||||||
<>
|
<section style={{ display: "flex", flexDirection: "column", gap: "24px" }}>
|
||||||
<p>
|
<div
|
||||||
<Badge variant="secondary">{result.dryRun ? "Dry run" : "Applied"}</Badge>{" "}
|
style={{
|
||||||
Rules evaluated: {result.rulesEvaluated}, members checked: {result.membersChecked},{" "}
|
display: "flex",
|
||||||
{result.dryRun
|
flexWrap: "wrap",
|
||||||
? `would grant ${result.plans.filter((p) => p.kind === "grant").length}, would upgrade ${result.plans.filter((p) => p.kind === "upgrade").length}`
|
gap: "var(--base)",
|
||||||
: `granted ${result.granted}, upgraded ${result.upgraded}`}
|
padding: "16px 20px",
|
||||||
, skipped: {result.skips.length}
|
...panelStyle,
|
||||||
</p>
|
}}
|
||||||
|
>
|
||||||
|
{[
|
||||||
|
{ label: "Mode", value: result.dryRun ? "Dry run" : "Applied" },
|
||||||
|
{ label: "Rules evaluated", value: String(result.rulesEvaluated) },
|
||||||
|
{ label: "Members checked", value: String(result.membersChecked) },
|
||||||
|
{
|
||||||
|
label: result.dryRun ? "Would grant" : "Granted",
|
||||||
|
value: String(result.dryRun ? grantCount : result.granted),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: result.dryRun ? "Would upgrade" : "Upgraded",
|
||||||
|
value: String(result.dryRun ? upgradeCount : result.upgraded),
|
||||||
|
},
|
||||||
|
{ label: "Skipped", value: String(result.skips.length) },
|
||||||
|
].map((stat) => (
|
||||||
|
<div
|
||||||
|
key={stat.label}
|
||||||
|
style={{ display: "flex", flexDirection: "column", gap: "2px", minWidth: "7rem" }}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: "0.625rem",
|
||||||
|
lineHeight: 1,
|
||||||
|
textTransform: "uppercase",
|
||||||
|
letterSpacing: "0.04em",
|
||||||
|
color: "var(--theme-elevation-500)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{stat.label}
|
||||||
|
</span>
|
||||||
|
<span style={{ fontSize: "1.25rem", lineHeight: 1.1 }}>{stat.value}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
{result.plans.length > 0 && (
|
{result.plans.length > 0 ? (
|
||||||
<table cellPadding={6} style={{ width: "100%", borderCollapse: "collapse" }}>
|
<div style={{ overflowX: "auto", ...panelStyle }}>
|
||||||
<thead>
|
<table style={{ width: "100%", borderCollapse: "collapse" }}>
|
||||||
<tr style={{ textAlign: "left", borderBottom: "1px solid var(--theme-elevation-200)" }}>
|
<thead>
|
||||||
<th>Member</th>
|
<tr style={{ borderBottom: "1px solid var(--theme-elevation-150)" }}>
|
||||||
<th>Rule</th>
|
{["Member", "Rule", "Award", "Metric value", "Action"].map((col) => (
|
||||||
<th>Award</th>
|
<th
|
||||||
<th>Metric value</th>
|
key={col}
|
||||||
<th>Action</th>
|
style={{
|
||||||
</tr>
|
textAlign: "left",
|
||||||
</thead>
|
padding: "12px 16px",
|
||||||
<tbody>
|
fontSize: "0.625rem",
|
||||||
{result.plans.map((plan, i) => (
|
lineHeight: 1,
|
||||||
<tr key={`${plan.ruleId}-${plan.userId}-${i}`} style={{ borderBottom: "1px solid var(--theme-elevation-100)" }}>
|
textTransform: "uppercase",
|
||||||
<td>{plan.username}</td>
|
letterSpacing: "0.04em",
|
||||||
<td>{plan.ruleLabel}</td>
|
color: "var(--theme-elevation-500)",
|
||||||
<td>{plan.awardName}</td>
|
fontWeight: 600,
|
||||||
<td>{plan.metricValue.toFixed(2)}</td>
|
}}
|
||||||
<td>
|
>
|
||||||
{plan.kind === "upgrade"
|
{col}
|
||||||
? `Upgrade (retires award #${plan.replacesAwardId})`
|
</th>
|
||||||
: "Grant"}
|
))}
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
</thead>
|
||||||
</tbody>
|
<tbody>
|
||||||
</table>
|
{result.plans.map((plan, i) => (
|
||||||
|
<tr
|
||||||
|
key={`${plan.ruleId}-${plan.userId}-${i}`}
|
||||||
|
style={{ borderBottom: "1px solid var(--theme-elevation-100)" }}
|
||||||
|
>
|
||||||
|
{[
|
||||||
|
plan.username,
|
||||||
|
plan.ruleLabel,
|
||||||
|
plan.awardName,
|
||||||
|
plan.metricValue.toFixed(2),
|
||||||
|
plan.kind === "upgrade"
|
||||||
|
? `Upgrade (retires award #${plan.replacesAwardId})`
|
||||||
|
: "Grant",
|
||||||
|
].map((cell, j) => (
|
||||||
|
<td
|
||||||
|
key={j}
|
||||||
|
style={{ padding: "12px 16px", verticalAlign: "top" }}
|
||||||
|
>
|
||||||
|
{cell}
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: 0,
|
||||||
|
padding: "20px",
|
||||||
|
color: "var(--theme-elevation-600)",
|
||||||
|
...panelStyle,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
No members currently qualify for anything new.
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
{result.plans.length === 0 && <p>No members currently qualify for anything new.</p>}
|
</section>
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue