1
0
Fork 0

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:
Jason Fraley 2026-10-12 15:27:12 -04:00
parent db9248244d
commit e987952a9b

View file

@ -1,11 +1,16 @@
"use client";
import * as React from "react";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { Button } from "@payloadcms/ui";
import { runAwardEvaluation, applyAwardGrants } from "@/lib/awards/automationActions";
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
* qualify under the active rules, then apply the grants. Both actions are
@ -40,68 +45,164 @@ export default function AwardAutomationView() {
setResult(res.result);
};
return (
<div style={{ padding: "var(--spacing-6) var(--base)" }}>
<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>
const grantCount = result ? result.plans.filter((p) => p.kind === "grant").length : 0;
const upgradeCount = result ? result.plans.filter((p) => p.kind === "upgrade").length : 0;
<div style={{ display: "flex", gap: "var(--spacing-2)", margin: "var(--spacing-4) 0" }}>
<Button onClick={runPreview} disabled={busy !== null}>
return (
<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)"}
</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"}
</Button>
</div>
{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 && (
<>
<p>
<Badge variant="secondary">{result.dryRun ? "Dry run" : "Applied"}</Badge>{" "}
Rules evaluated: {result.rulesEvaluated}, members checked: {result.membersChecked},{" "}
{result.dryRun
? `would grant ${result.plans.filter((p) => p.kind === "grant").length}, would upgrade ${result.plans.filter((p) => p.kind === "upgrade").length}`
: `granted ${result.granted}, upgraded ${result.upgraded}`}
, skipped: {result.skips.length}
</p>
<section style={{ display: "flex", flexDirection: "column", gap: "24px" }}>
<div
style={{
display: "flex",
flexWrap: "wrap",
gap: "var(--base)",
padding: "16px 20px",
...panelStyle,
}}
>
{[
{ 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 && (
<table cellPadding={6} style={{ width: "100%", borderCollapse: "collapse" }}>
<thead>
<tr style={{ textAlign: "left", borderBottom: "1px solid var(--theme-elevation-200)" }}>
<th>Member</th>
<th>Rule</th>
<th>Award</th>
<th>Metric value</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{result.plans.map((plan, i) => (
<tr key={`${plan.ruleId}-${plan.userId}-${i}`} style={{ borderBottom: "1px solid var(--theme-elevation-100)" }}>
<td>{plan.username}</td>
<td>{plan.ruleLabel}</td>
<td>{plan.awardName}</td>
<td>{plan.metricValue.toFixed(2)}</td>
<td>
{plan.kind === "upgrade"
? `Upgrade (retires award #${plan.replacesAwardId})`
: "Grant"}
</td>
{result.plans.length > 0 ? (
<div style={{ overflowX: "auto", ...panelStyle }}>
<table style={{ width: "100%", borderCollapse: "collapse" }}>
<thead>
<tr style={{ borderBottom: "1px solid var(--theme-elevation-150)" }}>
{["Member", "Rule", "Award", "Metric value", "Action"].map((col) => (
<th
key={col}
style={{
textAlign: "left",
padding: "12px 16px",
fontSize: "0.625rem",
lineHeight: 1,
textTransform: "uppercase",
letterSpacing: "0.04em",
color: "var(--theme-elevation-500)",
fontWeight: 600,
}}
>
{col}
</th>
))}
</tr>
))}
</tbody>
</table>
</thead>
<tbody>
{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>
);