@okjt/dashboard 0.1.0 → 0.2.1

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.
package/README.md CHANGED
@@ -135,11 +135,16 @@ and wrap the dashboard in `<CollaborationProvider>` (inside the router). Then
135
135
  | `GoogleButton` | Sends the browser to the kit's Google route |
136
136
  | `loginWithPasskey`, `registerPasskey`, `passkeysSupported` | Passkeys against the kit's `PasskeyController`; `{ base }` if the routes aren't under `/api` |
137
137
  | `NotificationsBell` | The header's notifications |
138
+ | `AuthLayout`, `AuthField`, `AuthSubmit`, `AuthError` | The sign-in pages' frame (`brand`, `backLabel`, and a desktop panel `aside`) and its fields |
139
+ | `SignInPage` | Email and password, a passkey, `google`; then verifying the email or a two-step code. `onSignedIn(result)` decides where to go (return a message to show instead) |
140
+ | `GoogleCallbackPage`, `VerifyEmailPage`, `AcceptInvitePage` | Where Google sign-in, the verification email and invitation links land |
141
+ | `AccountMenu` | The header's avatar menu: who you are, the project's own entries (`extra`), account pages (`links`), log out |
142
+
143
+ Each page takes `layout`: the project's own `AuthLayout` with its logo and panel.
144
+ `SignInPage` needs `react-hook-form`.
138
145
 
139
146
  ## The shell
140
147
 
141
148
  `DashboardShell` (with `DashboardSidebar` and `DashboardHeader`) is the frame
142
149
  around every page, set up through `shell` in the dashboard settings.
143
150
 
144
- Still in the projects for now, moving next: the Console, teams, backups,
145
- then the sign-in pages and the account menu.
@@ -0,0 +1,86 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { Link, useSearchParams } from "react-router-dom";
4
+ import { useAuth } from "./AuthContext.js";
5
+ import AuthLayout, { AuthError, AuthField, AuthSubmit } from "./AuthLayout.js";
6
+ function AcceptInvitePage({
7
+ layout: Layout = AuthLayout,
8
+ accept,
9
+ onSignedIn,
10
+ signInPath = "/sign-in",
11
+ title = "You\u2019re invited",
12
+ subtitle = "Choose a password to finish setting up your access."
13
+ }) {
14
+ const [params] = useSearchParams();
15
+ const { signedIn } = useAuth();
16
+ const email = params.get("email") || "";
17
+ const token = params.get("token") || "";
18
+ const [password, setPassword] = useState("");
19
+ const [confirmation, setConfirmation] = useState("");
20
+ const [error, setError] = useState(null);
21
+ const [saving, setSaving] = useState(false);
22
+ const onSubmit = async (e) => {
23
+ e.preventDefault();
24
+ if (password !== confirmation) {
25
+ setError("The passwords don\u2019t match.");
26
+ return;
27
+ }
28
+ setSaving(true);
29
+ setError(null);
30
+ try {
31
+ const data = await accept({ email, token, password, password_confirmation: confirmation });
32
+ onSignedIn?.(signedIn(data));
33
+ } catch (err) {
34
+ setError(err.response?.data?.errors?.password?.[0] || err.response?.data?.message || "Something went wrong. Try again.");
35
+ } finally {
36
+ setSaving(false);
37
+ }
38
+ };
39
+ return /* @__PURE__ */ jsx(
40
+ Layout,
41
+ {
42
+ title,
43
+ subtitle,
44
+ footer: /* @__PURE__ */ jsxs(Fragment, { children: [
45
+ "Already set up? ",
46
+ /* @__PURE__ */ jsx(Link, { to: signInPath, className: "font-medium text-accent-strong hover:underline", children: "Sign in" })
47
+ ] }),
48
+ children: !email || !token ? /* @__PURE__ */ jsx(AuthError, { children: "This invitation link is incomplete. Open the link from your email again, or ask for a new invitation." }) : /* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-5", children: [
49
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
50
+ /* @__PURE__ */ jsx(AuthField, { id: "invite-email", label: "Email", value: email, readOnly: true }),
51
+ /* @__PURE__ */ jsx(
52
+ AuthField,
53
+ {
54
+ id: "invite-password",
55
+ label: "Password",
56
+ type: "password",
57
+ autoComplete: "new-password",
58
+ minLength: 8,
59
+ required: true,
60
+ placeholder: "At least 8 characters",
61
+ value: password,
62
+ onChange: (e) => setPassword(e.target.value)
63
+ }
64
+ ),
65
+ /* @__PURE__ */ jsx(
66
+ AuthField,
67
+ {
68
+ id: "invite-password-confirm",
69
+ label: "Confirm password",
70
+ type: "password",
71
+ autoComplete: "new-password",
72
+ minLength: 8,
73
+ required: true,
74
+ placeholder: "Type it again",
75
+ value: confirmation,
76
+ onChange: (e) => setConfirmation(e.target.value)
77
+ }
78
+ ),
79
+ /* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsx(AuthSubmit, { loading: saving, children: "Set password & continue" }) })
80
+ ] })
81
+ }
82
+ );
83
+ }
84
+ export {
85
+ AcceptInvitePage as default
86
+ };
@@ -0,0 +1,73 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useRef, useState } from "react";
3
+ import { Link } from "react-router-dom";
4
+ import { AnimatePresence, motion } from "framer-motion";
5
+ import { ChevronDown, LogOut } from "lucide-react";
6
+ import { useDismiss } from "@okjt/ui";
7
+ import { useAuth } from "./AuthContext.js";
8
+ function AccountMenu({ compactLinks = [], links = [], roleText, extra, fallbackName = "Admin" }) {
9
+ const { user, logout } = useAuth();
10
+ const [open, setOpen] = useState(false);
11
+ const ref = useRef(null);
12
+ const close = useCallback(() => setOpen(false), []);
13
+ useDismiss(ref, open, close);
14
+ const handleLogout = async () => {
15
+ close();
16
+ await logout();
17
+ };
18
+ const initial = user?.name?.charAt(0)?.toUpperCase() || fallbackName.charAt(0).toUpperCase();
19
+ const itemClass = "flex items-center gap-3 px-4 py-2.5 text-sm text-tone-700 hover:bg-paper-warm focus:bg-paper-warm focus:outline-none";
20
+ return /* @__PURE__ */ jsxs("div", { className: "relative", ref, children: [
21
+ /* @__PURE__ */ jsxs(
22
+ "button",
23
+ {
24
+ id: "header-account",
25
+ type: "button",
26
+ onClick: () => setOpen((v) => !v),
27
+ "aria-haspopup": "menu",
28
+ "aria-expanded": open,
29
+ "aria-label": `Account menu for ${user?.name || fallbackName.toLowerCase()}`,
30
+ className: "flex items-center gap-2 p-1 pr-2 rounded-full hover:bg-black/5 transition-colors",
31
+ children: [
32
+ /* @__PURE__ */ jsx("span", { className: "w-8 h-8 rounded-full flex items-center justify-center text-white text-sm font-medium bg-accent", children: initial }),
33
+ /* @__PURE__ */ jsx("span", { className: "hidden xl:block max-w-[8rem] truncate text-sm font-medium text-body", children: user?.name || fallbackName }),
34
+ /* @__PURE__ */ jsx(ChevronDown, { className: `w-4 h-4 text-tone-400 transition-transform ${open ? "rotate-180" : ""}` })
35
+ ]
36
+ }
37
+ ),
38
+ /* @__PURE__ */ jsx(AnimatePresence, { children: open && /* @__PURE__ */ jsxs(
39
+ motion.div,
40
+ {
41
+ role: "menu",
42
+ initial: { opacity: 0, y: 8, scale: 0.97 },
43
+ animate: { opacity: 1, y: 0, scale: 1 },
44
+ exit: { opacity: 0, y: 8, scale: 0.97 },
45
+ transition: { duration: 0.15 },
46
+ className: "absolute right-0 top-full mt-2 w-64 bg-white rounded-2xl shadow-xl border border-tone-100 py-2 z-50",
47
+ children: [
48
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 border-b border-tone-100 mb-1", children: [
49
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-semibold text-tone-800 truncate", children: user?.name || fallbackName }),
50
+ user?.email && /* @__PURE__ */ jsx("p", { className: "text-xs text-tone-500 truncate", children: user.email }),
51
+ roleText && /* @__PURE__ */ jsx("p", { className: "text-[11px] text-accent font-medium mt-0.5", children: roleText })
52
+ ] }),
53
+ extra?.({ itemClass, close }),
54
+ compactLinks.length > 0 && /* @__PURE__ */ jsx("div", { className: "md:hidden border-b border-tone-100 pb-1 mb-1", children: compactLinks.map((link) => /* @__PURE__ */ jsxs(Link, { to: link.path, role: "menuitem", onClick: close, className: itemClass, children: [
55
+ /* @__PURE__ */ jsx(link.icon, { className: "w-4 h-4 text-accent" }),
56
+ link.label
57
+ ] }, link.path)) }),
58
+ links.map((link) => /* @__PURE__ */ jsxs(Link, { id: link.id, to: link.path, role: "menuitem", onClick: close, className: itemClass, children: [
59
+ /* @__PURE__ */ jsx(link.icon, { className: "w-4 h-4 text-accent" }),
60
+ link.label
61
+ ] }, link.path)),
62
+ /* @__PURE__ */ jsx("div", { className: "border-t border-tone-100 mt-1 pt-1", children: /* @__PURE__ */ jsxs("button", { type: "button", role: "menuitem", onClick: handleLogout, className: `${itemClass} w-full text-red-600`, children: [
63
+ /* @__PURE__ */ jsx(LogOut, { className: "w-4 h-4" }),
64
+ "Log out"
65
+ ] }) })
66
+ ]
67
+ }
68
+ ) })
69
+ ] });
70
+ }
71
+ export {
72
+ AccountMenu as default
73
+ };
@@ -43,7 +43,7 @@ function AdminFloatingToolbar({
43
43
  className: "admin-floating-toolbar flex flex-wrap items-center justify-center gap-1 sm:gap-2 p-1.5 sm:p-2 rounded-2xl border border-white/40 shadow-2xl backdrop-blur-md",
44
44
  style: {
45
45
  background: "rgba(255, 249, 245, 0.92)",
46
- boxShadow: "0 12px 40px rgba(74, 63, 53, 0.18)"
46
+ boxShadow: "0 12px 40px color-mix(in srgb, var(--color-body) 18%, transparent)"
47
47
  },
48
48
  children: [
49
49
  searchProps && /* @__PURE__ */ jsx(AdminToolbarSearch, { ...searchProps }),
@@ -37,7 +37,7 @@ function AdminPageHero({ title, description, breadcrumb, icon }) {
37
37
  transition: { duration: 0.15 },
38
38
  className: "flex items-center gap-2 min-w-0",
39
39
  children: [
40
- icon && /* @__PURE__ */ jsx("div", { className: "w-8 h-8 rounded-lg flex items-center justify-center shrink-0", style: { background: "rgba(166, 123, 91, 0.1)" }, children: icon }),
40
+ icon && /* @__PURE__ */ jsx("div", { className: "w-8 h-8 rounded-lg flex items-center justify-center shrink-0", style: { background: "color-mix(in srgb, var(--color-accent) 10%, transparent)" }, children: icon }),
41
41
  /* @__PURE__ */ jsxs("div", { className: "min-w-0 leading-tight", children: [
42
42
  parent && /* @__PURE__ */ jsx("p", { className: "hidden sm:block text-[11px] text-tone-400 truncate", children: parent.path ? /* @__PURE__ */ jsx(Link, { to: parent.path, className: "hover:text-accent", children: parent.label }) : parent.label }),
43
43
  /* @__PURE__ */ jsx("p", { className: "text-base font-semibold text-body truncate", children: title })
@@ -78,7 +78,7 @@ function AdminPageHero({ title, description, breadcrumb, icon }) {
78
78
  "div",
79
79
  {
80
80
  className: "w-10 h-10 rounded-xl flex items-center justify-center",
81
- style: { background: "rgba(166, 123, 91, 0.1)" },
81
+ style: { background: "color-mix(in srgb, var(--color-accent) 10%, transparent)" },
82
82
  children: icon
83
83
  }
84
84
  ),
@@ -87,11 +87,11 @@ function AdminPageHero({ title, description, breadcrumb, icon }) {
87
87
  "h1",
88
88
  {
89
89
  className: "text-2xl md:text-3xl font-semibold",
90
- style: { color: "#4A3F35" },
90
+ style: { color: "var(--color-body)" },
91
91
  children: title
92
92
  }
93
93
  ),
94
- description && /* @__PURE__ */ jsx("p", { className: "text-sm mt-0.5", style: { color: "#8B7B6B" }, children: description })
94
+ description && /* @__PURE__ */ jsx("p", { className: "text-sm mt-0.5", style: { color: "var(--color-muted)" }, children: description })
95
95
  ] })
96
96
  ] }) })
97
97
  ] });
@@ -25,7 +25,7 @@ function AdminSummaryCards({ cards = [], columns = 4 }) {
25
25
  transition: { delay: index * 0.05, duration: 0.2 },
26
26
  "aria-pressed": stat.onClick ? !!stat.active : void 0,
27
27
  className: `px-3.5 py-3 rounded-2xl bg-white flex items-center gap-3 text-left min-w-0 transition-shadow ${stat.onClick ? "cursor-pointer hover:ring-2 hover:ring-accent/20" : ""} ${stat.active ? "ring-2 ring-accent/50" : ""}`,
28
- style: { boxShadow: "0 4px 20px rgba(166, 123, 91, 0.08)" },
28
+ style: { boxShadow: "0 4px 20px color-mix(in srgb, var(--color-accent) 8%, transparent)" },
29
29
  children: [
30
30
  /* @__PURE__ */ jsx(
31
31
  "div",
@@ -13,12 +13,13 @@ function AdminTutorial({ steps, onComplete, isRestarted = false }) {
13
13
  if (boxRef.current) setBoxHeight(boxRef.current.offsetHeight);
14
14
  }, [currentStep, isVisible, coords]);
15
15
  useEffect(() => {
16
+ if (!steps?.length) return void 0;
16
17
  const isCompleted = localStorage.getItem("admin-tutorial-complete");
17
18
  if (!isCompleted || isRestarted) {
18
19
  const timer = setTimeout(() => setIsVisible(true), 1e3);
19
20
  return () => clearTimeout(timer);
20
21
  }
21
- }, [isRestarted]);
22
+ }, [isRestarted, steps?.length]);
22
23
  useEffect(() => {
23
24
  if (isVisible) {
24
25
  const step2 = steps[currentStep];
@@ -114,7 +115,7 @@ function AdminTutorial({ steps, onComplete, isRestarted = false }) {
114
115
  top = Math.min(Math.max(margin, top), vh - margin - boxH);
115
116
  return { style: { top, left, width: boxW }, placement: placement2 };
116
117
  };
117
- if (!isVisible) return null;
118
+ if (!isVisible || !steps?.length) return null;
118
119
  const step = steps[currentStep];
119
120
  const { style: boxStyle, placement } = getBoxStyle();
120
121
  return /* @__PURE__ */ jsxs("div", { className: "fixed inset-0 z-[100] pointer-events-none", children: [
@@ -143,6 +143,10 @@ function AuthProvider({ api, extend, children }) {
143
143
  setUser({ ...authUser, ...extra });
144
144
  setIsAuthenticated(true);
145
145
  };
146
+ const signedIn = ({ token, user: authUser, ...extra }) => {
147
+ loginWithToken(token, authUser, extra);
148
+ return { success: true, ...extra };
149
+ };
146
150
  const logout = async () => {
147
151
  try {
148
152
  await api.post("/logout");
@@ -165,6 +169,7 @@ function AuthProvider({ api, extend, children }) {
165
169
  register,
166
170
  verify2fa,
167
171
  loginWithToken,
172
+ signedIn,
168
173
  loginWithGoogle,
169
174
  resendVerification,
170
175
  verifyEmail,
@@ -0,0 +1,94 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { motion } from "framer-motion";
4
+ import { AlertCircle, ArrowLeft, Eye, EyeOff, Loader2 } from "lucide-react";
5
+ import { Link } from "react-router-dom";
6
+ function AuthLayout({ title, subtitle, children, footer, brand, backLabel = "Back to the website", aside }) {
7
+ return /* @__PURE__ */ jsx("div", { className: "auth-page min-h-dvh flex items-center justify-center p-3 sm:p-6 lg:p-10 bg-tint", children: /* @__PURE__ */ jsxs(
8
+ motion.div,
9
+ {
10
+ initial: { opacity: 0, y: 16 },
11
+ animate: { opacity: 1, y: 0 },
12
+ transition: { duration: 0.45 },
13
+ className: `w-full ${aside ? "max-w-6xl grid lg:grid-cols-2" : "max-w-xl grid"} gap-3 p-3 rounded-[2rem] bg-paper border border-white shadow-[0_30px_80px_-30px_color-mix(in_srgb,var(--color-body)_35%,transparent)]`,
14
+ children: [
15
+ /* @__PURE__ */ jsxs("section", { className: "flex flex-col px-5 py-8 sm:px-10 lg:px-14 lg:py-12", children: [
16
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4", children: [
17
+ brand && /* @__PURE__ */ jsx(Link, { to: "/", className: "flex items-center gap-2.5", "aria-label": "Back to the home page", children: brand }),
18
+ /* @__PURE__ */ jsxs(Link, { to: "/", className: "inline-flex items-center gap-1.5 rounded-full border border-line px-3 py-1.5 text-xs font-medium text-soft hover:border-accent hover:text-ink", children: [
19
+ /* @__PURE__ */ jsx(ArrowLeft, { className: "h-3.5 w-3.5", "aria-hidden": "true" }),
20
+ backLabel
21
+ ] })
22
+ ] }),
23
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col justify-center w-full max-w-sm mx-auto lg:mx-0 py-10", children: [
24
+ /* @__PURE__ */ jsx("h1", { className: "!text-3xl !font-semibold tracking-tight !text-ink", children: title }),
25
+ subtitle && /* @__PURE__ */ jsx("div", { className: "mt-2 text-sm leading-relaxed text-muted", children: subtitle }),
26
+ /* @__PURE__ */ jsx("div", { className: "mt-8", children })
27
+ ] }),
28
+ footer && /* @__PURE__ */ jsx("div", { className: "w-full max-w-sm mx-auto lg:mx-0 text-sm text-muted", children: footer })
29
+ ] }),
30
+ aside
31
+ ]
32
+ }
33
+ ) });
34
+ }
35
+ const fieldClass = "w-full h-12 px-5 rounded-full bg-white border border-line text-sm text-ink placeholder:text-[var(--okjt-auth-placeholder,var(--color-faint))] shadow-[0_1px_2px_color-mix(in_srgb,var(--color-body)_4%,transparent)] outline-none transition focus:border-[var(--okjt-auth-focus,var(--color-accent))] focus:ring-4 focus:ring-[var(--okjt-auth-focus,var(--color-accent))]/15 read-only:bg-tint read-only:text-muted";
36
+ function AuthField({ id, label, type = "text", error, className = "", inputClassName = "", ...props }) {
37
+ const [visible, setVisible] = useState(false);
38
+ const isPassword = type === "password";
39
+ return /* @__PURE__ */ jsxs("div", { className, children: [
40
+ /* @__PURE__ */ jsx("label", { htmlFor: id, className: "block text-xs font-semibold text-body mb-2", children: label }),
41
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
42
+ /* @__PURE__ */ jsx(
43
+ "input",
44
+ {
45
+ id,
46
+ type: isPassword && visible ? "text" : type,
47
+ "aria-invalid": error ? "true" : void 0,
48
+ "aria-describedby": error ? `${id}-error` : void 0,
49
+ className: `${fieldClass} ${isPassword ? "pr-12" : ""} ${error ? "!border-red-300" : ""} ${inputClassName}`,
50
+ ...props
51
+ }
52
+ ),
53
+ isPassword && /* @__PURE__ */ jsx(
54
+ "button",
55
+ {
56
+ type: "button",
57
+ onClick: () => setVisible((v) => !v),
58
+ "aria-label": visible ? "Hide password" : "Show password",
59
+ className: "absolute right-3 top-1/2 -translate-y-1/2 p-1.5 rounded-full text-faint hover:text-body hover:bg-tint",
60
+ children: visible ? /* @__PURE__ */ jsx(EyeOff, { className: "w-4 h-4" }) : /* @__PURE__ */ jsx(Eye, { className: "w-4 h-4" })
61
+ }
62
+ )
63
+ ] }),
64
+ error && /* @__PURE__ */ jsx("div", { id: `${id}-error`, className: "mt-1.5 pl-5 text-xs text-red-600", children: error })
65
+ ] });
66
+ }
67
+ function AuthSubmit({ loading, children, ...props }) {
68
+ return /* @__PURE__ */ jsxs(
69
+ "button",
70
+ {
71
+ type: "submit",
72
+ disabled: loading,
73
+ className: "w-full h-12 rounded-full text-sm font-semibold text-white bg-gradient-to-r from-accent-dark via-accent-strong to-[var(--okjt-auth-glow,var(--color-accent-soft))] shadow-[0_10px_24px_-10px_color-mix(in_srgb,var(--color-accent-strong)_80%,transparent)] transition hover:brightness-105 active:brightness-95 disabled:opacity-70 flex items-center justify-center gap-2 focus-visible:outline-none focus-visible:ring-4 focus-visible:ring-[var(--okjt-auth-focus,var(--color-accent))]/30",
74
+ ...props,
75
+ children: [
76
+ loading && /* @__PURE__ */ jsx(Loader2, { className: "w-4 h-4 animate-spin", "aria-hidden": "true" }),
77
+ children
78
+ ]
79
+ }
80
+ );
81
+ }
82
+ function AuthError({ children }) {
83
+ if (!children) return null;
84
+ return /* @__PURE__ */ jsxs("div", { role: "alert", className: "mb-5 flex items-start gap-2.5 rounded-2xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700", children: [
85
+ /* @__PURE__ */ jsx(AlertCircle, { className: "w-4 h-4 mt-0.5 shrink-0" }),
86
+ /* @__PURE__ */ jsx("span", { children })
87
+ ] });
88
+ }
89
+ export {
90
+ AuthError,
91
+ AuthField,
92
+ AuthSubmit,
93
+ AuthLayout as default
94
+ };
@@ -0,0 +1,81 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ import { useSearchParams } from "react-router-dom";
4
+ import { useAuth } from "./AuthContext.js";
5
+ import AuthLayout, { AuthError } from "./AuthLayout.js";
6
+ import TwoFactorForm from "./TwoFactorForm.js";
7
+ function GoogleCallbackPage({ layout: Layout = AuthLayout, onSignedIn, signInPath = "/sign-in" }) {
8
+ const [params] = useSearchParams();
9
+ const { loginWithGoogle, verify2fa } = useAuth();
10
+ const [error, setError] = useState(null);
11
+ const [needs2fa, setNeeds2fa] = useState(false);
12
+ const [emailFor2fa, setEmailFor2fa] = useState("");
13
+ const [code2fa, setCode2fa] = useState("");
14
+ const [loading, setLoading] = useState(true);
15
+ const code = params.get("code");
16
+ useEffect(() => {
17
+ if (!code) {
18
+ setError("Missing sign-in code \u2014 start again from the sign-in page.");
19
+ setLoading(false);
20
+ return;
21
+ }
22
+ let cancelled = false;
23
+ (async () => {
24
+ const result = await loginWithGoogle(code);
25
+ if (cancelled) return;
26
+ if (result.requires_2fa) {
27
+ setNeeds2fa(true);
28
+ setEmailFor2fa(result.email);
29
+ setLoading(false);
30
+ return;
31
+ }
32
+ if (result.success) {
33
+ const problem = onSignedIn?.(result);
34
+ if (typeof problem === "string") {
35
+ setError(problem);
36
+ setLoading(false);
37
+ }
38
+ return;
39
+ }
40
+ setError(result.message);
41
+ setLoading(false);
42
+ })();
43
+ return () => {
44
+ cancelled = true;
45
+ };
46
+ }, [code]);
47
+ const handle2fa = async (e) => {
48
+ e.preventDefault();
49
+ setLoading(true);
50
+ setError(null);
51
+ const result = await verify2fa(emailFor2fa, code2fa);
52
+ if (result.success) {
53
+ const problem = onSignedIn?.(result);
54
+ if (typeof problem === "string") setError(problem);
55
+ } else {
56
+ setError(result.message);
57
+ setLoading(false);
58
+ }
59
+ };
60
+ if (needs2fa) {
61
+ return /* @__PURE__ */ jsxs(
62
+ Layout,
63
+ {
64
+ title: "Two-step verification",
65
+ subtitle: "Enter the 6-digit code from your authenticator app to finish signing in.",
66
+ children: [
67
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
68
+ /* @__PURE__ */ jsx(TwoFactorForm, { id: "google-2fa-code", code: code2fa, onCode: setCode2fa, loading, onSubmit: handle2fa })
69
+ ]
70
+ }
71
+ );
72
+ }
73
+ return /* @__PURE__ */ jsxs(Layout, { title: "Signing you in", subtitle: "Finishing your Google sign-in\u2026", children: [
74
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
75
+ !error && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted", children: "Hang tight." }),
76
+ error && /* @__PURE__ */ jsx("a", { href: signInPath, className: "inline-flex text-sm font-semibold text-body underline underline-offset-4", children: "Back to sign in" })
77
+ ] });
78
+ }
79
+ export {
80
+ GoogleCallbackPage as default
81
+ };
@@ -96,7 +96,7 @@ function NotificationsBell() {
96
96
  "span",
97
97
  {
98
98
  className: "absolute top-1 right-1 w-2 h-2 rounded-full",
99
- style: { background: "#A67B5B", display: unreadCount > 0 ? "block" : "none" }
99
+ style: { background: "var(--color-accent)", display: unreadCount > 0 ? "block" : "none" }
100
100
  }
101
101
  )
102
102
  ]
@@ -0,0 +1,198 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useForm } from "react-hook-form";
4
+ import { useAuth } from "./AuthContext.js";
5
+ import AuthLayout, { AuthError, AuthField, AuthSubmit } from "./AuthLayout.js";
6
+ import TwoFactorForm from "./TwoFactorForm.js";
7
+ import { loginWithPasskey, passkeysSupported } from "./passkeys.js";
8
+ function SignInPage({
9
+ layout: Layout = AuthLayout,
10
+ onSignedIn,
11
+ title = "Welcome back",
12
+ subtitle,
13
+ footer,
14
+ forgotHint,
15
+ google,
16
+ idPrefix = "sign-in"
17
+ }) {
18
+ const { login, verify2fa, resendVerification, signedIn } = useAuth();
19
+ const [error, setError] = useState(null);
20
+ const [loading, setLoading] = useState(false);
21
+ const [is2faRequired, setIs2faRequired] = useState(false);
22
+ const [emailFor2fa, setEmailFor2fa] = useState("");
23
+ const [twoFactorCode, setTwoFactorCode] = useState("");
24
+ const [needsVerification, setNeedsVerification] = useState(null);
25
+ const [resendState, setResendState] = useState(null);
26
+ const { register, handleSubmit, formState: { errors } } = useForm();
27
+ const done = (result) => {
28
+ const problem = onSignedIn?.(result);
29
+ if (typeof problem === "string") setError(problem);
30
+ };
31
+ const onSubmit = async (data) => {
32
+ setLoading(true);
33
+ setError(null);
34
+ const result = await login(data.email, data.password);
35
+ if (result.requires_verification) {
36
+ setNeedsVerification(result.email);
37
+ setError(null);
38
+ } else if (result.success) {
39
+ if (result.requires_2fa) {
40
+ setIs2faRequired(true);
41
+ setEmailFor2fa(result.email);
42
+ } else {
43
+ done(result);
44
+ }
45
+ } else {
46
+ setError(result.message);
47
+ }
48
+ setLoading(false);
49
+ };
50
+ const handleResend = async () => {
51
+ setResendState("sending");
52
+ const result = await resendVerification(needsVerification);
53
+ setResendState(result.success ? "sent" : result.message);
54
+ };
55
+ const handlePasskey = async () => {
56
+ setLoading(true);
57
+ setError(null);
58
+ try {
59
+ const result = await loginWithPasskey();
60
+ if (result.requires_verification) {
61
+ setNeedsVerification(result.email);
62
+ return;
63
+ }
64
+ if (result.requires_2fa) {
65
+ setIs2faRequired(true);
66
+ setEmailFor2fa(result.email);
67
+ return;
68
+ }
69
+ done(signedIn(result));
70
+ } catch (err) {
71
+ setError(err.message || "Passkey sign-in failed.");
72
+ } finally {
73
+ setLoading(false);
74
+ }
75
+ };
76
+ const handle2faVerify = async (e) => {
77
+ e.preventDefault();
78
+ setLoading(true);
79
+ setError(null);
80
+ const result = await verify2fa(emailFor2fa, twoFactorCode);
81
+ if (result.success) {
82
+ done(result);
83
+ } else {
84
+ setError(result.message);
85
+ }
86
+ setLoading(false);
87
+ };
88
+ if (needsVerification) {
89
+ return /* @__PURE__ */ jsxs(
90
+ Layout,
91
+ {
92
+ title: "Verify your email",
93
+ subtitle: "One quick step \u2014 we sent a verification link so we know this address is yours.",
94
+ footer: /* @__PURE__ */ jsx("button", { type: "button", onClick: () => {
95
+ setNeedsVerification(null);
96
+ setResendState(null);
97
+ }, className: "hover:text-body", children: "\u2190 Back to sign in" }),
98
+ children: [
99
+ /* @__PURE__ */ jsxs("p", { className: "text-sm text-muted mb-4", children: [
100
+ "Open ",
101
+ /* @__PURE__ */ jsx("strong", { className: "text-body", children: needsVerification }),
102
+ " and click the link we just sent. After that, sign in as usual."
103
+ ] }),
104
+ resendState === "sent" && /* @__PURE__ */ jsx("p", { className: "text-sm text-green-700 mb-4", children: "Sent \u2014 check your inbox (and spam, just in case)." }),
105
+ typeof resendState === "string" && resendState !== "sent" && resendState !== "sending" && /* @__PURE__ */ jsx("p", { className: "text-sm text-red-600 mb-4", children: resendState }),
106
+ /* @__PURE__ */ jsx(
107
+ "button",
108
+ {
109
+ type: "button",
110
+ onClick: handleResend,
111
+ disabled: resendState === "sending",
112
+ className: "text-sm font-semibold text-accent-strong hover:underline disabled:opacity-50",
113
+ children: resendState === "sending" ? "Sending\u2026" : "Resend the email"
114
+ }
115
+ )
116
+ ]
117
+ }
118
+ );
119
+ }
120
+ if (is2faRequired) {
121
+ return /* @__PURE__ */ jsxs(
122
+ Layout,
123
+ {
124
+ title: "Two-step verification",
125
+ subtitle: "Enter the 6-digit code from your authenticator app to finish signing in.",
126
+ footer: /* @__PURE__ */ jsx("button", { type: "button", onClick: () => {
127
+ setIs2faRequired(false);
128
+ setError(null);
129
+ }, className: "hover:text-body", children: "\u2190 Use a different account" }),
130
+ children: [
131
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
132
+ /* @__PURE__ */ jsx(TwoFactorForm, { id: `${idPrefix}-2fa`, code: twoFactorCode, onCode: setTwoFactorCode, loading, onSubmit: handle2faVerify })
133
+ ]
134
+ }
135
+ );
136
+ }
137
+ return /* @__PURE__ */ jsxs(Layout, { title, subtitle, footer, children: [
138
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
139
+ /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit(onSubmit), className: "space-y-5", noValidate: true, children: [
140
+ /* @__PURE__ */ jsx(
141
+ AuthField,
142
+ {
143
+ id: `${idPrefix}-email`,
144
+ label: "Email",
145
+ type: "email",
146
+ autoComplete: "email",
147
+ placeholder: "you@example.com",
148
+ error: errors.email?.message,
149
+ ...register("email", {
150
+ required: "Email is required",
151
+ pattern: {
152
+ value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
153
+ message: "Invalid email address"
154
+ }
155
+ })
156
+ }
157
+ ),
158
+ /* @__PURE__ */ jsx(
159
+ AuthField,
160
+ {
161
+ id: `${idPrefix}-password`,
162
+ label: "Password",
163
+ type: "password",
164
+ autoComplete: "current-password",
165
+ placeholder: "Type your password",
166
+ error: errors.password?.message,
167
+ ...register("password", {
168
+ required: "Password is required",
169
+ minLength: { value: 6, message: "Password must be at least 6 characters" }
170
+ })
171
+ }
172
+ ),
173
+ forgotHint && /* @__PURE__ */ jsx("div", { className: "text-xs text-faint text-right -mt-1", children: forgotHint }),
174
+ /* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsx(AuthSubmit, { loading, children: loading ? "Signing in\u2026" : "Sign in" }) })
175
+ ] }),
176
+ /* @__PURE__ */ jsxs("div", { className: "relative my-5", "aria-hidden": "true", children: [
177
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center", children: /* @__PURE__ */ jsx("div", { className: "w-full border-t border-tone-200" }) }),
178
+ /* @__PURE__ */ jsx("div", { className: "relative flex justify-center text-xs", children: /* @__PURE__ */ jsx("span", { className: "bg-white px-3 text-faint", children: "or" }) })
179
+ ] }),
180
+ passkeysSupported() && /* @__PURE__ */ jsxs(
181
+ "button",
182
+ {
183
+ type: "button",
184
+ onClick: handlePasskey,
185
+ disabled: loading,
186
+ className: "mb-3 flex w-full items-center justify-center gap-2 rounded-full border border-tone-200 bg-white px-4 py-3 text-sm font-semibold text-ink shadow-sm transition-colors hover:bg-tone-50 disabled:opacity-50",
187
+ children: [
188
+ /* @__PURE__ */ jsx("svg", { className: "h-5 w-5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: "1.8", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M15.75 5.25a3 3 0 0 1 3 3m3 0a6 6 0 0 1-7.029 5.912c-.563-.097-1.159.026-1.563.43L10.5 17.25H8.25v2.25H6v2.25H2.25v-2.818c0-.597.237-1.17.659-1.591l6.499-6.499c.404-.404.527-1 .43-1.563A6 6 0 1 1 21.75 8.25Z" }) }),
189
+ "Sign in with a passkey"
190
+ ]
191
+ }
192
+ ),
193
+ google
194
+ ] });
195
+ }
196
+ export {
197
+ SignInPage as default
198
+ };
package/dist/StatCard.js CHANGED
@@ -8,7 +8,7 @@ function StatCard({ icon, label, value, color }) {
8
8
  className: "p-6 rounded-2xl transition-all hover:scale-[1.02]",
9
9
  style: {
10
10
  background: "white",
11
- boxShadow: "0 4px 20px rgba(166, 123, 91, 0.08)"
11
+ boxShadow: "0 4px 20px color-mix(in srgb, var(--color-accent) 8%, transparent)"
12
12
  },
13
13
  children: [
14
14
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-4", children: [
@@ -0,0 +1,26 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { AuthField, AuthSubmit } from "./AuthLayout.js";
3
+ function TwoFactorForm({ id, code, onCode, loading, onSubmit }) {
4
+ return /* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-6", children: [
5
+ /* @__PURE__ */ jsx(
6
+ AuthField,
7
+ {
8
+ id,
9
+ label: "Verification code",
10
+ value: code,
11
+ onChange: (e) => onCode(e.target.value.replace(/\D/g, "")),
12
+ inputMode: "numeric",
13
+ autoComplete: "one-time-code",
14
+ placeholder: "000000",
15
+ maxLength: 6,
16
+ required: true,
17
+ autoFocus: true,
18
+ inputClassName: "text-center text-xl tracking-[0.6em] font-semibold"
19
+ }
20
+ ),
21
+ /* @__PURE__ */ jsx(AuthSubmit, { loading, children: loading ? "Verifying\u2026" : "Verify & sign in" })
22
+ ] });
23
+ }
24
+ export {
25
+ TwoFactorForm as default
26
+ };
@@ -0,0 +1,42 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ import { useNavigate, useParams } from "react-router-dom";
4
+ import { useAuth } from "./AuthContext.js";
5
+ import AuthLayout, { AuthError } from "./AuthLayout.js";
6
+ function VerifyEmailPage({ layout: Layout = AuthLayout, next = "/", signInPath = "/sign-in" }) {
7
+ const { id, hash } = useParams();
8
+ const navigate = useNavigate();
9
+ const { verifyEmail } = useAuth();
10
+ const [error, setError] = useState(null);
11
+ const [done, setDone] = useState(false);
12
+ useEffect(() => {
13
+ let cancelled = false;
14
+ (async () => {
15
+ const result = await verifyEmail({ id, hash });
16
+ if (cancelled) return;
17
+ if (result.success) {
18
+ setDone(true);
19
+ setTimeout(() => navigate(next, { replace: true }), 1200);
20
+ } else {
21
+ setError(result.message);
22
+ }
23
+ })();
24
+ return () => {
25
+ cancelled = true;
26
+ };
27
+ }, [id, hash]);
28
+ return /* @__PURE__ */ jsxs(
29
+ Layout,
30
+ {
31
+ title: done ? "Email verified" : "Verifying\u2026",
32
+ subtitle: done ? "You\u2019re all set \u2014 taking you in." : "One moment while we confirm your address.",
33
+ children: [
34
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
35
+ error && /* @__PURE__ */ jsx("a", { href: signInPath, className: "inline-flex text-sm font-semibold text-body underline underline-offset-4", children: "Back to sign in" })
36
+ ]
37
+ }
38
+ );
39
+ }
40
+ export {
41
+ VerifyEmailPage as default
42
+ };
package/dist/index.js CHANGED
@@ -41,7 +41,15 @@ import { AuthProvider, useAuth, default as default34 } from "./AuthContext.js";
41
41
  import { default as default35 } from "./GoogleButton.js";
42
42
  import { default as default36 } from "./NotificationsBell.js";
43
43
  import { loginWithPasskey, registerPasskey, passkeysSupported } from "./passkeys.js";
44
+ import { default as default37, AuthField, AuthSubmit, AuthError } from "./AuthLayout.js";
45
+ import { default as default38 } from "./SignInPage.js";
46
+ import { default as default39 } from "./GoogleCallbackPage.js";
47
+ import { default as default40 } from "./VerifyEmailPage.js";
48
+ import { default as default41 } from "./AcceptInvitePage.js";
49
+ import { default as default42 } from "./AccountMenu.js";
44
50
  export {
51
+ default41 as AcceptInvitePage,
52
+ default42 as AccountMenu,
45
53
  default27 as ActivityPanel,
46
54
  default11 as AdminBulkActions,
47
55
  default12 as AdminCard,
@@ -61,7 +69,11 @@ export {
61
69
  default7 as AdminToolbarSearch,
62
70
  default20 as AdminTutorial,
63
71
  default34 as AuthContext,
72
+ AuthError,
73
+ AuthField,
74
+ default37 as AuthLayout,
64
75
  AuthProvider,
76
+ AuthSubmit,
65
77
  CollaborationProvider,
66
78
  CollaboratorAvatar,
67
79
  default26 as CollaboratorAvatars,
@@ -73,6 +85,7 @@ export {
73
85
  default14 as EditableFieldset,
74
86
  default17 as EmptyState,
75
87
  default35 as GoogleButton,
88
+ default39 as GoogleCallbackPage,
76
89
  HEARTBEAT_MS,
77
90
  default36 as NotificationsBell,
78
91
  default18 as QueryError,
@@ -81,9 +94,11 @@ export {
81
94
  SidePanelAside,
82
95
  SidePanelMobileBar,
83
96
  SidePanelNav,
97
+ default38 as SignInPage,
84
98
  default5 as StatCard,
85
99
  default16 as ToggleButton,
86
100
  default19 as UnsavedChangesStatus,
101
+ default40 as VerifyEmailPage,
87
102
  default29 as VersionHistoryDrawer,
88
103
  collaboratorColor,
89
104
  countActiveFilters,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@okjt/dashboard",
3
- "version": "0.1.0",
4
- "description": "Dashboard pages for OKJTech projects: page layout, hero, summary cards, floating toolbar with search and filters, side panel, lists, bulk actions, one way to save, and working together: presence, version history, sharing",
3
+ "version": "0.2.1",
4
+ "description": "Dashboard pages for OKJTech projects: page layout, hero, summary cards, floating toolbar with search and filters, side panel, lists, bulk actions, one way to save, and working together: presence, version history, sharing; the dashboard shell, sign-in pages and account menu",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -32,6 +32,7 @@
32
32
  "lucide-react": ">=0.400.0",
33
33
  "react": ">=18",
34
34
  "react-dom": ">=18",
35
+ "react-hook-form": ">=7",
35
36
  "react-hot-toast": ">=2",
36
37
  "react-router-dom": ">=6.4"
37
38
  },