@okjt/dashboard 0.0.0-stage → 0.1.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/README.md +144 -2
- package/dist/ActivityPanel.js +48 -0
- package/dist/AdminBulkActions.js +109 -0
- package/dist/AdminCard.js +7 -0
- package/dist/AdminChromeContext.js +16 -0
- package/dist/AdminFloatingToolbar.js +147 -0
- package/dist/AdminInput.js +66 -0
- package/dist/AdminListPanel.js +26 -0
- package/dist/AdminModal.js +23 -0
- package/dist/AdminPageHero.js +101 -0
- package/dist/AdminPageLayout.js +54 -0
- package/dist/AdminPagination.js +92 -0
- package/dist/AdminSidePanel.js +479 -0
- package/dist/AdminSummaryCards.js +51 -0
- package/dist/AdminToolbarFilters.js +168 -0
- package/dist/AdminToolbarSearch.js +61 -0
- package/dist/AdminTutorial.js +221 -0
- package/dist/AuthContext.js +189 -0
- package/dist/CollaborationContext.js +84 -0
- package/dist/CollaboratorAvatars.js +36 -0
- package/dist/DashboardHeader.js +140 -0
- package/dist/DashboardProvider.js +45 -0
- package/dist/DashboardShell.js +93 -0
- package/dist/DashboardSidebar.js +97 -0
- package/dist/DeleteButton.js +21 -0
- package/dist/EditableFieldset.js +9 -0
- package/dist/EmptyState.js +22 -0
- package/dist/GoogleButton.js +22 -0
- package/dist/NotificationsBell.js +149 -0
- package/dist/QueryError.js +23 -0
- package/dist/SearchContext.js +16 -0
- package/dist/ShareModal.js +228 -0
- package/dist/StatCard.js +33 -0
- package/dist/ToggleButton.js +26 -0
- package/dist/UnsavedChangesStatus.js +13 -0
- package/dist/VersionHistoryDrawer.js +172 -0
- package/dist/index.js +110 -0
- package/dist/modules.js +32 -0
- package/dist/passkeys.js +84 -0
- package/dist/useActivityPanel.js +34 -0
- package/dist/useAdminAction.js +77 -0
- package/dist/useCrudHandlers.js +54 -0
- package/dist/useFilteredItems.js +19 -0
- package/dist/useSavedViews.js +30 -0
- package/dist/useUnsavedChangesGuard.js +41 -0
- package/package.json +39 -4
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
4
|
+
import { SlidersHorizontal, List, Grid, LayoutGrid, RotateCcw, Check, Bookmark, BookmarkPlus, X } from "lucide-react";
|
|
5
|
+
import { SegmentedControl } from "@okjt/ui";
|
|
6
|
+
const viewIcons = {
|
|
7
|
+
list: List,
|
|
8
|
+
grid: Grid,
|
|
9
|
+
spreadsheet: LayoutGrid
|
|
10
|
+
};
|
|
11
|
+
const defaultOf = (group) => group.defaultValue ?? group.options?.[0]?.id;
|
|
12
|
+
function countActiveFilters(filters) {
|
|
13
|
+
return (filters?.groups || []).filter((g) => g.value !== defaultOf(g)).length;
|
|
14
|
+
}
|
|
15
|
+
function AdminToolbarFilters({ filters }) {
|
|
16
|
+
const [open, setOpen] = useState(false);
|
|
17
|
+
const panelRef = useRef(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!open) return void 0;
|
|
20
|
+
const onPointerDown = (e) => {
|
|
21
|
+
if (panelRef.current && !panelRef.current.contains(e.target)) setOpen(false);
|
|
22
|
+
};
|
|
23
|
+
const onKeyDown = (e) => {
|
|
24
|
+
if (e.key === "Escape") setOpen(false);
|
|
25
|
+
};
|
|
26
|
+
document.addEventListener("mousedown", onPointerDown);
|
|
27
|
+
document.addEventListener("keydown", onKeyDown);
|
|
28
|
+
return () => {
|
|
29
|
+
document.removeEventListener("mousedown", onPointerDown);
|
|
30
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
31
|
+
};
|
|
32
|
+
}, [open]);
|
|
33
|
+
if (!filters) return null;
|
|
34
|
+
const groups = (filters.groups || []).filter((g) => g.options?.length > 0);
|
|
35
|
+
const sort = filters.sort?.options?.length > 0 ? filters.sort : null;
|
|
36
|
+
const view = filters.view?.options?.length > 1 ? filters.view : null;
|
|
37
|
+
const views = filters.views || null;
|
|
38
|
+
const hasPanel = groups.length > 0 || !!sort || !!filters.extra || !!views;
|
|
39
|
+
if (!hasPanel && !view) return null;
|
|
40
|
+
const activeCount = countActiveFilters(filters);
|
|
41
|
+
const sortChanged = sort && sort.value !== defaultOf(sort);
|
|
42
|
+
const canReset = activeCount > 0 || sortChanged;
|
|
43
|
+
const activeGroups = groups.filter((g) => g.value !== defaultOf(g));
|
|
44
|
+
const buttonLabel = activeGroups.length === 1 ? activeGroups[0].options.find((o) => o.id === activeGroups[0].value)?.label || "Filters" : "Filters";
|
|
45
|
+
const reset = () => {
|
|
46
|
+
groups.forEach((g) => g.value !== defaultOf(g) && g.onChange?.(defaultOf(g)));
|
|
47
|
+
if (sortChanged) sort.onChange?.(defaultOf(sort));
|
|
48
|
+
};
|
|
49
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
50
|
+
hasPanel && /* @__PURE__ */ jsxs("div", { className: "relative", ref: panelRef, children: [
|
|
51
|
+
/* @__PURE__ */ jsxs(
|
|
52
|
+
"button",
|
|
53
|
+
{
|
|
54
|
+
type: "button",
|
|
55
|
+
onClick: () => setOpen((v) => !v),
|
|
56
|
+
"aria-haspopup": "dialog",
|
|
57
|
+
"aria-expanded": open,
|
|
58
|
+
className: `flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-medium transition-all border ${activeCount > 0 ? "bg-accent/10 text-accent-dark border-accent/30" : "bg-white/80 text-body hover:bg-white border-tone-200/60"}`,
|
|
59
|
+
title: "Filter & sort",
|
|
60
|
+
children: [
|
|
61
|
+
/* @__PURE__ */ jsx(SlidersHorizontal, { className: "w-4 h-4" }),
|
|
62
|
+
/* @__PURE__ */ jsx("span", { className: "hidden sm:inline max-w-[10rem] truncate", children: buttonLabel }),
|
|
63
|
+
activeCount > 0 && /* @__PURE__ */ jsx("span", { className: "min-w-5 h-5 px-1 rounded-full bg-accent text-white text-[10px] font-bold flex items-center justify-center", children: activeCount })
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
),
|
|
67
|
+
/* @__PURE__ */ jsx(AnimatePresence, { children: open && /* @__PURE__ */ jsxs(
|
|
68
|
+
motion.div,
|
|
69
|
+
{
|
|
70
|
+
role: "dialog",
|
|
71
|
+
"aria-label": "Filters",
|
|
72
|
+
initial: { opacity: 0, y: 8, scale: 0.97 },
|
|
73
|
+
animate: { opacity: 1, y: 0, scale: 1 },
|
|
74
|
+
exit: { opacity: 0, y: 8, scale: 0.97 },
|
|
75
|
+
transition: { duration: 0.15 },
|
|
76
|
+
className: "absolute bottom-full left-0 mb-3 w-[min(20rem,calc(100vw-2rem))] max-h-[60vh] overflow-y-auto bg-white rounded-2xl shadow-2xl border border-tone-100 p-4 space-y-4 text-left",
|
|
77
|
+
children: [
|
|
78
|
+
groups.map((group) => /* @__PURE__ */ jsxs("div", { children: [
|
|
79
|
+
/* @__PURE__ */ jsx("p", { className: "text-[11px] font-semibold uppercase tracking-wider text-tone-500 mb-2", children: group.label || "Show" }),
|
|
80
|
+
/* @__PURE__ */ jsx(
|
|
81
|
+
SegmentedControl,
|
|
82
|
+
{
|
|
83
|
+
"aria-label": group.label || "Show",
|
|
84
|
+
size: "sm",
|
|
85
|
+
className: "flex-wrap",
|
|
86
|
+
value: group.value,
|
|
87
|
+
onChange: (id) => group.onChange?.(id),
|
|
88
|
+
options: group.options.map((option) => {
|
|
89
|
+
const active = group.value === option.id;
|
|
90
|
+
return {
|
|
91
|
+
value: option.id,
|
|
92
|
+
icon: active ? Check : void 0,
|
|
93
|
+
label: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
94
|
+
option.label,
|
|
95
|
+
option.count !== void 0 && /* @__PURE__ */ jsx("span", { className: active ? "text-white/80" : "text-tone-400", children: option.count })
|
|
96
|
+
] })
|
|
97
|
+
};
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
] }, group.id)),
|
|
102
|
+
sort && /* @__PURE__ */ jsxs("div", { children: [
|
|
103
|
+
/* @__PURE__ */ jsx("p", { className: "text-[11px] font-semibold uppercase tracking-wider text-tone-500 mb-2", children: sort.label || "Sort by" }),
|
|
104
|
+
/* @__PURE__ */ jsx(
|
|
105
|
+
"select",
|
|
106
|
+
{
|
|
107
|
+
value: sort.value || "",
|
|
108
|
+
onChange: (e) => sort.onChange?.(e.target.value),
|
|
109
|
+
"aria-label": sort.label || "Sort by",
|
|
110
|
+
className: "w-full px-3 py-2 rounded-lg border border-tone-200 bg-tone-50 text-sm text-tone-700 focus:outline-none focus:ring-2 focus:ring-accent/20 focus:border-accent",
|
|
111
|
+
children: sort.options.map((option) => /* @__PURE__ */ jsx("option", { value: option.id, children: option.label }, option.id))
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
] }),
|
|
115
|
+
filters.extra && /* @__PURE__ */ jsx("div", { className: "space-y-2", children: filters.extra }),
|
|
116
|
+
views && /* @__PURE__ */ jsxs("div", { children: [
|
|
117
|
+
/* @__PURE__ */ jsx("p", { className: "text-[11px] font-semibold uppercase tracking-wider text-tone-500 mb-2", children: "Saved views" }),
|
|
118
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-1.5", children: [
|
|
119
|
+
views.items.map((view2) => /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center rounded-lg bg-tone-50 text-sm text-tone-700", children: [
|
|
120
|
+
/* @__PURE__ */ jsxs("button", { type: "button", onClick: () => {
|
|
121
|
+
views.onApply(view2.id);
|
|
122
|
+
setOpen(false);
|
|
123
|
+
}, className: "flex items-center gap-1.5 pl-2.5 pr-1 py-1.5 hover:text-accent", children: [
|
|
124
|
+
/* @__PURE__ */ jsx(Bookmark, { className: "w-3.5 h-3.5 text-accent" }),
|
|
125
|
+
view2.name
|
|
126
|
+
] }),
|
|
127
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => views.onDelete(view2.id), className: "p-1.5 text-tone-400 hover:text-red-500", "aria-label": `Delete saved view ${view2.name}`, children: /* @__PURE__ */ jsx(X, { className: "w-3 h-3" }) })
|
|
128
|
+
] }, view2.id)),
|
|
129
|
+
/* @__PURE__ */ jsxs("button", { type: "button", onClick: views.onSave, className: "inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg border border-dashed border-accent/40 text-sm text-accent hover:bg-accent/5", children: [
|
|
130
|
+
/* @__PURE__ */ jsx(BookmarkPlus, { className: "w-3.5 h-3.5" }),
|
|
131
|
+
"Save current view"
|
|
132
|
+
] })
|
|
133
|
+
] })
|
|
134
|
+
] }),
|
|
135
|
+
canReset && /* @__PURE__ */ jsxs(
|
|
136
|
+
"button",
|
|
137
|
+
{
|
|
138
|
+
type: "button",
|
|
139
|
+
onClick: reset,
|
|
140
|
+
className: "w-full flex items-center justify-center gap-2 pt-3 border-t border-tone-100 text-sm text-tone-500 hover:text-accent",
|
|
141
|
+
children: [
|
|
142
|
+
/* @__PURE__ */ jsx(RotateCcw, { className: "w-3.5 h-3.5" }),
|
|
143
|
+
"Reset to defaults"
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
) })
|
|
150
|
+
] }),
|
|
151
|
+
view && /* @__PURE__ */ jsx(
|
|
152
|
+
SegmentedControl,
|
|
153
|
+
{
|
|
154
|
+
"aria-label": "View mode",
|
|
155
|
+
value: view.value,
|
|
156
|
+
onChange: (mode) => view.onChange?.(mode),
|
|
157
|
+
options: view.options.map((mode) => {
|
|
158
|
+
const label = `${mode.charAt(0).toUpperCase()}${mode.slice(1)} view`;
|
|
159
|
+
return { value: mode, icon: viewIcons[mode] || List, ariaLabel: label, title: label };
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
] });
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
countActiveFilters,
|
|
167
|
+
AdminToolbarFilters as default
|
|
168
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { Search, X } from "lucide-react";
|
|
4
|
+
import { useSearch } from "./SearchContext.js";
|
|
5
|
+
function AdminToolbarSearch({ placeholder = "Search...", value, onChange }) {
|
|
6
|
+
const global = useSearch();
|
|
7
|
+
const query = value ?? global.searchQuery;
|
|
8
|
+
const setQuery = onChange ?? global.setSearchQuery;
|
|
9
|
+
const inputRef = useRef(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const onKeyDown = (e) => {
|
|
12
|
+
const target = e.target;
|
|
13
|
+
const typing = target instanceof HTMLElement && (target.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(target.tagName));
|
|
14
|
+
const isShortcut = e.key === "k" && (e.metaKey || e.ctrlKey) || e.key === "/" && !typing;
|
|
15
|
+
if (!isShortcut) return;
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
inputRef.current?.focus();
|
|
18
|
+
inputRef.current?.select();
|
|
19
|
+
};
|
|
20
|
+
document.addEventListener("keydown", onKeyDown);
|
|
21
|
+
return () => document.removeEventListener("keydown", onKeyDown);
|
|
22
|
+
}, []);
|
|
23
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
24
|
+
/* @__PURE__ */ jsx(Search, { className: "absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-tone-400 pointer-events-none" }),
|
|
25
|
+
/* @__PURE__ */ jsx(
|
|
26
|
+
"input",
|
|
27
|
+
{
|
|
28
|
+
ref: inputRef,
|
|
29
|
+
type: "search",
|
|
30
|
+
value: query || "",
|
|
31
|
+
onChange: (e) => setQuery(e.target.value),
|
|
32
|
+
onKeyDown: (e) => {
|
|
33
|
+
if (e.key === "Escape" && query) {
|
|
34
|
+
e.stopPropagation();
|
|
35
|
+
setQuery("");
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
placeholder,
|
|
39
|
+
"aria-label": placeholder,
|
|
40
|
+
title: "Search (press / to focus)",
|
|
41
|
+
className: "w-28 sm:w-52 xl:w-60 pl-9 pr-8 py-2 sm:py-2.5 rounded-xl border border-tone-200/60 bg-white/80 text-sm text-tone-700 focus:bg-white focus:outline-none focus:ring-2 focus:ring-accent/30 focus:border-accent [&::-webkit-search-cancel-button]:hidden"
|
|
42
|
+
}
|
|
43
|
+
),
|
|
44
|
+
query && /* @__PURE__ */ jsx(
|
|
45
|
+
"button",
|
|
46
|
+
{
|
|
47
|
+
type: "button",
|
|
48
|
+
"aria-label": "Clear search",
|
|
49
|
+
onClick: () => {
|
|
50
|
+
setQuery("");
|
|
51
|
+
inputRef.current?.focus();
|
|
52
|
+
},
|
|
53
|
+
className: "absolute right-2 top-1/2 -translate-y-1/2 p-0.5 text-tone-400 hover:text-tone-600",
|
|
54
|
+
children: /* @__PURE__ */ jsx(X, { className: "w-4 h-4" })
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
] });
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
AdminToolbarSearch as default
|
|
61
|
+
};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useState, useEffect, useLayoutEffect, useRef } from "react";
|
|
3
|
+
import { motion, AnimatePresence } from "framer-motion";
|
|
4
|
+
import { ChevronRight, ChevronLeft, X, Trophy, Sparkles } from "lucide-react";
|
|
5
|
+
import { Button } from "@okjt/ui";
|
|
6
|
+
function AdminTutorial({ steps, onComplete, isRestarted = false }) {
|
|
7
|
+
const [currentStep, setCurrentStep] = useState(0);
|
|
8
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
9
|
+
const [coords, setCoords] = useState(null);
|
|
10
|
+
const [boxHeight, setBoxHeight] = useState(360);
|
|
11
|
+
const boxRef = useRef(null);
|
|
12
|
+
useLayoutEffect(() => {
|
|
13
|
+
if (boxRef.current) setBoxHeight(boxRef.current.offsetHeight);
|
|
14
|
+
}, [currentStep, isVisible, coords]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const isCompleted = localStorage.getItem("admin-tutorial-complete");
|
|
17
|
+
if (!isCompleted || isRestarted) {
|
|
18
|
+
const timer = setTimeout(() => setIsVisible(true), 1e3);
|
|
19
|
+
return () => clearTimeout(timer);
|
|
20
|
+
}
|
|
21
|
+
}, [isRestarted]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (isVisible) {
|
|
24
|
+
const step2 = steps[currentStep];
|
|
25
|
+
const el = document.getElementById(step2.target);
|
|
26
|
+
if (el) {
|
|
27
|
+
el.scrollIntoView({ behavior: "auto", block: "center" });
|
|
28
|
+
}
|
|
29
|
+
const timer = requestAnimationFrame(() => {
|
|
30
|
+
updateCoords();
|
|
31
|
+
});
|
|
32
|
+
window.addEventListener("resize", updateCoords);
|
|
33
|
+
return () => {
|
|
34
|
+
window.removeEventListener("resize", updateCoords);
|
|
35
|
+
cancelAnimationFrame(timer);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}, [isVisible, currentStep]);
|
|
39
|
+
const updateCoords = () => {
|
|
40
|
+
const step2 = steps[currentStep];
|
|
41
|
+
const el = document.getElementById(step2.target);
|
|
42
|
+
if (el) {
|
|
43
|
+
const rect = el.getBoundingClientRect();
|
|
44
|
+
if (!isNaN(rect.top) && !isNaN(rect.left)) {
|
|
45
|
+
setCoords({
|
|
46
|
+
top: rect.top,
|
|
47
|
+
left: rect.left,
|
|
48
|
+
bottom: rect.bottom,
|
|
49
|
+
right: rect.right,
|
|
50
|
+
width: rect.width,
|
|
51
|
+
height: rect.height
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
setCoords(null);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const handleNext = () => {
|
|
59
|
+
if (currentStep < steps.length - 1) {
|
|
60
|
+
setCurrentStep(currentStep + 1);
|
|
61
|
+
} else {
|
|
62
|
+
handleComplete();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const handleBack = () => {
|
|
66
|
+
if (currentStep > 0) {
|
|
67
|
+
setCurrentStep(currentStep - 1);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const handleComplete = () => {
|
|
71
|
+
setIsVisible(false);
|
|
72
|
+
localStorage.setItem("admin-tutorial-complete", "true");
|
|
73
|
+
if (onComplete) onComplete();
|
|
74
|
+
};
|
|
75
|
+
const getBoxStyle = () => {
|
|
76
|
+
if (!coords) {
|
|
77
|
+
return { style: { top: "50%", left: "50%", transform: "translate(-50%, -50%)" }, placement: null };
|
|
78
|
+
}
|
|
79
|
+
const margin = 16;
|
|
80
|
+
const gap = 24;
|
|
81
|
+
const vw = window.innerWidth;
|
|
82
|
+
const vh = window.innerHeight;
|
|
83
|
+
const boxW = Math.min(384, vw - margin * 2);
|
|
84
|
+
const boxH = boxHeight || 360;
|
|
85
|
+
const isMobile = vw < 768;
|
|
86
|
+
const preferRight = step.position === "right" && !isMobile;
|
|
87
|
+
let left;
|
|
88
|
+
let top;
|
|
89
|
+
let placement2;
|
|
90
|
+
if (preferRight) {
|
|
91
|
+
left = coords.right + gap;
|
|
92
|
+
if (left + boxW > vw - margin) {
|
|
93
|
+
left = coords.left - gap - boxW;
|
|
94
|
+
placement2 = "left";
|
|
95
|
+
} else {
|
|
96
|
+
placement2 = "right";
|
|
97
|
+
}
|
|
98
|
+
top = coords.top + coords.height / 2 - boxH / 2;
|
|
99
|
+
} else {
|
|
100
|
+
left = coords.left + coords.width / 2 - boxW / 2;
|
|
101
|
+
top = coords.bottom + gap;
|
|
102
|
+
placement2 = "bottom";
|
|
103
|
+
if (top + boxH > vh - margin) {
|
|
104
|
+
const above = coords.top - gap - boxH;
|
|
105
|
+
if (above >= margin) {
|
|
106
|
+
top = above;
|
|
107
|
+
placement2 = "top";
|
|
108
|
+
} else {
|
|
109
|
+
top = Math.max(margin, vh - margin - boxH);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
left = Math.min(Math.max(margin, left), vw - margin - boxW);
|
|
114
|
+
top = Math.min(Math.max(margin, top), vh - margin - boxH);
|
|
115
|
+
return { style: { top, left, width: boxW }, placement: placement2 };
|
|
116
|
+
};
|
|
117
|
+
if (!isVisible) return null;
|
|
118
|
+
const step = steps[currentStep];
|
|
119
|
+
const { style: boxStyle, placement } = getBoxStyle();
|
|
120
|
+
return /* @__PURE__ */ jsxs("div", { className: "fixed inset-0 z-[100] pointer-events-none", children: [
|
|
121
|
+
/* @__PURE__ */ jsx(
|
|
122
|
+
motion.div,
|
|
123
|
+
{
|
|
124
|
+
initial: { opacity: 0 },
|
|
125
|
+
animate: { opacity: 1 },
|
|
126
|
+
exit: { opacity: 0 },
|
|
127
|
+
className: "absolute inset-0 bg-black/60 backdrop-blur-[2px] pointer-events-auto",
|
|
128
|
+
onClick: handleComplete,
|
|
129
|
+
style: {
|
|
130
|
+
clipPath: coords ? `polygon(0% 0%, 0% 100%, ${coords.left - 4}px 100%, ${coords.left - 4}px ${coords.top - 4}px, ${coords.right + 4}px ${coords.top - 4}px, ${coords.right + 4}px ${coords.bottom + 4}px, ${coords.left - 4}px ${coords.bottom + 4}px, ${coords.left - 4}px 100%, 100% 100%, 100% 0%)` : "none"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
),
|
|
134
|
+
/* @__PURE__ */ jsxs(
|
|
135
|
+
motion.div,
|
|
136
|
+
{
|
|
137
|
+
layout: true,
|
|
138
|
+
ref: boxRef,
|
|
139
|
+
initial: { opacity: 0, scale: 0.95 },
|
|
140
|
+
animate: { opacity: 1, scale: 1 },
|
|
141
|
+
style: boxStyle,
|
|
142
|
+
className: "absolute w-[calc(100%-48px)] max-w-sm max-h-[calc(100vh-32px)] flex flex-col bg-white rounded-3xl shadow-2xl overflow-hidden pointer-events-auto border-2 border-accent/30",
|
|
143
|
+
children: [
|
|
144
|
+
/* @__PURE__ */ jsx("div", { className: "h-1.5 w-full bg-tone-100", children: /* @__PURE__ */ jsx(
|
|
145
|
+
motion.div,
|
|
146
|
+
{
|
|
147
|
+
className: "h-full bg-accent",
|
|
148
|
+
initial: { width: 0 },
|
|
149
|
+
animate: { width: `${(currentStep + 1) / steps.length * 100}%` }
|
|
150
|
+
}
|
|
151
|
+
) }),
|
|
152
|
+
/* @__PURE__ */ jsx("div", { className: "p-6 pb-0", children: /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-start mb-4", children: [
|
|
153
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
154
|
+
/* @__PURE__ */ jsx("div", { className: "w-10 h-10 rounded-xl bg-accent/10 flex items-center justify-center", children: currentStep === steps.length - 1 ? /* @__PURE__ */ jsx(Trophy, { className: "w-5 h-5 text-accent" }) : /* @__PURE__ */ jsx("span", { className: "text-accent font-bold text-base", children: currentStep + 1 }) }),
|
|
155
|
+
currentStep === 0 && /* @__PURE__ */ jsx("span", { className: "bg-accent/10 text-accent text-[10px] uppercase tracking-wider font-bold px-2 py-1 rounded-md", children: "New Feature" })
|
|
156
|
+
] }),
|
|
157
|
+
/* @__PURE__ */ jsx(
|
|
158
|
+
"button",
|
|
159
|
+
{
|
|
160
|
+
"aria-label": "Close tour",
|
|
161
|
+
onClick: handleComplete,
|
|
162
|
+
className: "p-1.5 hover:bg-tone-50 rounded-lg text-tone-300 hover:text-tone-500 transition-colors",
|
|
163
|
+
children: /* @__PURE__ */ jsx(X, { className: "w-5 h-5" })
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
] }) }),
|
|
167
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-y-auto px-6 pb-4", children: /* @__PURE__ */ jsx(AnimatePresence, { mode: "wait", children: /* @__PURE__ */ jsxs(
|
|
168
|
+
motion.div,
|
|
169
|
+
{
|
|
170
|
+
initial: { opacity: 0, y: 10 },
|
|
171
|
+
animate: { opacity: 1, y: 0 },
|
|
172
|
+
exit: { opacity: 0, y: -10 },
|
|
173
|
+
className: "min-h-[100px]",
|
|
174
|
+
children: [
|
|
175
|
+
/* @__PURE__ */ jsxs("h3", { className: "text-xl font-semibold text-body mb-2 flex items-center gap-2", children: [
|
|
176
|
+
step.title,
|
|
177
|
+
currentStep === 0 && /* @__PURE__ */ jsx(Sparkles, { className: "w-4 h-4 text-accent" })
|
|
178
|
+
] }),
|
|
179
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted text-sm leading-relaxed", children: step.content })
|
|
180
|
+
]
|
|
181
|
+
},
|
|
182
|
+
currentStep
|
|
183
|
+
) }) }),
|
|
184
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4 border-t border-tone-100 bg-white rounded-b-3xl", children: [
|
|
185
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-1.5", children: [
|
|
186
|
+
/* @__PURE__ */ jsx(
|
|
187
|
+
Button,
|
|
188
|
+
{
|
|
189
|
+
size: "icon",
|
|
190
|
+
icon: ChevronLeft,
|
|
191
|
+
"aria-label": "Previous step",
|
|
192
|
+
onClick: handleBack,
|
|
193
|
+
disabled: currentStep === 0
|
|
194
|
+
}
|
|
195
|
+
),
|
|
196
|
+
/* @__PURE__ */ jsxs(Button, { variant: "secondary", onClick: handleNext, children: [
|
|
197
|
+
currentStep === steps.length - 1 ? "Finish Tour" : "Next Step",
|
|
198
|
+
/* @__PURE__ */ jsx(ChevronRight, {})
|
|
199
|
+
] })
|
|
200
|
+
] }),
|
|
201
|
+
/* @__PURE__ */ jsx(
|
|
202
|
+
"button",
|
|
203
|
+
{
|
|
204
|
+
onClick: handleComplete,
|
|
205
|
+
className: "text-xs text-tone-400 hover:text-accent transition-colors font-medium px-2",
|
|
206
|
+
children: "Skip Tour"
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
] }),
|
|
210
|
+
coords && placement === "right" && /* @__PURE__ */ jsx("div", { className: "absolute right-full top-1/2 -translate-y-1/2 border-y-[8px] border-y-transparent border-r-[8px] border-r-white" }),
|
|
211
|
+
coords && placement === "left" && /* @__PURE__ */ jsx("div", { className: "absolute left-full top-1/2 -translate-y-1/2 border-y-[8px] border-y-transparent border-l-[8px] border-l-white" }),
|
|
212
|
+
coords && placement === "bottom" && /* @__PURE__ */ jsx("div", { className: "absolute bottom-full left-1/2 -translate-x-1/2 border-x-[8px] border-x-transparent border-b-[8px] border-b-white" }),
|
|
213
|
+
coords && placement === "top" && /* @__PURE__ */ jsx("div", { className: "absolute top-full left-1/2 -translate-x-1/2 border-x-[8px] border-x-transparent border-t-[8px] border-t-white" })
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
] });
|
|
218
|
+
}
|
|
219
|
+
export {
|
|
220
|
+
AdminTutorial as default
|
|
221
|
+
};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useState, useEffect } from "react";
|
|
3
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
const AuthContext = createContext(null);
|
|
5
|
+
function AuthProvider({ api, extend, children }) {
|
|
6
|
+
const queryClient = useQueryClient();
|
|
7
|
+
const [user, setUser] = useState(null);
|
|
8
|
+
const [loading, setLoading] = useState(true);
|
|
9
|
+
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
10
|
+
const [signedOut, setSignedOut] = useState(false);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
checkAuth();
|
|
13
|
+
}, []);
|
|
14
|
+
const checkAuth = async () => {
|
|
15
|
+
const token = localStorage.getItem("auth_token");
|
|
16
|
+
if (token) {
|
|
17
|
+
try {
|
|
18
|
+
const response = await api.get("/user");
|
|
19
|
+
setUser(response.data);
|
|
20
|
+
setIsAuthenticated(true);
|
|
21
|
+
} catch {
|
|
22
|
+
localStorage.removeItem("auth_token");
|
|
23
|
+
setUser(null);
|
|
24
|
+
setIsAuthenticated(false);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
setLoading(false);
|
|
28
|
+
};
|
|
29
|
+
const login = async (email, password) => {
|
|
30
|
+
try {
|
|
31
|
+
const response = await api.post("/login", { email, password });
|
|
32
|
+
if (response.data.requires_verification) {
|
|
33
|
+
return {
|
|
34
|
+
success: false,
|
|
35
|
+
requires_verification: true,
|
|
36
|
+
email: response.data.email,
|
|
37
|
+
message: response.data.message || "Please verify your email before signing in."
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (response.data.requires_2fa) {
|
|
41
|
+
return {
|
|
42
|
+
success: true,
|
|
43
|
+
requires_2fa: true,
|
|
44
|
+
email: response.data.email
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const { token, user: user2, ...extra } = response.data;
|
|
48
|
+
localStorage.setItem("auth_token", token);
|
|
49
|
+
setUser({ ...user2, ...extra });
|
|
50
|
+
setIsAuthenticated(true);
|
|
51
|
+
return { success: true, ...extra };
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return {
|
|
54
|
+
success: false,
|
|
55
|
+
message: error.response?.data?.message || "Login failed"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const verify2fa = async (email, code) => {
|
|
60
|
+
try {
|
|
61
|
+
const response = await api.post("/verify-2fa", { email, code });
|
|
62
|
+
const { token, user: user2, ...extra } = response.data;
|
|
63
|
+
localStorage.setItem("auth_token", token);
|
|
64
|
+
setUser({ ...user2, ...extra });
|
|
65
|
+
setIsAuthenticated(true);
|
|
66
|
+
return { success: true, ...extra };
|
|
67
|
+
} catch (error) {
|
|
68
|
+
return {
|
|
69
|
+
success: false,
|
|
70
|
+
message: error.response?.data?.message || "Invalid 2FA code"
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const register = async (data) => {
|
|
75
|
+
try {
|
|
76
|
+
const response = await api.post("/register", data);
|
|
77
|
+
const payload = response.data;
|
|
78
|
+
if (payload.requires_verification) {
|
|
79
|
+
return {
|
|
80
|
+
success: false,
|
|
81
|
+
requires_verification: true,
|
|
82
|
+
email: payload.email,
|
|
83
|
+
message: payload.message
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const { token, user: user2, ...extra } = payload;
|
|
87
|
+
localStorage.setItem("auth_token", token);
|
|
88
|
+
setUser({ ...user2, ...extra });
|
|
89
|
+
setIsAuthenticated(true);
|
|
90
|
+
return { success: true };
|
|
91
|
+
} catch (error) {
|
|
92
|
+
return {
|
|
93
|
+
success: false,
|
|
94
|
+
message: error.response?.data?.message || "Sign-up failed",
|
|
95
|
+
errors: error.response?.data?.errors || {}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const resendVerification = async (email) => {
|
|
100
|
+
try {
|
|
101
|
+
await api.post("/email/resend", email ? { email } : {});
|
|
102
|
+
return { success: true };
|
|
103
|
+
} catch (error) {
|
|
104
|
+
return { success: false, message: error.response?.data?.message || "Could not resend \u2014 try again." };
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const verifyEmail = async ({ id, hash }) => {
|
|
108
|
+
try {
|
|
109
|
+
const response = await api.post("/email/verify", { id, hash });
|
|
110
|
+
const { token, user: user2, message: _message, email_verified: _verified, ...extra } = response.data;
|
|
111
|
+
if (token) {
|
|
112
|
+
localStorage.setItem("auth_token", token);
|
|
113
|
+
setUser({ ...user2, ...extra });
|
|
114
|
+
setIsAuthenticated(true);
|
|
115
|
+
} else {
|
|
116
|
+
await checkAuth();
|
|
117
|
+
}
|
|
118
|
+
return { success: true, message: response.data?.message };
|
|
119
|
+
} catch (error) {
|
|
120
|
+
return { success: false, message: error.response?.data?.message || "Verification link is invalid or expired." };
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const loginWithGoogle = async (code) => {
|
|
124
|
+
try {
|
|
125
|
+
const response = await api.post("/auth/google", { code });
|
|
126
|
+
if (response.data.requires_2fa) {
|
|
127
|
+
return { success: true, requires_2fa: true, email: response.data.email };
|
|
128
|
+
}
|
|
129
|
+
const { token, user: user2, ...extra } = response.data;
|
|
130
|
+
localStorage.setItem("auth_token", token);
|
|
131
|
+
setUser({ ...user2, ...extra });
|
|
132
|
+
setIsAuthenticated(true);
|
|
133
|
+
return { success: true, ...extra };
|
|
134
|
+
} catch (error) {
|
|
135
|
+
return {
|
|
136
|
+
success: false,
|
|
137
|
+
message: error.response?.data?.message || "Google sign-in failed"
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const loginWithToken = (token, authUser, extra = {}) => {
|
|
142
|
+
localStorage.setItem("auth_token", token);
|
|
143
|
+
setUser({ ...authUser, ...extra });
|
|
144
|
+
setIsAuthenticated(true);
|
|
145
|
+
};
|
|
146
|
+
const logout = async () => {
|
|
147
|
+
try {
|
|
148
|
+
await api.post("/logout");
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error("Logout error:", error);
|
|
151
|
+
} finally {
|
|
152
|
+
localStorage.removeItem("auth_token");
|
|
153
|
+
queryClient.clear();
|
|
154
|
+
setUser(null);
|
|
155
|
+
setIsAuthenticated(false);
|
|
156
|
+
setSignedOut(true);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const base = {
|
|
160
|
+
user,
|
|
161
|
+
loading,
|
|
162
|
+
isAuthenticated,
|
|
163
|
+
signedOut,
|
|
164
|
+
login,
|
|
165
|
+
register,
|
|
166
|
+
verify2fa,
|
|
167
|
+
loginWithToken,
|
|
168
|
+
loginWithGoogle,
|
|
169
|
+
resendVerification,
|
|
170
|
+
verifyEmail,
|
|
171
|
+
logout,
|
|
172
|
+
checkAuth
|
|
173
|
+
};
|
|
174
|
+
const value = extend ? { ...base, ...extend(base, { setUser }) } : base;
|
|
175
|
+
return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children });
|
|
176
|
+
}
|
|
177
|
+
function useAuth() {
|
|
178
|
+
const context = useContext(AuthContext);
|
|
179
|
+
if (!context) {
|
|
180
|
+
throw new Error("useAuth must be used within an AuthProvider");
|
|
181
|
+
}
|
|
182
|
+
return context;
|
|
183
|
+
}
|
|
184
|
+
var AuthContext_default = AuthContext;
|
|
185
|
+
export {
|
|
186
|
+
AuthProvider,
|
|
187
|
+
AuthContext_default as default,
|
|
188
|
+
useAuth
|
|
189
|
+
};
|