hazo_auth 10.18.2 → 10.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,8 @@ export interface UserSignupStatsCardsProps {
9
9
  }
10
10
  /**
11
11
  * Total + rolling-window signup cards (All time, 7d, 30d, 3mo, 6mo, YTD) each
12
- * with % change vs the prior equal period, plus a mini YTD monthly bar chart.
12
+ * with % change vs the prior equal period, plus a larger interactive YTD
13
+ * monthly bar chart with axes, gridlines, and hover tooltips.
13
14
  * Computes everything client-side from the already-loaded users list.
14
15
  */
15
16
  export declare function UserSignupStatsCards({ users, now, className }: UserSignupStatsCardsProps): React.JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"user_signup_stats_cards.d.ts","sourceRoot":"","sources":["../../../../../src/components/layouts/user_management/components/user_signup_stats_cards.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAOvC,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,aAAa,CAAC;QAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IACrD,8DAA8D;IAC9D,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAwFD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,yBAAyB,qBAaxF"}
1
+ {"version":3,"file":"user_signup_stats_cards.d.ts","sourceRoot":"","sources":["../../../../../src/components/layouts/user_management/components/user_signup_stats_cards.tsx"],"names":[],"mappings":"AAMA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAOjD,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,aAAa,CAAC;QAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IACrD,8DAA8D;IAC9D,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA2ND;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,yBAAyB,qBAaxF"}
@@ -1,9 +1,10 @@
1
1
  // file_description: Mini stat cards (total + rolling windows with % change vs the
2
- // prior equal period) plus a small YTD monthly signups bar chart, for the top of
3
- // the Manage Users tab. Pure/dependency-free (inline SVG chart).
2
+ // prior equal period) in a 12-col grid, plus a larger interactive YTD monthly
3
+ // signups bar chart (axes, gridlines, hover tooltip) for the top of the Manage
4
+ // Users tab. Pure/dependency-free (inline SVG chart, no chart library).
4
5
  "use client";
5
6
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
- import { useMemo } from "react";
7
+ import { useMemo, useState } from "react";
7
8
  import { computeUserSignupStats, } from "../../../../lib/user_signup_stats.js";
8
9
  function DeltaBadge({ pct }) {
9
10
  if (pct === null) {
@@ -14,34 +15,76 @@ function DeltaBadge({ pct }) {
14
15
  const arrow = up ? "▲" : "▼";
15
16
  return (_jsxs("span", { className: `text-xs font-medium ${cls}`, title: "vs. previous equal period", children: [arrow, " ", up ? "+" : "", pct, "%"] }));
16
17
  }
18
+ const STAT_CARD_HEIGHT_PX = 168;
17
19
  function StatCard({ w }) {
18
- return (_jsxs("div", { className: "cls_user_signup_stat_card rounded-lg border bg-card p-3", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: w.label }), _jsxs("div", { className: "mt-1 flex items-baseline justify-between gap-2", children: [_jsx("span", { className: "text-2xl font-bold tabular-nums", children: w.count.toLocaleString() }), w.key !== "all" && _jsx(DeltaBadge, { pct: w.pctChange })] }), w.key !== "all" && w.prevCount !== null && (_jsxs("div", { className: "mt-0.5 text-[11px] text-muted-foreground", children: ["prev ", w.prevCount.toLocaleString()] })), w.key === "all" && (_jsx("div", { className: "mt-0.5 text-[11px] text-muted-foreground", children: "total users" }))] }));
20
+ return (_jsxs("div", { className: "cls_user_signup_stat_card flex min-w-0 flex-col justify-between rounded-lg border bg-card p-4", style: { height: STAT_CARD_HEIGHT_PX }, children: [_jsx("div", { className: "truncate text-xs text-muted-foreground", children: w.label }), _jsxs("div", { className: "flex items-baseline justify-between gap-1", children: [_jsx("span", { className: "text-3xl font-bold tabular-nums", children: w.count.toLocaleString() }), w.key !== "all" && _jsx(DeltaBadge, { pct: w.pctChange })] }), w.key !== "all" && w.prevCount !== null && (_jsxs("div", { className: "truncate text-xs text-muted-foreground", children: ["prev ", w.prevCount.toLocaleString()] })), w.key === "all" && (_jsx("div", { className: "truncate text-xs text-muted-foreground", children: "total users" }))] }));
21
+ }
22
+ /** Round a value up to a "nice" axis maximum (1/2/5 * 10^n steps). */
23
+ function niceMax(n) {
24
+ if (n <= 0)
25
+ return 1;
26
+ const exp = Math.floor(Math.log10(n));
27
+ const base = Math.pow(10, exp);
28
+ const frac = n / base;
29
+ let niceFrac;
30
+ if (frac <= 1)
31
+ niceFrac = 1;
32
+ else if (frac <= 2)
33
+ niceFrac = 2;
34
+ else if (frac <= 5)
35
+ niceFrac = 5;
36
+ else
37
+ niceFrac = 10;
38
+ return niceFrac * base;
19
39
  }
20
40
  function YtdMiniChart({ data }) {
21
- var _a, _b, _c, _d;
41
+ const [hoverIndex, setHoverIndex] = useState(null);
22
42
  const total = data.reduce((n, d) => n + d.count, 0);
23
- const max = Math.max(1, ...data.map((d) => d.count));
24
- // Inline SVG bar chart — no chart library dependency.
25
- const W = 220;
26
- const H = 56;
27
- const gap = 3;
43
+ const rawMax = Math.max(1, ...data.map((d) => d.count));
44
+ const max = niceMax(rawMax);
45
+ const mid = Math.round(max / 2);
46
+ // Chart geometry. H mirrors the plot area left after the header row + padding
47
+ // are subtracted from STAT_CARD_HEIGHT_PX, so the rendered SVG (stretched via
48
+ // preserveAspectRatio="none") stays close to a 1 viewBox-unit : 1px scale.
49
+ const W = 480;
50
+ const H = 120;
51
+ const marginLeft = 34;
52
+ const marginRight = 8;
53
+ const marginTop = 16;
54
+ const marginBottom = 20;
55
+ const plotW = W - marginLeft - marginRight;
56
+ const plotH = H - marginTop - marginBottom;
57
+ const gap = 6;
28
58
  const n = Math.max(1, data.length);
29
- const bw = (W - gap * (n - 1)) / n;
30
- return (_jsxs("div", { className: "cls_user_signup_ytd_chart rounded-lg border bg-card p-3 sm:col-span-2", children: [_jsxs("div", { className: "flex items-baseline justify-between", children: [_jsx("div", { className: "text-xs text-muted-foreground", children: "Signups by month (YTD)" }), _jsx("div", { className: "text-sm font-semibold tabular-nums", children: total.toLocaleString() })] }), _jsx("svg", { role: "img", "aria-label": `Year-to-date signups by month: ${data
31
- .map((d) => `${d.label} ${d.count}`)
32
- .join(", ")}`, viewBox: `0 0 ${W} ${H}`, className: "mt-2 w-full", preserveAspectRatio: "none", children: data.map((d, i) => {
33
- const h = Math.round((d.count / max) * (H - 2));
34
- const x = i * (bw + gap);
35
- const y = H - h;
36
- return (_jsx("rect", { x: x, y: y, width: bw, height: h, rx: 1.5, className: "fill-primary", children: _jsx("title", { children: `${d.label}: ${d.count}` }) }, d.label));
37
- }) }), _jsxs("div", { className: "mt-1 flex justify-between text-[10px] text-muted-foreground", children: [_jsx("span", { children: (_b = (_a = data[0]) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : "" }), _jsx("span", { children: (_d = (_c = data[data.length - 1]) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : "" })] })] }));
59
+ const colW = plotW / n;
60
+ const bw = Math.max(1, colW - gap);
61
+ const yFor = (value) => marginTop + plotH - (value / max) * plotH;
62
+ const hovered = hoverIndex !== null ? data[hoverIndex] : null;
63
+ return (_jsxs("div", { className: "cls_user_signup_ytd_chart col-span-6 flex min-w-0 flex-col rounded-lg border bg-card p-3", style: { height: STAT_CARD_HEIGHT_PX }, children: [_jsxs("div", { className: "flex shrink-0 items-baseline justify-between", children: [_jsx("div", { className: "truncate text-[11px] text-muted-foreground", children: "Signups by month (YTD)" }), _jsx("div", { className: "text-sm font-semibold tabular-nums", children: total.toLocaleString() })] }), _jsxs("div", { className: "relative mt-2 min-h-0 flex-1", children: [_jsxs("svg", { role: "img", "aria-label": `Year-to-date signups by month: ${data
64
+ .map((d) => `${d.label} ${d.count}`)
65
+ .join(", ")}`, viewBox: `0 0 ${W} ${H}`, preserveAspectRatio: "none", className: "h-full w-full", children: [[0, mid, max].map((tick) => {
66
+ const y = yFor(tick);
67
+ return (_jsxs("g", { children: [_jsx("line", { x1: marginLeft, x2: W - marginRight, y1: y, y2: y, stroke: "currentColor", strokeOpacity: 0.1 }), _jsx("text", { x: marginLeft - 6, y: y, dy: 3, textAnchor: "end", fontSize: 9, className: "fill-muted-foreground", children: tick.toLocaleString() })] }, tick));
68
+ }), _jsx("line", { x1: marginLeft, x2: W - marginRight, y1: marginTop + plotH, y2: marginTop + plotH, stroke: "currentColor", strokeOpacity: 0.2 }), data.map((d, i) => {
69
+ const barH = Math.round((d.count / max) * plotH);
70
+ const colX = marginLeft + i * colW;
71
+ const barX = colX + (colW - bw) / 2;
72
+ const barY = marginTop + plotH - barH;
73
+ const centerX = colX + colW / 2;
74
+ const isDimmed = hoverIndex !== null && hoverIndex !== i;
75
+ return (_jsxs("g", { onMouseEnter: () => setHoverIndex(i), onMouseLeave: () => setHoverIndex(null), children: [_jsx("rect", { x: colX, y: marginTop, width: colW, height: plotH, fill: "transparent" }), _jsx("rect", { x: barX, y: barY, width: bw, height: Math.max(0, barH), rx: 2, className: "fill-primary", fillOpacity: isDimmed ? 0.45 : 1, children: _jsx("title", { children: `${d.label}: ${d.count}` }) }), _jsx("text", { x: centerX, y: barY - 4, textAnchor: "middle", fontSize: 10, fontWeight: 600, className: "fill-foreground", children: d.count }), _jsx("text", { x: centerX, y: marginTop + plotH + 14, textAnchor: "middle", fontSize: 9, className: "fill-muted-foreground", children: d.label })] }, d.label));
76
+ })] }), hovered && hoverIndex !== null && (_jsxs("div", { className: "pointer-events-none absolute z-10 -translate-x-1/2 -translate-y-full rounded-md border bg-popover px-2 py-1 text-[10px] font-medium text-popover-foreground shadow-sm", style: {
77
+ left: `${Math.min(92, Math.max(8, ((marginLeft + hoverIndex * (plotW / n) + plotW / n / 2) / W) * 100))}%`,
78
+ top: `${((marginTop + plotH - (hovered.count / max) * plotH) / H) * 100}%`,
79
+ }, children: [hovered.label, ": ", hovered.count, " signups"] }))] })] }));
38
80
  }
39
81
  /**
40
82
  * Total + rolling-window signup cards (All time, 7d, 30d, 3mo, 6mo, YTD) each
41
- * with % change vs the prior equal period, plus a mini YTD monthly bar chart.
83
+ * with % change vs the prior equal period, plus a larger interactive YTD
84
+ * monthly bar chart with axes, gridlines, and hover tooltips.
42
85
  * Computes everything client-side from the already-loaded users list.
43
86
  */
44
87
  export function UserSignupStatsCards({ users, now, className }) {
45
88
  const stats = useMemo(() => computeUserSignupStats(users, now), [users, now]);
46
- return (_jsxs("div", { className: `cls_user_signup_stats_cards mb-4 grid grid-cols-2 gap-3 sm:grid-cols-4 lg:grid-cols-8 ${className !== null && className !== void 0 ? className : ""}`, children: [stats.windows.map((w) => (_jsx(StatCard, { w: w }, w.key))), _jsx(YtdMiniChart, { data: stats.ytdMonthly })] }));
89
+ return (_jsxs("div", { className: `cls_user_signup_stats_cards mb-4 grid grid-cols-6 items-start gap-2 md:grid-cols-12 ${className !== null && className !== void 0 ? className : ""}`, children: [stats.windows.map((w) => (_jsx(StatCard, { w: w }, w.key))), _jsx(YtdMiniChart, { data: stats.ytdMonthly })] }));
47
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hazo_auth",
3
- "version": "10.18.2",
3
+ "version": "10.18.4",
4
4
  "description": "Zero-config authentication UI components for Next.js with RBAC, OAuth, scope-based multi-tenancy, and invitations",
5
5
  "keywords": [
6
6
  "authentication",
@@ -246,6 +246,7 @@
246
246
  "clsx": "^2.1.1",
247
247
  "date-fns": "^4.1.0",
248
248
  "gravatar-url": "^4.0.1",
249
+ "hazo_auth": "^10.18.3",
249
250
  "ini": "^6.0.0",
250
251
  "input-otp": "^1.4.0",
251
252
  "jose": "^5.9.6",