Compare commits

...
Author SHA1 Message Date
fecoandClaude Opus 5.5 8c65d45907 Merge main: admin user totals (users, buyers) and short unit marks
CI / test (push) Successful in 1m59s
CI / build (push) Successful in 6m18s
CI / deploy (push) Successful in 38s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-23 13:07:13 +00:00
fecoandClaude Opus 5.5 3255e939c4 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
2026-11-23 12:57:56 +00:00
4 changed files with 113 additions and 18 deletions
+13 -1
View File
@@ -73,6 +73,15 @@ pub async fn list_users(
.bind(&pattern) .bind(&pattern)
.fetch_one(&state.db) .fetch_one(&state.db)
.await?; .await?;
// For the whole site, not the search: everyone, and who has paid at least
// once (a live payment; test-mode payments counted apart).
let (all_users, buyers, test_buyers): (i64, i64, i64) = sqlx::query_as(
"SELECT (SELECT count(*) FROM users), count(*) FILTER (WHERE live), count(*) FILTER (WHERE NOT live) \
FROM (SELECT c.user_id, bool_or(c.live) AS live FROM stripe_checkouts c \
WHERE c.completed_at IS NOT NULL AND c.user_id IS NOT NULL GROUP BY c.user_id) b",
)
.fetch_one(&state.db)
.await?;
let users: Vec<Value> = rows let users: Vec<Value> = rows
.into_iter() .into_iter()
.map(|(id, email, name, roles, verified, created, last_login, charts, natal, synastry, forecast, question, tarot)| { .map(|(id, email, name, roles, verified, created, last_login, charts, natal, synastry, forecast, question, tarot)| {
@@ -86,7 +95,10 @@ pub async fn list_users(
}) })
}) })
.collect(); .collect();
Ok(Json(json!({ "users": users, "total": total, "limit": limit, "offset": offset }))) Ok(Json(json!({
"users": users, "total": total, "limit": limit, "offset": offset,
"stats": { "users": all_users, "buyers": buyers, "test_buyers": test_buyers },
})))
} }
#[derive(Deserialize)] #[derive(Deserialize)]
+28
View File
@@ -3208,4 +3208,32 @@ async fn the_user_list_pages_with_a_total(pool: PgPool) {
assert_eq!((r.body["total"].as_i64(), r.body["users"].as_array().unwrap().len()), (Some(5), 2)); assert_eq!((r.body["total"].as_i64(), r.body["users"].as_array().unwrap().len()), (Some(5), 2));
let r = app.get("/v1/admin/users?q=lap&limit=3&offset=3", Some(&admin)).await; let r = app.get("/v1/admin/users?q=lap&limit=3&offset=3", Some(&admin)).await;
assert_eq!((r.body["total"].as_i64(), r.body["users"].as_array().unwrap().len()), (Some(4), 1)); assert_eq!((r.body["total"].as_i64(), r.body["users"].as_array().unwrap().len()), (Some(4), 1));
// The counts are for the whole site, not the search. A buyer paid at least
// once (two payments still one buyer); a test-mode payment counts apart,
// an unfinished checkout not at all.
let ids: Vec<uuid::Uuid> = sqlx::query_scalar("SELECT id FROM users WHERE email LIKE 'lap%' ORDER BY email")
.fetch_all(&pool)
.await
.unwrap();
for (n, (user, live, done)) in
[(ids[0], true, true), (ids[0], true, true), (ids[1], false, true), (ids[2], true, false)]
.into_iter()
.enumerate()
{
sqlx::query(
"INSERT INTO stripe_checkouts (id, user_id, package, price_huf, live, completed_at) \
VALUES ($1, $2, 'alap', 1990, $3, CASE WHEN $4 THEN now() END)",
)
.bind(format!("cs_test_{n}"))
.bind(user)
.bind(live)
.bind(done)
.execute(&pool)
.await
.unwrap();
}
let r = app.get("/v1/admin/users?q=lap0", Some(&admin)).await;
assert_eq!(r.body["total"].as_i64(), Some(1));
assert_eq!(r.body["stats"], json!({ "users": 5, "buyers": 1, "test_buyers": 1 }));
} }
+56 -17
View File
@@ -12,27 +12,31 @@ const PAGE_SIZE = 25;
const EDITABLE_ROLES: Role[] = ["user", "creator", "admin"]; const EDITABLE_ROLES: Role[] = ["user", "creator", "admin"];
type UnitKind = "natal" | "synastry" | "forecast" | "question" | "tarot"; type UnitKind = "natal" | "synastry" | "forecast" | "question" | "tarot";
const UNITS: { value: UnitKind; label: string }[] = [ /** `short`: the mark in the list, where the names do not fit (explained under it). */
{ value: "natal", label: "képlet" }, const UNITS: { value: UnitKind; label: string; short: string }[] = [
{ value: "synastry", label: "szinasztria" }, { value: "natal", label: "képlet", short: "K" },
{ value: "forecast", label: "előrejelzés" }, { value: "synastry", label: "szinasztria", short: "Sz" },
{ value: "question", label: "kérdés" }, { value: "forecast", label: "előrejelzés", short: "E" },
{ value: "tarot", label: "kártyajóslás" }, { 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; type Status = { ok: boolean; text: string } | null;
export function AdminUsers({ selfId }: { selfId: string }) { export function AdminUsers({ selfId }: { selfId: string }) {
const [query, setQuery] = useState(""); const [query, setQuery] = useState("");
const [page, setPage] = useState(0); 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 [error, setError] = useState<string | null>(null);
const [editing, setEditing] = useState<string | null>(null); const [editing, setEditing] = useState<string | null>(null);
const packages = usePackages() ?? []; const packages = usePackages() ?? [];
const load = useCallback(async (q: string, p: number) => { const load = useCallback(async (q: string, p: number) => {
try { 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}`, `/admin/users?q=${encodeURIComponent(q)}&limit=${PAGE_SIZE}&offset=${p * PAGE_SIZE}`,
); );
setData(res); setData(res);
@@ -56,6 +60,7 @@ export function AdminUsers({ selfId }: { selfId: string }) {
return ( return (
<section className="card" aria-label="Felhasználók listája"> <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="row" style={{ justifyContent: "space-between", alignItems: "flex-end" }}>
<div className="field" style={{ flex: "1 1 280px", maxWidth: 420 }}> <div className="field" style={{ flex: "1 1 280px", maxWidth: 420 }}>
<label htmlFor="user-search">Keresés név vagy e-mail alapján</label> <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@" placeholder="pl. anna@"
/> />
</div> </div>
{data && ( {data && query.trim() && (
<span className="muted" style={{ fontSize: 14 }}> <span className="muted" style={{ fontSize: 14 }}>
{total} felhasználó {total} találat
</span> </span>
)} )}
</div> </div>
@@ -93,7 +98,7 @@ export function AdminUsers({ selfId }: { selfId: string }) {
<tr> <tr>
<th scope="col">Felhasználó</th> <th scope="col">Felhasználó</th>
<th scope="col">Szerepkör</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">Képletek</th>
<th scope="col">Regisztrált</th> <th scope="col">Regisztrált</th>
<th scope="col">Utoljára belépett</th> <th scope="col">Utoljára belépett</th>
@@ -130,6 +135,15 @@ export function AdminUsers({ selfId }: { selfId: string }) {
))} ))}
</tbody> </tbody>
</table> </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> </div>
)} )}
{data && total > PAGE_SIZE && ( {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 }) { function Balances({ user }: { user: AdminUser }) {
const left = UNITS.map((u) => ({ ...u, n: user.analyses_left[u.value] ?? 0 })).filter((u) => u.n !== 0); 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>; if (left.length === 0) return <span className="muted">–</span>;
return ( return (
<span style={{ fontSize: 13 }}> <span className="unit-marks">
{left.map((u, i) => ( {left.map((u) => (
<span key={u.value} style={{ whiteSpace: "nowrap" }}> <span key={u.value} className="unit-mark" title={`${u.label}: ${u.n}`}>
{i > 0 && " · "} <span aria-hidden="true">{u.short}</span>
{u.label} <span className="num">{u.n}</span> <span className="sr-only">{u.label}</span> <span className="num">{u.n}</span>
</span> </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. */ /* 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); } .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-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 { dialog.modal {
width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; margin: auto; 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; background: var(--panel); color: var(--ink); border: 1px solid var(--line-2); border-radius: 14px;