Admin users: site totals (users, buyers) and short unit marks
CI / test (push) Successful in 2m3s
CI / build (push) Skipped
CI / deploy (push) Skipped

The user list shows how many users the site has and how many of them have
paid at least once (live Stripe payments; test-mode buyers counted apart),
independent of the search. The remaining units are short marks (K, Sz, E,
?, T) with a legend under the table, so the column fits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-23 12:57:56 +00:00
co-authored by Claude Opus 5.5
parent 3269aaaa35
commit 3255e939c4
4 changed files with 113 additions and 18 deletions
+56 -17
View File
@@ -12,27 +12,31 @@ const PAGE_SIZE = 25;
const EDITABLE_ROLES: Role[] = ["user", "creator", "admin"];
type UnitKind = "natal" | "synastry" | "forecast" | "question" | "tarot";
const UNITS: { value: UnitKind; label: string }[] = [
{ value: "natal", label: "képlet" },
{ value: "synastry", label: "szinasztria" },
{ value: "forecast", label: "előrejelzés" },
{ value: "question", label: "kérdés" },
{ value: "tarot", label: "kártyajóslás" },
/** `short`: the mark in the list, where the names do not fit (explained under it). */
const UNITS: { value: UnitKind; label: string; short: string }[] = [
{ value: "natal", label: "képlet", short: "K" },
{ value: "synastry", label: "szinasztria", short: "Sz" },
{ value: "forecast", label: "előrejelzés", short: "E" },
{ value: "question", label: "kérdés", short: "?" },
{ value: "tarot", label: "kártyajóslás", short: "T" },
];
type Stats = { users: number; buyers: number; test_buyers: number };
type UserPage = { users: AdminUser[]; total: number; stats: Stats };
type Status = { ok: boolean; text: string } | null;
export function AdminUsers({ selfId }: { selfId: string }) {
const [query, setQuery] = useState("");
const [page, setPage] = useState(0);
const [data, setData] = useState<{ users: AdminUser[]; total: number } | null>(null);
const [data, setData] = useState<UserPage | null>(null);
const [error, setError] = useState<string | null>(null);
const [editing, setEditing] = useState<string | null>(null);
const packages = usePackages() ?? [];
const load = useCallback(async (q: string, p: number) => {
try {
const res = await api<{ users: AdminUser[]; total: number }>(
const res = await api<UserPage>(
`/admin/users?q=${encodeURIComponent(q)}&limit=${PAGE_SIZE}&offset=${p * PAGE_SIZE}`,
);
setData(res);
@@ -56,6 +60,7 @@ export function AdminUsers({ selfId }: { selfId: string }) {
return (
<section className="card" aria-label="Felhasználók listája">
{data && <SiteStats stats={data.stats} />}
<div className="row" style={{ justifyContent: "space-between", alignItems: "flex-end" }}>
<div className="field" style={{ flex: "1 1 280px", maxWidth: 420 }}>
<label htmlFor="user-search">Keresés név vagy e-mail alapján</label>
@@ -71,9 +76,9 @@ export function AdminUsers({ selfId }: { selfId: string }) {
placeholder="pl. anna@"
/>
</div>
{data && (
{data && query.trim() && (
<span className="muted" style={{ fontSize: 14 }}>
{total} felhasználó
{total} találat
</span>
)}
</div>
@@ -93,7 +98,7 @@ export function AdminUsers({ selfId }: { selfId: string }) {
<tr>
<th scope="col">Felhasználó</th>
<th scope="col">Szerepkör</th>
<th scope="col">Hátralévő elemzések</th>
<th scope="col">Hátralévő</th>
<th scope="col">Képletek</th>
<th scope="col">Regisztrált</th>
<th scope="col">Utoljára belépett</th>
@@ -130,6 +135,15 @@ export function AdminUsers({ selfId }: { selfId: string }) {
))}
</tbody>
</table>
<p className="hint unit-legend">
Hátralévő:{" "}
{UNITS.map((u, i) => (
<span key={u.value}>
{i > 0 && " · "}
<b>{u.short}</b> {u.label}
</span>
))}
</p>
</div>
)}
{data && total > PAGE_SIZE && (
@@ -177,16 +191,41 @@ function RoleBadges({ roles }: { roles: Role[] }) {
);
}
/** The remaining units in one line, only the ones the user has. */
/** Everyone on the site and who has paid (not affected by the search). */
function SiteStats({ stats }: { stats: Stats }) {
const share = stats.users > 0 ? (stats.buyers / stats.users) * 100 : 0;
return (
<dl className="admin-stats">
<div>
<dt>Felhasználó</dt>
<dd className="num">{stats.users.toLocaleString("hu-HU")}</dd>
</div>
<div>
<dt>Vásárló</dt>
<dd className="num">{stats.buyers.toLocaleString("hu-HU")}</dd>
<dd className="hint">
{stats.users > 0 && `a felhasználók ${share.toLocaleString("hu-HU", { maximumFractionDigits: 1 })}%-a`}
{stats.test_buyers > 0 && (
<>
{stats.users > 0 && <br />}+{stats.test_buyers} csak tesztmódban
</>
)}
</dd>
</div>
</dl>
);
}
/** The remaining units as short marks (K 2 · ? 3), only the ones the user has. */
function Balances({ user }: { user: AdminUser }) {
const left = UNITS.map((u) => ({ ...u, n: user.analyses_left[u.value] ?? 0 })).filter((u) => u.n !== 0);
if (left.length === 0) return <span className="muted">–</span>;
return (
<span style={{ fontSize: 13 }}>
{left.map((u, i) => (
<span key={u.value} style={{ whiteSpace: "nowrap" }}>
{i > 0 && " · "}
{u.label} <span className="num">{u.n}</span>
<span className="unit-marks">
{left.map((u) => (
<span key={u.value} className="unit-mark" title={`${u.label}: ${u.n}`}>
<span aria-hidden="true">{u.short}</span>
<span className="sr-only">{u.label}</span> <span className="num">{u.n}</span>
</span>
))}
</span>
+16
View File
@@ -487,6 +487,22 @@ td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Admin: the user list's pager and the user dialog. */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; font-size: 14px; color: var(--ink-2); }
.admin-users td { vertical-align: middle; }
.admin-stats { display: flex; flex-wrap: wrap; gap: 12px; margin: 0 0 18px; }
.admin-stats > div {
flex: 1 1 140px; max-width: 220px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px;
}
.admin-stats dt { font-size: 13px; color: var(--muted); }
.admin-stats dd { margin: 0; }
.admin-stats dd.num { font-size: 26px; font-weight: 600; line-height: 1.25; color: var(--ink); font-variant-numeric: tabular-nums; }
.unit-marks { display: inline-flex; gap: 4px; }
.unit-mark {
display: inline-flex; gap: 4px; align-items: baseline; padding: 1px 7px; border: 1px solid var(--line-2); border-radius: 6px;
font-size: 12px; color: var(--ink-2); white-space: nowrap;
}
.unit-mark > span:first-child { color: var(--gold); font-weight: 600; }
.unit-mark .num { color: var(--ink); font-variant-numeric: tabular-nums; }
.unit-legend { margin: 10px 0 0; }
.unit-legend b { color: var(--gold); font-weight: 600; }
dialog.modal {
width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; margin: auto;
background: var(--panel); color: var(--ink); border: 1px solid var(--line-2); border-radius: 14px;