@okjt/dashboard 0.3.0 → 0.5.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 +11 -4
- package/dist/AdminInput.js +25 -53
- 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/AdminTutorial.js +47 -10
- package/dist/AuthContext.js +95 -56
- package/dist/AuthLayout.js +2 -2
- package/dist/BoldToolbar.js +272 -0
- package/dist/CollaborationContext.js +1 -1
- 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/GoogleButton.js +1 -1
- package/dist/GoogleCallbackPage.js +3 -3
- package/dist/NotificationsBell.js +11 -23
- package/dist/ResetPasswordPage.js +61 -0
- package/dist/SignInPage.js +125 -42
- package/dist/TwoFactorForm.js +18 -3
- package/dist/UnsavedChangesStatus.js +3 -1
- package/dist/index.js +77 -51
- package/dist/useUnsavedChangesGuard.js +65 -3
- package/package.json +2 -2
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import { Link } from "react-router-dom";
|
|
5
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
6
|
+
import { Bookmark, ChevronDown, ChevronUp, MoreHorizontal, Search, SlidersHorizontal, X } from "lucide-react";
|
|
7
|
+
import { promptAction, useDismiss } from "@okjt/ui";
|
|
8
|
+
import DashboardIcon from "./DashboardIcon.js";
|
|
9
|
+
import useSavedViews from "./useSavedViews.js";
|
|
10
|
+
function countActiveFilterLists(filters = []) {
|
|
11
|
+
return filters.filter((f) => f.value !== (f.defaultValue ?? f.options?.[0]?.value)).length;
|
|
12
|
+
}
|
|
13
|
+
const actionClass = {
|
|
14
|
+
primary: "bg-gradient-to-r from-action to-accent text-white hover:shadow-lg hover:shadow-action/25",
|
|
15
|
+
secondary: "border border-contrast/10 bg-contrast/5 text-body hover:bg-contrast/10 hover:text-ink",
|
|
16
|
+
danger: "border border-red-500/30 bg-red-500/10 text-red-300 hover:bg-red-500/20 hover:text-red-200"
|
|
17
|
+
};
|
|
18
|
+
const Named = ({ name, fallback, className }) => /* @__PURE__ */ jsx(DashboardIcon, { icon: name, fallback, className });
|
|
19
|
+
function ActionLink({ action, ...props }) {
|
|
20
|
+
return action.download ? /* @__PURE__ */ jsx("a", { href: action.href, download: true, ...props }) : /* @__PURE__ */ jsx(Link, { to: action.href, ...props });
|
|
21
|
+
}
|
|
22
|
+
function Action({ action, compact }) {
|
|
23
|
+
const className = `inline-flex items-center gap-2 rounded-xl px-3 py-2 text-sm font-semibold transition disabled:opacity-50 disabled:cursor-not-allowed ${actionClass[action.variant || "secondary"]}`;
|
|
24
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
25
|
+
/* @__PURE__ */ jsx(DashboardIcon, { icon: action.icon }),
|
|
26
|
+
/* @__PURE__ */ jsx("span", { className: compact ? "sr-only" : "hidden sm:inline", children: action.label })
|
|
27
|
+
] });
|
|
28
|
+
return action.href ? /* @__PURE__ */ jsx(ActionLink, { action, className, title: action.label, "aria-label": action.label, children: content }) : /* @__PURE__ */ jsx("button", { type: "button", onClick: action.onClick, disabled: action.disabled, className, title: action.label, "aria-label": action.label, children: content });
|
|
29
|
+
}
|
|
30
|
+
const snapshot = (filters, search) => ({
|
|
31
|
+
filters: Object.fromEntries(filters.map((f) => [f.name, f.value])),
|
|
32
|
+
search: search?.value ?? ""
|
|
33
|
+
});
|
|
34
|
+
function SavedViews({ filters, search, storageKey, onApplied }) {
|
|
35
|
+
const { views, saveView, deleteView } = useSavedViews(storageKey);
|
|
36
|
+
const apply = (view) => {
|
|
37
|
+
filters.forEach((f) => {
|
|
38
|
+
const value = view.state.filters?.[f.name];
|
|
39
|
+
if (value !== void 0 && f.options.some((o) => String(o.value) === String(value))) f.onChange(value);
|
|
40
|
+
});
|
|
41
|
+
if (search && typeof view.state.search === "string") search.onChange(view.state.search);
|
|
42
|
+
onApplied();
|
|
43
|
+
};
|
|
44
|
+
const save = async () => {
|
|
45
|
+
const name = await promptAction({ title: "Save this view", label: "Name", placeholder: "e.g. Pending receipts", confirmLabel: "Save view" });
|
|
46
|
+
if (name) saveView(name, snapshot(filters, search));
|
|
47
|
+
};
|
|
48
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-1.5 border-t border-contrast/10 pt-3", children: [
|
|
49
|
+
/* @__PURE__ */ jsx("span", { className: "block text-xs font-semibold capitalize text-soft", children: "Saved views" }),
|
|
50
|
+
views.length > 0 && /* @__PURE__ */ jsx("ul", { className: "space-y-1", children: views.map((view) => /* @__PURE__ */ jsxs("li", { className: "flex items-center gap-1", children: [
|
|
51
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => apply(view), className: "min-w-0 flex-1 truncate rounded-lg px-2 py-1 text-left text-sm text-body hover:bg-contrast/5 hover:text-ink", children: view.name }),
|
|
52
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => deleteView(view.id), "aria-label": `Delete view ${view.name}`, className: "rounded-lg p-1 text-faint hover:bg-contrast/5 hover:text-accent-dark", children: /* @__PURE__ */ jsx(Named, { name: "close", fallback: X, className: "text-xs" }) })
|
|
53
|
+
] }, view.id)) }),
|
|
54
|
+
/* @__PURE__ */ jsxs("button", { type: "button", onClick: save, className: "text-xs font-semibold text-body transition hover:text-ink", children: [
|
|
55
|
+
/* @__PURE__ */ jsx(Named, { name: "bookmark", fallback: Bookmark, className: "mr-1.5" }),
|
|
56
|
+
"Save current view\u2026"
|
|
57
|
+
] })
|
|
58
|
+
] });
|
|
59
|
+
}
|
|
60
|
+
const popover = { initial: { opacity: 0, y: 8, scale: 0.97 }, animate: { opacity: 1, y: 0, scale: 1 }, exit: { opacity: 0, y: 8, scale: 0.97 }, transition: { duration: 0.15 } };
|
|
61
|
+
function FiltersMenu({ filters, search, storageKey }) {
|
|
62
|
+
const [open, setOpen] = useState(false);
|
|
63
|
+
const ref = useRef(null);
|
|
64
|
+
useDismiss(ref, open, () => setOpen(false));
|
|
65
|
+
const active = countActiveFilterLists(filters);
|
|
66
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative", ref, children: [
|
|
67
|
+
/* @__PURE__ */ jsxs(
|
|
68
|
+
"button",
|
|
69
|
+
{
|
|
70
|
+
type: "button",
|
|
71
|
+
onClick: () => setOpen((v) => !v),
|
|
72
|
+
"aria-expanded": open,
|
|
73
|
+
className: `inline-flex items-center gap-2 rounded-xl px-3 py-2 text-sm font-semibold transition border ${active ? "border-accent/40 bg-action/15 text-ink" : "border-contrast/10 bg-contrast/5 text-body hover:bg-contrast/10"}`,
|
|
74
|
+
children: [
|
|
75
|
+
/* @__PURE__ */ jsx(Named, { name: "filters", fallback: SlidersHorizontal }),
|
|
76
|
+
/* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: "Filters" }),
|
|
77
|
+
active > 0 && /* @__PURE__ */ jsx("span", { className: "min-w-[1.25rem] h-5 px-1 rounded-full bg-accent text-[11px] leading-5 text-white text-center", children: active })
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
),
|
|
81
|
+
/* @__PURE__ */ jsx(AnimatePresence, { children: open && /* @__PURE__ */ jsxs(motion.div, { ...popover, className: "absolute bottom-full left-1/2 -translate-x-1/2 mb-3 w-72 max-w-[calc(100vw-2rem)] rounded-2xl border border-tone-100 bg-surface p-4 shadow-2xl space-y-3", children: [
|
|
82
|
+
filters.map((filter) => /* @__PURE__ */ jsxs("label", { className: "block", children: [
|
|
83
|
+
/* @__PURE__ */ jsx("span", { className: "mb-1 block text-xs font-semibold capitalize text-soft", children: filter.title || filter.label }),
|
|
84
|
+
/* @__PURE__ */ jsx("select", { value: filter.value, onChange: (e) => filter.onChange(e.target.value), className: "w-full py-2", children: filter.options.map((o) => /* @__PURE__ */ jsx("option", { value: o.value, children: o.label }, o.value)) })
|
|
85
|
+
] }, filter.name)),
|
|
86
|
+
active > 0 && /* @__PURE__ */ jsx(
|
|
87
|
+
"button",
|
|
88
|
+
{
|
|
89
|
+
type: "button",
|
|
90
|
+
onClick: () => filters.forEach((f) => f.onChange(f.defaultValue ?? f.options?.[0]?.value)),
|
|
91
|
+
className: "text-xs font-semibold text-accent-dark hover:text-ink transition",
|
|
92
|
+
children: "Reset filters"
|
|
93
|
+
}
|
|
94
|
+
),
|
|
95
|
+
/* @__PURE__ */ jsx(SavedViews, { filters, search, storageKey, onApplied: () => setOpen(false) })
|
|
96
|
+
] }) })
|
|
97
|
+
] });
|
|
98
|
+
}
|
|
99
|
+
function MoreMenu({ actions }) {
|
|
100
|
+
const [open, setOpen] = useState(false);
|
|
101
|
+
const ref = useRef(null);
|
|
102
|
+
useDismiss(ref, open, () => setOpen(false));
|
|
103
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative", ref, children: [
|
|
104
|
+
/* @__PURE__ */ jsxs(
|
|
105
|
+
"button",
|
|
106
|
+
{
|
|
107
|
+
type: "button",
|
|
108
|
+
onClick: () => setOpen((v) => !v),
|
|
109
|
+
"aria-expanded": open,
|
|
110
|
+
"aria-label": "More actions",
|
|
111
|
+
className: "inline-flex items-center gap-2 rounded-xl px-3 py-2 text-sm font-semibold border border-contrast/10 bg-contrast/5 text-body hover:bg-contrast/10 transition",
|
|
112
|
+
children: [
|
|
113
|
+
/* @__PURE__ */ jsx(Named, { name: "more", fallback: MoreHorizontal }),
|
|
114
|
+
/* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: "More" })
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
),
|
|
118
|
+
/* @__PURE__ */ jsx(AnimatePresence, { children: open && /* @__PURE__ */ jsx(motion.div, { ...popover, className: "absolute bottom-full right-0 mb-3 min-w-[12rem] rounded-xl border border-tone-100 bg-surface py-2 shadow-2xl", children: actions.map((action) => {
|
|
119
|
+
const className = `flex w-full items-center gap-3 px-4 py-2.5 text-left text-sm transition hover:bg-contrast/[0.06] ${action.variant === "danger" ? "text-red-300" : "text-body"}`;
|
|
120
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
121
|
+
/* @__PURE__ */ jsx(DashboardIcon, { icon: action.icon, className: "w-4 text-center" }),
|
|
122
|
+
action.label
|
|
123
|
+
] });
|
|
124
|
+
return action.href ? /* @__PURE__ */ jsx(ActionLink, { action, className, onClick: () => setOpen(false), children: content }, action.id) : /* @__PURE__ */ jsx("button", { type: "button", disabled: action.disabled, className, onClick: () => {
|
|
125
|
+
setOpen(false);
|
|
126
|
+
action.onClick?.();
|
|
127
|
+
}, children: content }, action.id);
|
|
128
|
+
}) }) })
|
|
129
|
+
] });
|
|
130
|
+
}
|
|
131
|
+
const Divider = () => /* @__PURE__ */ jsx("div", { "aria-hidden": "true", className: "hidden sm:block w-px h-6 bg-contrast/10 mx-0.5" });
|
|
132
|
+
function BoldToolbar({ search, filters = [], view, actions = [], selection, children, savedViewsKey }) {
|
|
133
|
+
const [visible, setVisible] = useState(true);
|
|
134
|
+
const searchRef = useRef(null);
|
|
135
|
+
const selecting = selection && selection.count > 0;
|
|
136
|
+
const storageKey = savedViewsKey || `okjt.views.${typeof window === "undefined" ? "" : window.location.pathname}`;
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
if (!search) return void 0;
|
|
139
|
+
const onKey = (e) => {
|
|
140
|
+
if (e.key !== "/" || e.metaKey || e.ctrlKey || e.altKey) return;
|
|
141
|
+
const tag = e.target?.tagName;
|
|
142
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || e.target?.isContentEditable) return;
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
setVisible(true);
|
|
145
|
+
requestAnimationFrame(() => searchRef.current?.focus());
|
|
146
|
+
};
|
|
147
|
+
document.addEventListener("keydown", onKey);
|
|
148
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
149
|
+
}, [search]);
|
|
150
|
+
const hasLeading = !!search || filters.length > 0 || !!view;
|
|
151
|
+
const max = hasLeading ? 2 : 4;
|
|
152
|
+
const primary = actions.slice(0, max);
|
|
153
|
+
const overflow = actions.slice(max);
|
|
154
|
+
const narrowed = !!search?.value || countActiveFilterLists(filters) > 0;
|
|
155
|
+
const position = "fixed z-[25] bottom-[max(0.75rem,env(safe-area-inset-bottom))] sm:bottom-6 left-1/2 lg:left-[calc(50%_+_var(--okjt-sidebar-w,16rem)_/_2)] transition-[left] duration-300";
|
|
156
|
+
const centre = { x: "-50%" };
|
|
157
|
+
if (typeof document === "undefined") return null;
|
|
158
|
+
if (!hasLeading && !actions.length && !selection && !children) return null;
|
|
159
|
+
return createPortal(
|
|
160
|
+
/* @__PURE__ */ jsx(AnimatePresence, { initial: false, children: visible ? /* @__PURE__ */ jsx(
|
|
161
|
+
motion.div,
|
|
162
|
+
{
|
|
163
|
+
role: "toolbar",
|
|
164
|
+
"aria-label": "Page tools",
|
|
165
|
+
initial: { ...centre, opacity: 0, y: 24 },
|
|
166
|
+
animate: { ...centre, opacity: 1, y: 0 },
|
|
167
|
+
exit: { ...centre, opacity: 0, y: 16 },
|
|
168
|
+
transition: { type: "spring", stiffness: 320, damping: 28 },
|
|
169
|
+
className: `${position} w-max max-w-[calc(100vw-1rem)] lg:max-w-[calc(100vw_-_var(--okjt-sidebar-w,16rem)_-_2rem)]`,
|
|
170
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-center gap-1.5 sm:gap-2 rounded-2xl border border-tone-100 bg-paper-warm/90 p-1.5 sm:p-2 shadow-[0_16px_48px_rgba(0,0,0,0.55)] backdrop-blur-xl", children: [
|
|
171
|
+
selecting ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
172
|
+
/* @__PURE__ */ jsxs("span", { className: "px-2 text-sm font-semibold text-ink whitespace-nowrap", children: [
|
|
173
|
+
selection.count,
|
|
174
|
+
" selected"
|
|
175
|
+
] }),
|
|
176
|
+
selection.onSelectAll && /* @__PURE__ */ jsx(
|
|
177
|
+
"button",
|
|
178
|
+
{
|
|
179
|
+
type: "button",
|
|
180
|
+
onClick: selection.count === selection.total ? selection.onDeselectAll : selection.onSelectAll,
|
|
181
|
+
className: "rounded-xl px-3 py-2 text-sm font-semibold text-body hover:bg-contrast/[0.06] hover:text-ink transition",
|
|
182
|
+
children: selection.count === selection.total ? "Deselect all" : `Select all ${selection.total}`
|
|
183
|
+
}
|
|
184
|
+
),
|
|
185
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
|
186
|
+
(selection.actions || []).map((action) => /* @__PURE__ */ jsx(Action, { action }, action.id)),
|
|
187
|
+
/* @__PURE__ */ jsx(
|
|
188
|
+
"button",
|
|
189
|
+
{
|
|
190
|
+
type: "button",
|
|
191
|
+
onClick: selection.onDeselectAll,
|
|
192
|
+
"aria-label": "Clear selection",
|
|
193
|
+
title: "Clear selection",
|
|
194
|
+
className: "rounded-xl p-2 text-soft hover:bg-contrast/[0.06] hover:text-ink transition",
|
|
195
|
+
children: /* @__PURE__ */ jsx(Named, { name: "close", fallback: X })
|
|
196
|
+
}
|
|
197
|
+
)
|
|
198
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
199
|
+
search && /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
200
|
+
/* @__PURE__ */ jsx(Named, { name: "search", fallback: Search, className: "pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-xs text-soft" }),
|
|
201
|
+
/* @__PURE__ */ jsx(
|
|
202
|
+
"input",
|
|
203
|
+
{
|
|
204
|
+
ref: searchRef,
|
|
205
|
+
type: "search",
|
|
206
|
+
value: search.value,
|
|
207
|
+
onChange: (e) => search.onChange(e.target.value),
|
|
208
|
+
placeholder: search.placeholder || "Search\u2026",
|
|
209
|
+
"aria-label": search.placeholder || "Search this page",
|
|
210
|
+
className: "w-40 sm:w-56 sm:focus:w-72 rounded-xl border border-contrast/10 bg-contrast/5 py-2 pl-9 pr-9 text-sm transition-all"
|
|
211
|
+
}
|
|
212
|
+
),
|
|
213
|
+
/* @__PURE__ */ jsx("kbd", { className: "pointer-events-none absolute right-2.5 top-1/2 -translate-y-1/2 hidden sm:block rounded border border-contrast/15 px-1.5 text-[10px] text-soft", children: "/" })
|
|
214
|
+
] }),
|
|
215
|
+
filters.length > 0 && /* @__PURE__ */ jsx(FiltersMenu, { filters, search, storageKey }),
|
|
216
|
+
view && view.modes?.length > 1 && /* @__PURE__ */ jsx("div", { className: "flex gap-1 rounded-xl border border-contrast/10 bg-ink-deep/30 p-1", children: view.modes.map((mode) => /* @__PURE__ */ jsx(
|
|
217
|
+
"button",
|
|
218
|
+
{
|
|
219
|
+
type: "button",
|
|
220
|
+
onClick: () => view.onChange(mode.value),
|
|
221
|
+
"aria-label": mode.label || `${mode.value} view`,
|
|
222
|
+
"aria-pressed": view.current === mode.value,
|
|
223
|
+
title: mode.label || `${mode.value} view`,
|
|
224
|
+
className: `rounded-lg px-2.5 py-1 text-sm transition-colors ${view.current === mode.value ? "bg-action text-white" : "text-soft hover:text-ink"}`,
|
|
225
|
+
children: /* @__PURE__ */ jsx(DashboardIcon, { icon: mode.icon })
|
|
226
|
+
},
|
|
227
|
+
mode.value
|
|
228
|
+
)) }),
|
|
229
|
+
hasLeading && (children || actions.length > 0) && /* @__PURE__ */ jsx(Divider, {}),
|
|
230
|
+
children,
|
|
231
|
+
primary.map((action) => /* @__PURE__ */ jsx(Action, { action }, action.id)),
|
|
232
|
+
overflow.length > 0 && /* @__PURE__ */ jsx(MoreMenu, { actions: overflow })
|
|
233
|
+
] }),
|
|
234
|
+
/* @__PURE__ */ jsx(
|
|
235
|
+
"button",
|
|
236
|
+
{
|
|
237
|
+
type: "button",
|
|
238
|
+
onClick: () => setVisible(false),
|
|
239
|
+
"aria-label": "Hide toolbar",
|
|
240
|
+
title: "Hide toolbar",
|
|
241
|
+
className: "rounded-xl p-2 text-faint hover:bg-contrast/[0.06] hover:text-ink transition",
|
|
242
|
+
children: /* @__PURE__ */ jsx(Named, { name: "hide-toolbar", fallback: ChevronDown })
|
|
243
|
+
}
|
|
244
|
+
)
|
|
245
|
+
] })
|
|
246
|
+
},
|
|
247
|
+
"toolbar"
|
|
248
|
+
) : /* @__PURE__ */ jsxs(
|
|
249
|
+
motion.button,
|
|
250
|
+
{
|
|
251
|
+
type: "button",
|
|
252
|
+
initial: { ...centre, opacity: 0, y: 16 },
|
|
253
|
+
animate: { ...centre, opacity: 1, y: 0 },
|
|
254
|
+
exit: { ...centre, opacity: 0, y: 16 },
|
|
255
|
+
onClick: () => setVisible(true),
|
|
256
|
+
"aria-label": narrowed || selecting ? "Show toolbar (search, filters or selection active)" : "Show toolbar",
|
|
257
|
+
title: narrowed || selecting ? "Show toolbar (search, filters or selection active)" : "Show toolbar",
|
|
258
|
+
className: `${position} rounded-full border border-contrast/10 bg-paper-warm/90 p-3 text-body shadow-xl backdrop-blur-xl hover:text-ink`,
|
|
259
|
+
children: [
|
|
260
|
+
/* @__PURE__ */ jsx(Named, { name: "chevron-up", fallback: ChevronUp }),
|
|
261
|
+
(narrowed || selecting) && /* @__PURE__ */ jsx("span", { className: "absolute right-1 top-1 h-2.5 w-2.5 rounded-full bg-accent" })
|
|
262
|
+
]
|
|
263
|
+
},
|
|
264
|
+
"toolbar-show"
|
|
265
|
+
) }),
|
|
266
|
+
document.body
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
export {
|
|
270
|
+
countActiveFilterLists,
|
|
271
|
+
BoldToolbar as default
|
|
272
|
+
};
|
|
@@ -35,7 +35,7 @@ function CollaborationProvider({ children }) {
|
|
|
35
35
|
const latest = useRef({ module, pathname });
|
|
36
36
|
latest.current = { module, pathname };
|
|
37
37
|
const beat = useCallback(async () => {
|
|
38
|
-
if (document.visibilityState === "hidden") return;
|
|
38
|
+
if (!api || document.visibilityState === "hidden") return;
|
|
39
39
|
try {
|
|
40
40
|
const res = await api.post("/collaboration/heartbeat", { module: latest.current.module, path: latest.current.pathname });
|
|
41
41
|
setState({ presence: res.data?.presence || [], badges: res.data?.badges || {} });
|
|
@@ -0,0 +1,41 @@
|
|
|
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 ConfirmPasswordPage({
|
|
6
|
+
layout: Layout = AuthLayout,
|
|
7
|
+
onConfirmed,
|
|
8
|
+
title = "Confirm it\u2019s you",
|
|
9
|
+
subtitle = "This is a secure area. Please confirm your password to carry on.",
|
|
10
|
+
footer,
|
|
11
|
+
submitLabel = "Confirm",
|
|
12
|
+
idPrefix = "confirm"
|
|
13
|
+
}) {
|
|
14
|
+
const { confirmPassword } = useAuth();
|
|
15
|
+
const [password, setPassword] = useState("");
|
|
16
|
+
const [error, setError] = useState(null);
|
|
17
|
+
const [loading, setLoading] = useState(false);
|
|
18
|
+
const onSubmit = async (e) => {
|
|
19
|
+
e.preventDefault();
|
|
20
|
+
setLoading(true);
|
|
21
|
+
setError(null);
|
|
22
|
+
const result = await confirmPassword(password);
|
|
23
|
+
setLoading(false);
|
|
24
|
+
if (result.success) {
|
|
25
|
+
onConfirmed?.();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
setError(result.errors?.password?.[0] || result.message);
|
|
29
|
+
setPassword("");
|
|
30
|
+
};
|
|
31
|
+
return /* @__PURE__ */ jsxs(Layout, { title, subtitle, footer, children: [
|
|
32
|
+
/* @__PURE__ */ jsx(AuthError, { children: error }),
|
|
33
|
+
/* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-5", children: [
|
|
34
|
+
/* @__PURE__ */ jsx(AuthField, { id: `${idPrefix}-password`, label: "Password", type: "password", autoComplete: "current-password", value: password, onChange: (e) => setPassword(e.target.value), required: true, autoFocus: true }),
|
|
35
|
+
/* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsx(AuthSubmit, { loading, children: loading ? "Checking\u2026" : submitLabel }) })
|
|
36
|
+
] })
|
|
37
|
+
] });
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
ConfirmPasswordPage as default
|
|
41
|
+
};
|
package/dist/DashboardHeader.js
CHANGED
|
@@ -33,7 +33,7 @@ function DashboardHeader({ onMenuClick, onRestartTutorial, titleSlotRef, statusS
|
|
|
33
33
|
className: `${shell.collapsible ? "" : "lg:hidden "}relative p-2 rounded-lg shrink-0 ${shell.menuButtonClass}`,
|
|
34
34
|
children: [
|
|
35
35
|
shell.MenuIcon ? /* @__PURE__ */ jsx(shell.MenuIcon, {}) : /* @__PURE__ */ jsx(Menu, { className: "w-6 h-6 text-body" }),
|
|
36
|
-
hasNews && /* @__PURE__ */ jsx("span", { className: `absolute top-1.5 right-1.5 w-2 h-2 rounded-full bg-accent ring-2 ring-paper ${shell.collapsible ? "lg:hidden" : ""}`, "aria-hidden": "true" })
|
|
36
|
+
hasNews && shell.menuNewsDot && /* @__PURE__ */ jsx("span", { className: `absolute top-1.5 right-1.5 w-2 h-2 rounded-full bg-accent ring-2 ring-paper ${shell.collapsible ? "lg:hidden" : ""}`, "aria-hidden": "true" })
|
|
37
37
|
]
|
|
38
38
|
}
|
|
39
39
|
),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useDashboard } from "./DashboardProvider.js";
|
|
3
|
+
function DashboardIcon({ icon, fallback = null, className = "", ...rest }) {
|
|
4
|
+
const { iconFor } = useDashboard();
|
|
5
|
+
const Icon = (typeof icon === "string" ? iconFor(icon) : icon) || fallback;
|
|
6
|
+
return Icon ? /* @__PURE__ */ jsx(Icon, { className, "aria-hidden": "true", ...rest }) : null;
|
|
7
|
+
}
|
|
8
|
+
function toIcon(icon, iconFor) {
|
|
9
|
+
if (!icon) return null;
|
|
10
|
+
return typeof icon === "string" ? iconFor?.(icon) || null : icon;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
DashboardIcon as default,
|
|
14
|
+
toIcon
|
|
15
|
+
};
|
|
@@ -16,7 +16,9 @@ const DEFAULTS = {
|
|
|
16
16
|
roleLabel: (role) => DEFAULT_ROLES.find((r) => r.value === role)?.label || role,
|
|
17
17
|
anonymousName: "Someone",
|
|
18
18
|
removeCollaborator: null,
|
|
19
|
-
tutorialSteps: []
|
|
19
|
+
tutorialSteps: [],
|
|
20
|
+
iconFor: () => null,
|
|
21
|
+
componentDefaults: {}
|
|
20
22
|
};
|
|
21
23
|
const DEFAULT_SHELL = {
|
|
22
24
|
logo: { src: "", alt: "", to: "/" },
|
|
@@ -50,6 +52,7 @@ const DEFAULT_SHELL = {
|
|
|
50
52
|
headerEndClass: "gap-1 sm:gap-2 shrink-0",
|
|
51
53
|
menuButtonClass: "hover:bg-contrast/5",
|
|
52
54
|
MenuIcon: null,
|
|
55
|
+
menuNewsDot: true,
|
|
53
56
|
mainClass: "p-4 sm:p-6",
|
|
54
57
|
headerButtonClass: "text-soft hover:bg-accent/10 hover:text-accent",
|
|
55
58
|
headerActions: ["online", "share", "history", "tour"],
|
|
@@ -61,11 +64,17 @@ const DEFAULT_SHELL = {
|
|
|
61
64
|
function DashboardProvider({ dashboard, children }) {
|
|
62
65
|
return /* @__PURE__ */ jsx(DashboardContext.Provider, { value: dashboard, children });
|
|
63
66
|
}
|
|
67
|
+
function useComponentDefaults(name, props) {
|
|
68
|
+
const { componentDefaults } = useDashboard();
|
|
69
|
+
const defaults = componentDefaults?.[name];
|
|
70
|
+
return defaults ? { ...defaults, ...props } : props;
|
|
71
|
+
}
|
|
64
72
|
function useDashboard() {
|
|
65
73
|
const settings = useContext(DashboardContext);
|
|
66
74
|
return { ...DEFAULTS, ...settings, shell: { ...DEFAULT_SHELL, ...settings?.shell, logo: { ...DEFAULT_SHELL.logo, ...settings?.shell?.logo } } };
|
|
67
75
|
}
|
|
68
76
|
export {
|
|
69
77
|
DashboardProvider,
|
|
78
|
+
useComponentDefaults,
|
|
70
79
|
useDashboard
|
|
71
80
|
};
|
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
|
+
};
|
package/dist/GoogleButton.js
CHANGED
|
@@ -4,7 +4,7 @@ function GoogleButton({ href = "/api/auth/google", label = "Continue with Google
|
|
|
4
4
|
"a",
|
|
5
5
|
{
|
|
6
6
|
href,
|
|
7
|
-
className: "flex w-full items-center justify-center gap-3 rounded-full border border-tone-200 bg-
|
|
7
|
+
className: "flex w-full items-center justify-center gap-3 rounded-full border border-tone-200 bg-surface px-4 py-3 text-sm font-semibold text-ink shadow-sm transition-colors hover:bg-tone-50",
|
|
8
8
|
children: [
|
|
9
9
|
/* @__PURE__ */ jsxs("svg", { className: "h-5 w-5", viewBox: "0 0 24 24", "aria-hidden": "true", children: [
|
|
10
10
|
/* @__PURE__ */ jsx("path", { fill: "#4285F4", d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" }),
|
|
@@ -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);
|
|
@@ -31,18 +31,21 @@ function NotificationIcon({ icon }) {
|
|
|
31
31
|
const IconComp = ICON_MAP[icon] || BellRing;
|
|
32
32
|
return /* @__PURE__ */ jsx(IconComp, { className: "w-4 h-4 text-accent" });
|
|
33
33
|
}
|
|
34
|
-
function NotificationsBell() {
|
|
34
|
+
function NotificationsBell({ listPath = "/notifications", markAllPath = "/notifications/mark-read", map }) {
|
|
35
35
|
const navigate = useNavigate();
|
|
36
36
|
const { api } = useDashboard();
|
|
37
37
|
const [showNotifications, setShowNotifications] = useState(false);
|
|
38
38
|
const [notifications, setNotifications] = useState([]);
|
|
39
39
|
const [unreadCount, setUnreadCount] = useState(0);
|
|
40
|
-
const
|
|
41
|
-
|
|
40
|
+
const latest = useRef({ listPath, map });
|
|
41
|
+
latest.current = { listPath, map };
|
|
42
|
+
const fetchNotifications = async (isCancelled = () => false) => {
|
|
42
43
|
try {
|
|
43
|
-
const res = await api.get(
|
|
44
|
+
const res = await api.get(latest.current.listPath);
|
|
45
|
+
if (isCancelled()) return;
|
|
44
46
|
const payload = res.data;
|
|
45
|
-
const
|
|
47
|
+
const raw = Array.isArray(payload) ? payload : Array.isArray(payload?.data) ? payload.data : [];
|
|
48
|
+
const items = latest.current.map ? raw.map(latest.current.map) : raw;
|
|
46
49
|
setNotifications(items);
|
|
47
50
|
setUnreadCount(items.filter((n) => !n.read_at).length);
|
|
48
51
|
} catch (e) {
|
|
@@ -51,23 +54,8 @@ function NotificationsBell() {
|
|
|
51
54
|
};
|
|
52
55
|
useEffect(() => {
|
|
53
56
|
let cancelled = false;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
fetchedRef.current = true;
|
|
57
|
-
try {
|
|
58
|
-
const res = await api.get("/notifications");
|
|
59
|
-
if (cancelled) return;
|
|
60
|
-
const payload = res.data;
|
|
61
|
-
const items = Array.isArray(payload) ? payload : Array.isArray(payload?.data) ? payload.data : [];
|
|
62
|
-
setNotifications(items);
|
|
63
|
-
setUnreadCount(items.filter((n) => !n.read_at).length);
|
|
64
|
-
} catch (e) {
|
|
65
|
-
console.error("Failed to fetch notifications", e);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
init();
|
|
70
|
-
const interval = setInterval(fetchNotifications, 3e4);
|
|
57
|
+
fetchNotifications(() => cancelled);
|
|
58
|
+
const interval = setInterval(() => fetchNotifications(() => cancelled), 3e4);
|
|
71
59
|
return () => {
|
|
72
60
|
cancelled = true;
|
|
73
61
|
clearInterval(interval);
|
|
@@ -75,7 +63,7 @@ function NotificationsBell() {
|
|
|
75
63
|
}, []);
|
|
76
64
|
const handleMarkAllRead = async () => {
|
|
77
65
|
try {
|
|
78
|
-
await api.post(
|
|
66
|
+
await api.post(markAllPath);
|
|
79
67
|
fetchNotifications();
|
|
80
68
|
} catch (e) {
|
|
81
69
|
console.error("Failed to mark read", e);
|