Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c65d45907 | ||
|
|
3255e939c4 |
@@ -73,6 +73,15 @@ pub async fn list_users(
|
||||
.bind(&pattern)
|
||||
.fetch_one(&state.db)
|
||||
.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
|
||||
.into_iter()
|
||||
.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();
|
||||
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)]
|
||||
|
||||
@@ -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));
|
||||
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));
|
||||
|
||||
// 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 }));
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user