@okjt/dashboard 0.3.0 → 0.4.0
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/dist/AdminFloatingToolbar.js +7 -1
- package/dist/AdminPageHero.js +69 -4
- package/dist/AdminPageLayout.js +24 -2
- package/dist/AdminSidePanel.js +87 -39
- package/dist/AdminSummaryCards.js +64 -1
- package/dist/AuthContext.js +95 -56
- package/dist/BoldToolbar.js +272 -0
- package/dist/ConfirmPasswordPage.js +41 -0
- package/dist/DashboardHeader.js +1 -1
- package/dist/DashboardIcon.js +15 -0
- package/dist/DashboardProvider.js +10 -1
- package/dist/EmptyState.js +42 -11
- package/dist/ForgotPasswordPage.js +39 -0
- package/dist/GoogleCallbackPage.js +3 -3
- package/dist/ResetPasswordPage.js +61 -0
- package/dist/SignInPage.js +125 -42
- package/dist/TwoFactorForm.js +18 -3
- package/dist/index.js +64 -51
- package/package.json +2 -2
package/dist/EmptyState.js
CHANGED
|
@@ -1,22 +1,53 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Search } from "lucide-react";
|
|
2
3
|
import { Button, Skeleton } from "@okjt/ui";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
import DashboardIcon from "./DashboardIcon.js";
|
|
5
|
+
import { useComponentDefaults } from "./DashboardProvider.js";
|
|
6
|
+
function EmptyState(ownProps) {
|
|
7
|
+
const { variant = "plain", ...props } = useComponentDefaults("EmptyState", ownProps);
|
|
8
|
+
if (props.loading) return /* @__PURE__ */ jsx(Loading, { rows: props.rows });
|
|
9
|
+
return variant === "card" ? /* @__PURE__ */ jsx(CardState, { ...props }) : /* @__PURE__ */ jsx(PlainState, { ...props });
|
|
10
|
+
}
|
|
11
|
+
function Loading({ rows = 5 }) {
|
|
12
|
+
return /* @__PURE__ */ jsx("div", { className: "p-6 space-y-4", role: "status", "aria-label": "Loading", children: Array.from({ length: rows }, (_, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
|
|
13
|
+
/* @__PURE__ */ jsx(Skeleton, { variant: "circle", width: "36px", height: "36px" }),
|
|
14
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-2", children: [
|
|
15
|
+
/* @__PURE__ */ jsx(Skeleton, { variant: "text", width: `${60 - i % 3 * 12}%` }),
|
|
16
|
+
/* @__PURE__ */ jsx(Skeleton, { variant: "text", width: "35%", height: "10px" })
|
|
17
|
+
] })
|
|
18
|
+
] }, i)) });
|
|
19
|
+
}
|
|
20
|
+
function PlainState({ icon, message, searchQuery, action }) {
|
|
13
21
|
return /* @__PURE__ */ jsxs("div", { className: "p-12 text-center text-tone-500", children: [
|
|
14
|
-
|
|
22
|
+
/* @__PURE__ */ jsx(DashboardIcon, { icon, className: "w-12 h-12 mx-auto mb-4 opacity-20" }),
|
|
15
23
|
/* @__PURE__ */ jsx("p", { children: searchQuery ? `Nothing matches \u201C${searchQuery}\u201D` : message || "No items yet" }),
|
|
16
24
|
searchQuery && /* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-tone-500", children: "Try a different search or clear the filters." }),
|
|
17
25
|
!searchQuery && action && /* @__PURE__ */ jsx(Button, { variant: "secondary", icon: action.icon, onClick: action.onClick, className: "mt-4", edit: !action.readOnly, children: action.label })
|
|
18
26
|
] });
|
|
19
27
|
}
|
|
28
|
+
function CardState({ icon, title, message, action, compact = false, search, searchQuery, filtered = false, noun = "item", onClear }) {
|
|
29
|
+
const query = (search ?? searchQuery ?? "").trim();
|
|
30
|
+
if (query || filtered) {
|
|
31
|
+
icon = "search";
|
|
32
|
+
title = query ? `No ${noun}s match \u201C${query}\u201D` : `No ${noun}s match these filters`;
|
|
33
|
+
message = query && filtered ? "Try a different search, or clear the search and filters." : query ? "Try a different search." : "Try different filters.";
|
|
34
|
+
action = onClear ? { label: query && filtered ? "Clear search and filters" : query ? "Clear search" : "Clear filters", onClick: onClear } : null;
|
|
35
|
+
}
|
|
36
|
+
return /* @__PURE__ */ jsxs("div", { className: `rounded-2xl border text-center ${compact ? "border-transparent bg-transparent px-3 py-8" : "border-contrast/10 bg-ink-deep/50 p-12"}`, children: [
|
|
37
|
+
/* @__PURE__ */ jsx("div", { className: `inline-flex items-center justify-center rounded-full bg-contrast/5 ${compact ? "mb-3 h-12 w-12" : "mb-4 h-16 w-16"}`, children: /* @__PURE__ */ jsx(DashboardIcon, { icon, fallback: icon === "search" ? Search : null, className: `${compact ? "text-xl" : "text-2xl"} text-soft` }) }),
|
|
38
|
+
title && /* @__PURE__ */ jsx("h3", { className: "mb-2 text-lg font-semibold text-ink", children: title }),
|
|
39
|
+
message && /* @__PURE__ */ jsx("p", { className: "mx-auto mb-6 max-w-md text-sm text-soft", children: message }),
|
|
40
|
+
action && /* @__PURE__ */ jsx(
|
|
41
|
+
"button",
|
|
42
|
+
{
|
|
43
|
+
type: "button",
|
|
44
|
+
onClick: action.onClick,
|
|
45
|
+
className: "rounded-xl bg-action px-5 py-2.5 text-sm font-medium text-white transition hover:brightness-125",
|
|
46
|
+
children: action.label
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
] });
|
|
50
|
+
}
|
|
20
51
|
export {
|
|
21
52
|
EmptyState as default
|
|
22
53
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { useAuth } from "./AuthContext.js";
|
|
4
|
+
import AuthLayout, { AuthError, AuthField, AuthSubmit } from "./AuthLayout.js";
|
|
5
|
+
function ForgotPasswordPage({
|
|
6
|
+
layout: Layout = AuthLayout,
|
|
7
|
+
title = "Forgot your password?",
|
|
8
|
+
subtitle = "Tell us your email address and we\u2019ll send you a link to choose a new one.",
|
|
9
|
+
footer,
|
|
10
|
+
email: initialEmail = "",
|
|
11
|
+
submitLabel = "Email me a reset link",
|
|
12
|
+
idPrefix = "forgot"
|
|
13
|
+
}) {
|
|
14
|
+
const { forgotPassword } = useAuth();
|
|
15
|
+
const [email, setEmail] = useState(initialEmail);
|
|
16
|
+
const [error, setError] = useState(null);
|
|
17
|
+
const [sent, setSent] = useState(null);
|
|
18
|
+
const [loading, setLoading] = useState(false);
|
|
19
|
+
const onSubmit = async (e) => {
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
setLoading(true);
|
|
22
|
+
setError(null);
|
|
23
|
+
const result = await forgotPassword(email);
|
|
24
|
+
if (result.success) setSent(result.message || "If that address has an account, a reset link is on its way.");
|
|
25
|
+
else setError(result.errors?.email?.[0] || result.message);
|
|
26
|
+
setLoading(false);
|
|
27
|
+
};
|
|
28
|
+
return /* @__PURE__ */ jsxs(Layout, { title, subtitle, footer, children: [
|
|
29
|
+
sent && /* @__PURE__ */ jsx("div", { role: "status", className: "mb-5 rounded-2xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-center text-sm text-emerald-700", children: sent }),
|
|
30
|
+
/* @__PURE__ */ jsx(AuthError, { children: error }),
|
|
31
|
+
/* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-5", children: [
|
|
32
|
+
/* @__PURE__ */ jsx(AuthField, { id: `${idPrefix}-email`, label: "Email", type: "email", autoComplete: "email", placeholder: "you@example.com", value: email, onChange: (e) => setEmail(e.target.value), required: true, autoFocus: true }),
|
|
33
|
+
/* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsx(AuthSubmit, { loading, children: loading ? "Sending\u2026" : submitLabel }) })
|
|
34
|
+
] })
|
|
35
|
+
] });
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
ForgotPasswordPage as default
|
|
39
|
+
};
|
|
@@ -9,7 +9,7 @@ function GoogleCallbackPage({ layout: Layout = AuthLayout, onSignedIn, signInPat
|
|
|
9
9
|
const { loginWithGoogle, verify2fa } = useAuth();
|
|
10
10
|
const [error, setError] = useState(null);
|
|
11
11
|
const [needs2fa, setNeeds2fa] = useState(false);
|
|
12
|
-
const [
|
|
12
|
+
const [challenge, setChallenge] = useState("");
|
|
13
13
|
const [code2fa, setCode2fa] = useState("");
|
|
14
14
|
const [loading, setLoading] = useState(true);
|
|
15
15
|
const code = params.get("code");
|
|
@@ -25,7 +25,7 @@ function GoogleCallbackPage({ layout: Layout = AuthLayout, onSignedIn, signInPat
|
|
|
25
25
|
if (cancelled) return;
|
|
26
26
|
if (result.requires_2fa) {
|
|
27
27
|
setNeeds2fa(true);
|
|
28
|
-
|
|
28
|
+
setChallenge(result.challenge);
|
|
29
29
|
setLoading(false);
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
@@ -48,7 +48,7 @@ function GoogleCallbackPage({ layout: Layout = AuthLayout, onSignedIn, signInPat
|
|
|
48
48
|
e.preventDefault();
|
|
49
49
|
setLoading(true);
|
|
50
50
|
setError(null);
|
|
51
|
-
const result = await verify2fa(
|
|
51
|
+
const result = await verify2fa(challenge, code2fa);
|
|
52
52
|
if (result.success) {
|
|
53
53
|
const problem = onSignedIn?.(result);
|
|
54
54
|
if (typeof problem === "string") setError(problem);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { useParams, useSearchParams } from "react-router-dom";
|
|
4
|
+
import { useAuth } from "./AuthContext.js";
|
|
5
|
+
import AuthLayout, { AuthError, AuthField, AuthSubmit } from "./AuthLayout.js";
|
|
6
|
+
function ResetPasswordPage({
|
|
7
|
+
layout: Layout = AuthLayout,
|
|
8
|
+
token: tokenProp,
|
|
9
|
+
email: emailProp,
|
|
10
|
+
onReset,
|
|
11
|
+
title = "Choose a new password",
|
|
12
|
+
subtitle = "Make it at least 8 characters. You\u2019ll sign in with it from now on.",
|
|
13
|
+
footer,
|
|
14
|
+
submitLabel = "Reset password",
|
|
15
|
+
idPrefix = "reset"
|
|
16
|
+
}) {
|
|
17
|
+
const params = useParams();
|
|
18
|
+
const [query] = useSearchParams();
|
|
19
|
+
const token = tokenProp ?? params.token ?? "";
|
|
20
|
+
const { resetPassword } = useAuth();
|
|
21
|
+
const [email, setEmail] = useState(emailProp ?? query.get("email") ?? "");
|
|
22
|
+
const [password, setPassword] = useState("");
|
|
23
|
+
const [confirmation, setConfirmation] = useState("");
|
|
24
|
+
const [errors, setErrors] = useState({});
|
|
25
|
+
const [error, setError] = useState(null);
|
|
26
|
+
const [loading, setLoading] = useState(false);
|
|
27
|
+
const onSubmit = async (e) => {
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
if (password !== confirmation) {
|
|
30
|
+
setErrors({ password_confirmation: "The passwords don\u2019t match." });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
setLoading(true);
|
|
34
|
+
setError(null);
|
|
35
|
+
setErrors({});
|
|
36
|
+
const result = await resetPassword({ token, email, password, password_confirmation: confirmation });
|
|
37
|
+
setLoading(false);
|
|
38
|
+
if (result.success) {
|
|
39
|
+
onReset?.(result);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const fieldErrors = Object.fromEntries(Object.entries(result.errors ?? {}).map(([k, v]) => [k, Array.isArray(v) ? v[0] : v]));
|
|
43
|
+
setErrors(fieldErrors);
|
|
44
|
+
if (!Object.keys(fieldErrors).length) setError(result.message);
|
|
45
|
+
};
|
|
46
|
+
if (!token) {
|
|
47
|
+
return /* @__PURE__ */ jsx(Layout, { title: "This link is incomplete", subtitle: "Open the link from the email again, or ask for a new one.", footer });
|
|
48
|
+
}
|
|
49
|
+
return /* @__PURE__ */ jsxs(Layout, { title, subtitle, footer, children: [
|
|
50
|
+
/* @__PURE__ */ jsx(AuthError, { children: error }),
|
|
51
|
+
/* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-5", children: [
|
|
52
|
+
/* @__PURE__ */ jsx(AuthField, { id: `${idPrefix}-email`, label: "Email", type: "email", autoComplete: "email", value: email, onChange: (e) => setEmail(e.target.value), error: errors.email, required: true }),
|
|
53
|
+
/* @__PURE__ */ jsx(AuthField, { id: `${idPrefix}-password`, label: "New password", type: "password", autoComplete: "new-password", value: password, onChange: (e) => setPassword(e.target.value), error: errors.password, required: true, autoFocus: true }),
|
|
54
|
+
/* @__PURE__ */ jsx(AuthField, { id: `${idPrefix}-password-confirmation`, label: "Confirm password", type: "password", autoComplete: "new-password", value: confirmation, onChange: (e) => setConfirmation(e.target.value), error: errors.password_confirmation, required: true }),
|
|
55
|
+
/* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsx(AuthSubmit, { loading, children: loading ? "Saving\u2026" : submitLabel }) })
|
|
56
|
+
] })
|
|
57
|
+
] });
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
ResetPasswordPage as default
|
|
61
|
+
};
|
package/dist/SignInPage.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from "react";
|
|
3
3
|
import { useForm } from "react-hook-form";
|
|
4
4
|
import { useAuth } from "./AuthContext.js";
|
|
5
5
|
import AuthLayout, { AuthError, AuthField, AuthSubmit } from "./AuthLayout.js";
|
|
6
6
|
import TwoFactorForm from "./TwoFactorForm.js";
|
|
7
7
|
import { loginWithPasskey, passkeysSupported } from "./passkeys.js";
|
|
8
|
+
const LABELS = {
|
|
9
|
+
submit: "Sign in",
|
|
10
|
+
submitting: "Signing in\u2026",
|
|
11
|
+
sendCode: "Email me a code",
|
|
12
|
+
verifyCode: "Verify & sign in",
|
|
13
|
+
emailPlaceholder: "you@example.com",
|
|
14
|
+
passwordPlaceholder: "Type your password",
|
|
15
|
+
remember: "Remember me",
|
|
16
|
+
useCode: "Email me a sign-in code instead",
|
|
17
|
+
usePassword: "Use password instead"
|
|
18
|
+
};
|
|
8
19
|
function SignInPage({
|
|
9
20
|
layout: Layout = AuthLayout,
|
|
10
21
|
onSignedIn,
|
|
@@ -12,41 +23,78 @@ function SignInPage({
|
|
|
12
23
|
subtitle,
|
|
13
24
|
footer,
|
|
14
25
|
forgotHint,
|
|
26
|
+
remember: offerRemember = false,
|
|
27
|
+
emailCode = false,
|
|
28
|
+
status,
|
|
29
|
+
passkey,
|
|
30
|
+
labels: labelsIn,
|
|
31
|
+
emailAutoComplete = "email",
|
|
15
32
|
google,
|
|
16
33
|
idPrefix = "sign-in"
|
|
17
34
|
}) {
|
|
18
|
-
const
|
|
35
|
+
const labels = { ...LABELS, ...labelsIn };
|
|
36
|
+
const { login, verify2fa, resendVerification, signedIn, requestLoginCode, verifyLoginCode } = useAuth();
|
|
19
37
|
const [error, setError] = useState(null);
|
|
38
|
+
const [notice, setNotice] = useState(status ?? null);
|
|
20
39
|
const [loading, setLoading] = useState(false);
|
|
21
|
-
const [
|
|
22
|
-
const [emailFor2fa, setEmailFor2fa] = useState("");
|
|
40
|
+
const [challenge, setChallenge] = useState(null);
|
|
23
41
|
const [twoFactorCode, setTwoFactorCode] = useState("");
|
|
42
|
+
const [useRecovery, setUseRecovery] = useState(false);
|
|
24
43
|
const [needsVerification, setNeedsVerification] = useState(null);
|
|
25
44
|
const [resendState, setResendState] = useState(null);
|
|
26
|
-
const
|
|
45
|
+
const [method, setMethod] = useState("password");
|
|
46
|
+
const [codeFor, setCodeFor] = useState(null);
|
|
47
|
+
const [rememberMe, setRememberMe] = useState(false);
|
|
48
|
+
const [emailedCode, setEmailedCode] = useState("");
|
|
49
|
+
const { register, handleSubmit, resetField, formState: { errors } } = useForm();
|
|
27
50
|
const done = (result) => {
|
|
28
51
|
const problem = onSignedIn?.(result);
|
|
29
52
|
if (typeof problem === "string") setError(problem);
|
|
30
53
|
};
|
|
31
|
-
const
|
|
32
|
-
setLoading(true);
|
|
33
|
-
setError(null);
|
|
34
|
-
const result = await login(data.email, data.password);
|
|
54
|
+
const settle = (result) => {
|
|
35
55
|
if (result.requires_verification) {
|
|
36
56
|
setNeedsVerification(result.email);
|
|
37
57
|
setError(null);
|
|
38
58
|
} else if (result.success) {
|
|
39
59
|
if (result.requires_2fa) {
|
|
40
|
-
|
|
41
|
-
setEmailFor2fa(result.email);
|
|
60
|
+
setChallenge(result.challenge ?? "");
|
|
42
61
|
} else {
|
|
43
62
|
done(result);
|
|
44
63
|
}
|
|
45
64
|
} else {
|
|
46
|
-
setError(result.message);
|
|
65
|
+
setError(result.errors?.code?.[0] || result.message);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const onSubmit = async (data) => {
|
|
69
|
+
setLoading(true);
|
|
70
|
+
setError(null);
|
|
71
|
+
if (method === "code") {
|
|
72
|
+
if (!codeFor) {
|
|
73
|
+
const result = await requestLoginCode(data.email);
|
|
74
|
+
if (result.success) {
|
|
75
|
+
setCodeFor(data.email);
|
|
76
|
+
setNotice(result.message || "If that address exists, a sign-in code is on its way.");
|
|
77
|
+
} else {
|
|
78
|
+
setError(result.message);
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
setNotice(null);
|
|
82
|
+
settle(await verifyLoginCode(codeFor, emailedCode));
|
|
83
|
+
}
|
|
84
|
+
setLoading(false);
|
|
85
|
+
return;
|
|
47
86
|
}
|
|
87
|
+
settle(await login(data.email, data.password, offerRemember && rememberMe ? { remember: true } : {}));
|
|
48
88
|
setLoading(false);
|
|
49
89
|
};
|
|
90
|
+
const switchMethod = () => {
|
|
91
|
+
setMethod((m) => m === "password" ? "code" : "password");
|
|
92
|
+
setCodeFor(null);
|
|
93
|
+
setError(null);
|
|
94
|
+
setNotice(null);
|
|
95
|
+
resetField("password");
|
|
96
|
+
setEmailedCode("");
|
|
97
|
+
};
|
|
50
98
|
const handleResend = async () => {
|
|
51
99
|
setResendState("sending");
|
|
52
100
|
const result = await resendVerification(needsVerification);
|
|
@@ -62,8 +110,7 @@ function SignInPage({
|
|
|
62
110
|
return;
|
|
63
111
|
}
|
|
64
112
|
if (result.requires_2fa) {
|
|
65
|
-
|
|
66
|
-
setEmailFor2fa(result.email);
|
|
113
|
+
setChallenge(result.challenge ?? "");
|
|
67
114
|
return;
|
|
68
115
|
}
|
|
69
116
|
done(signedIn(result));
|
|
@@ -77,7 +124,7 @@ function SignInPage({
|
|
|
77
124
|
e.preventDefault();
|
|
78
125
|
setLoading(true);
|
|
79
126
|
setError(null);
|
|
80
|
-
const result = await verify2fa(
|
|
127
|
+
const result = await verify2fa(challenge, twoFactorCode);
|
|
81
128
|
if (result.success) {
|
|
82
129
|
done(result);
|
|
83
130
|
} else {
|
|
@@ -117,24 +164,46 @@ function SignInPage({
|
|
|
117
164
|
}
|
|
118
165
|
);
|
|
119
166
|
}
|
|
120
|
-
if (
|
|
167
|
+
if (challenge !== null) {
|
|
121
168
|
return /* @__PURE__ */ jsxs(
|
|
122
169
|
Layout,
|
|
123
170
|
{
|
|
124
171
|
title: "Two-step verification",
|
|
125
|
-
subtitle: "Enter the 6-digit code from your authenticator app to finish signing in.",
|
|
172
|
+
subtitle: useRecovery ? "Enter one of the recovery codes you saved when you turned two-step sign-in on." : "Enter the 6-digit code from your authenticator app to finish signing in.",
|
|
126
173
|
footer: /* @__PURE__ */ jsx("button", { type: "button", onClick: () => {
|
|
127
|
-
|
|
174
|
+
setChallenge(null);
|
|
175
|
+
setTwoFactorCode("");
|
|
176
|
+
setUseRecovery(false);
|
|
128
177
|
setError(null);
|
|
129
178
|
}, className: "hover:text-body", children: "\u2190 Use a different account" }),
|
|
130
179
|
children: [
|
|
131
180
|
/* @__PURE__ */ jsx(AuthError, { children: error }),
|
|
132
|
-
/* @__PURE__ */ jsx(TwoFactorForm, { id: `${idPrefix}-2fa`, code: twoFactorCode, onCode: setTwoFactorCode, loading, onSubmit: handle2faVerify })
|
|
181
|
+
/* @__PURE__ */ jsx(TwoFactorForm, { id: `${idPrefix}-2fa`, code: twoFactorCode, onCode: setTwoFactorCode, loading, onSubmit: handle2faVerify, recovery: useRecovery }),
|
|
182
|
+
/* @__PURE__ */ jsx("div", { className: "mt-4 text-center", children: /* @__PURE__ */ jsx("button", { type: "button", onClick: () => {
|
|
183
|
+
setUseRecovery((r) => !r);
|
|
184
|
+
setTwoFactorCode("");
|
|
185
|
+
setError(null);
|
|
186
|
+
}, className: "text-sm text-muted hover:text-body", children: useRecovery ? "Use your authenticator app instead" : "Use a recovery code instead" }) })
|
|
133
187
|
]
|
|
134
188
|
}
|
|
135
189
|
);
|
|
136
190
|
}
|
|
191
|
+
const byCode = method === "code";
|
|
192
|
+
const passkeyButton = passkey !== void 0 ? passkey : passkeysSupported() && /* @__PURE__ */ jsxs(
|
|
193
|
+
"button",
|
|
194
|
+
{
|
|
195
|
+
type: "button",
|
|
196
|
+
onClick: handlePasskey,
|
|
197
|
+
disabled: loading,
|
|
198
|
+
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",
|
|
199
|
+
children: [
|
|
200
|
+
/* @__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" }) }),
|
|
201
|
+
"Sign in with a passkey"
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
);
|
|
137
205
|
return /* @__PURE__ */ jsxs(Layout, { title, subtitle, footer, children: [
|
|
206
|
+
notice && /* @__PURE__ */ jsx("div", { role: "status", className: "mb-5 rounded-2xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-center text-sm text-emerald-700", children: notice }),
|
|
138
207
|
/* @__PURE__ */ jsx(AuthError, { children: error }),
|
|
139
208
|
/* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit(onSubmit), className: "space-y-5", noValidate: true, children: [
|
|
140
209
|
/* @__PURE__ */ jsx(
|
|
@@ -143,8 +212,9 @@ function SignInPage({
|
|
|
143
212
|
id: `${idPrefix}-email`,
|
|
144
213
|
label: "Email",
|
|
145
214
|
type: "email",
|
|
146
|
-
autoComplete:
|
|
147
|
-
placeholder:
|
|
215
|
+
autoComplete: emailAutoComplete,
|
|
216
|
+
placeholder: labels.emailPlaceholder,
|
|
217
|
+
readOnly: byCode && !!codeFor,
|
|
148
218
|
error: errors.email?.message,
|
|
149
219
|
...register("email", {
|
|
150
220
|
required: "Email is required",
|
|
@@ -155,14 +225,14 @@ function SignInPage({
|
|
|
155
225
|
})
|
|
156
226
|
}
|
|
157
227
|
),
|
|
158
|
-
/* @__PURE__ */ jsx(
|
|
228
|
+
!byCode && /* @__PURE__ */ jsx(
|
|
159
229
|
AuthField,
|
|
160
230
|
{
|
|
161
231
|
id: `${idPrefix}-password`,
|
|
162
232
|
label: "Password",
|
|
163
233
|
type: "password",
|
|
164
234
|
autoComplete: "current-password",
|
|
165
|
-
placeholder:
|
|
235
|
+
placeholder: labels.passwordPlaceholder,
|
|
166
236
|
error: errors.password?.message,
|
|
167
237
|
...register("password", {
|
|
168
238
|
required: "Password is required",
|
|
@@ -170,27 +240,40 @@ function SignInPage({
|
|
|
170
240
|
})
|
|
171
241
|
}
|
|
172
242
|
),
|
|
173
|
-
|
|
174
|
-
|
|
243
|
+
byCode && codeFor && /* @__PURE__ */ jsx(
|
|
244
|
+
AuthField,
|
|
245
|
+
{
|
|
246
|
+
id: `${idPrefix}-code`,
|
|
247
|
+
label: "Sign-in code",
|
|
248
|
+
inputMode: "numeric",
|
|
249
|
+
autoComplete: "one-time-code",
|
|
250
|
+
placeholder: "6-digit code",
|
|
251
|
+
maxLength: 6,
|
|
252
|
+
autoFocus: true,
|
|
253
|
+
required: true,
|
|
254
|
+
value: emailedCode,
|
|
255
|
+
onChange: (e) => setEmailedCode(e.target.value.replace(/\D/g, ""))
|
|
256
|
+
}
|
|
257
|
+
),
|
|
258
|
+
!byCode && offerRemember && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 -mt-1", children: [
|
|
259
|
+
/* @__PURE__ */ jsxs("label", { className: "flex cursor-pointer items-center gap-2 text-sm text-muted", children: [
|
|
260
|
+
/* @__PURE__ */ jsx("input", { type: "checkbox", checked: rememberMe, onChange: (e) => setRememberMe(e.target.checked), className: "h-4 w-4 rounded border-line accent-[var(--okjt-auth-focus,var(--color-accent))]" }),
|
|
261
|
+
labels.remember
|
|
262
|
+
] }),
|
|
263
|
+
forgotHint && /* @__PURE__ */ jsx("div", { className: "text-sm text-muted", children: forgotHint })
|
|
264
|
+
] }),
|
|
265
|
+
!byCode && !offerRemember && forgotHint && /* @__PURE__ */ jsx("div", { className: "text-xs text-faint text-right -mt-1", children: forgotHint }),
|
|
266
|
+
/* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsx(AuthSubmit, { loading, children: loading ? labels.submitting : !byCode ? labels.submit : codeFor ? labels.verifyCode : labels.sendCode }) })
|
|
175
267
|
] }),
|
|
176
|
-
/* @__PURE__ */ jsxs(
|
|
177
|
-
/* @__PURE__ */
|
|
178
|
-
|
|
268
|
+
(passkeyButton || google) && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
269
|
+
/* @__PURE__ */ jsxs("div", { className: "relative my-5", "aria-hidden": "true", children: [
|
|
270
|
+
/* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center", children: /* @__PURE__ */ jsx("div", { className: "w-full border-t border-tone-200" }) }),
|
|
271
|
+
/* @__PURE__ */ jsx("div", { className: "relative flex justify-center text-xs", children: /* @__PURE__ */ jsx("span", { className: "bg-[var(--okjt-auth-card,#fff)] px-3 text-faint", children: "or" }) })
|
|
272
|
+
] }),
|
|
273
|
+
passkeyButton,
|
|
274
|
+
google
|
|
179
275
|
] }),
|
|
180
|
-
|
|
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
|
|
276
|
+
emailCode && /* @__PURE__ */ jsx("div", { className: "mt-4 text-center", children: /* @__PURE__ */ jsx("button", { type: "button", onClick: switchMethod, className: "text-sm text-muted hover:text-body", children: byCode ? labels.usePassword : labels.useCode }) })
|
|
194
277
|
] });
|
|
195
278
|
}
|
|
196
279
|
export {
|
package/dist/TwoFactorForm.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { AuthField, AuthSubmit } from "./AuthLayout.js";
|
|
3
|
-
function TwoFactorForm({ id, code, onCode, loading, onSubmit }) {
|
|
3
|
+
function TwoFactorForm({ id, code, onCode, loading, onSubmit, recovery = false }) {
|
|
4
4
|
return /* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-6", children: [
|
|
5
|
-
/* @__PURE__ */ jsx(
|
|
5
|
+
recovery ? /* @__PURE__ */ jsx(
|
|
6
|
+
AuthField,
|
|
7
|
+
{
|
|
8
|
+
id,
|
|
9
|
+
label: "Recovery code",
|
|
10
|
+
value: code,
|
|
11
|
+
onChange: (e) => onCode(e.target.value.trim()),
|
|
12
|
+
autoComplete: "off",
|
|
13
|
+
placeholder: "xxxxxxxxxx-xxxxxxxxxx",
|
|
14
|
+
required: true,
|
|
15
|
+
autoFocus: true,
|
|
16
|
+
inputClassName: "text-center font-mono"
|
|
17
|
+
},
|
|
18
|
+
"recovery"
|
|
19
|
+
) : /* @__PURE__ */ jsx(
|
|
6
20
|
AuthField,
|
|
7
21
|
{
|
|
8
22
|
id,
|
|
@@ -16,7 +30,8 @@ function TwoFactorForm({ id, code, onCode, loading, onSubmit }) {
|
|
|
16
30
|
required: true,
|
|
17
31
|
autoFocus: true,
|
|
18
32
|
inputClassName: "text-center text-xl tracking-[0.6em] font-semibold"
|
|
19
|
-
}
|
|
33
|
+
},
|
|
34
|
+
"code"
|
|
20
35
|
),
|
|
21
36
|
/* @__PURE__ */ jsx(AuthSubmit, { loading, children: loading ? "Verifying\u2026" : "Verify & sign in" })
|
|
22
37
|
] });
|