@okjt/dashboard 0.0.0-stage → 0.2.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.
Files changed (53) hide show
  1. package/README.md +149 -2
  2. package/dist/AcceptInvitePage.js +86 -0
  3. package/dist/AccountMenu.js +73 -0
  4. package/dist/ActivityPanel.js +48 -0
  5. package/dist/AdminBulkActions.js +109 -0
  6. package/dist/AdminCard.js +7 -0
  7. package/dist/AdminChromeContext.js +16 -0
  8. package/dist/AdminFloatingToolbar.js +147 -0
  9. package/dist/AdminInput.js +66 -0
  10. package/dist/AdminListPanel.js +26 -0
  11. package/dist/AdminModal.js +23 -0
  12. package/dist/AdminPageHero.js +101 -0
  13. package/dist/AdminPageLayout.js +54 -0
  14. package/dist/AdminPagination.js +92 -0
  15. package/dist/AdminSidePanel.js +479 -0
  16. package/dist/AdminSummaryCards.js +51 -0
  17. package/dist/AdminToolbarFilters.js +168 -0
  18. package/dist/AdminToolbarSearch.js +61 -0
  19. package/dist/AdminTutorial.js +221 -0
  20. package/dist/AuthContext.js +194 -0
  21. package/dist/AuthLayout.js +94 -0
  22. package/dist/CollaborationContext.js +84 -0
  23. package/dist/CollaboratorAvatars.js +36 -0
  24. package/dist/DashboardHeader.js +140 -0
  25. package/dist/DashboardProvider.js +45 -0
  26. package/dist/DashboardShell.js +93 -0
  27. package/dist/DashboardSidebar.js +97 -0
  28. package/dist/DeleteButton.js +21 -0
  29. package/dist/EditableFieldset.js +9 -0
  30. package/dist/EmptyState.js +22 -0
  31. package/dist/GoogleButton.js +22 -0
  32. package/dist/GoogleCallbackPage.js +81 -0
  33. package/dist/NotificationsBell.js +149 -0
  34. package/dist/QueryError.js +23 -0
  35. package/dist/SearchContext.js +16 -0
  36. package/dist/ShareModal.js +228 -0
  37. package/dist/SignInPage.js +198 -0
  38. package/dist/StatCard.js +33 -0
  39. package/dist/ToggleButton.js +26 -0
  40. package/dist/TwoFactorForm.js +26 -0
  41. package/dist/UnsavedChangesStatus.js +13 -0
  42. package/dist/VerifyEmailPage.js +42 -0
  43. package/dist/VersionHistoryDrawer.js +172 -0
  44. package/dist/index.js +125 -0
  45. package/dist/modules.js +32 -0
  46. package/dist/passkeys.js +84 -0
  47. package/dist/useActivityPanel.js +34 -0
  48. package/dist/useAdminAction.js +77 -0
  49. package/dist/useCrudHandlers.js +54 -0
  50. package/dist/useFilteredItems.js +19 -0
  51. package/dist/useSavedViews.js +30 -0
  52. package/dist/useUnsavedChangesGuard.js +41 -0
  53. package/package.json +40 -4
@@ -0,0 +1,22 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ function GoogleButton({ href = "/api/auth/google", label = "Continue with Google" }) {
3
+ return /* @__PURE__ */ jsxs(
4
+ "a",
5
+ {
6
+ href,
7
+ className: "flex w-full items-center justify-center gap-3 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",
8
+ children: [
9
+ /* @__PURE__ */ jsxs("svg", { className: "h-5 w-5", viewBox: "0 0 24 24", "aria-hidden": "true", children: [
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" }),
11
+ /* @__PURE__ */ jsx("path", { fill: "#34A853", d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" }),
12
+ /* @__PURE__ */ jsx("path", { fill: "#FBBC05", d: "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" }),
13
+ /* @__PURE__ */ jsx("path", { fill: "#EA4335", d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" })
14
+ ] }),
15
+ label
16
+ ]
17
+ }
18
+ );
19
+ }
20
+ export {
21
+ GoogleButton as default
22
+ };
@@ -0,0 +1,81 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ import { useSearchParams } from "react-router-dom";
4
+ import { useAuth } from "./AuthContext.js";
5
+ import AuthLayout, { AuthError } from "./AuthLayout.js";
6
+ import TwoFactorForm from "./TwoFactorForm.js";
7
+ function GoogleCallbackPage({ layout: Layout = AuthLayout, onSignedIn, signInPath = "/sign-in" }) {
8
+ const [params] = useSearchParams();
9
+ const { loginWithGoogle, verify2fa } = useAuth();
10
+ const [error, setError] = useState(null);
11
+ const [needs2fa, setNeeds2fa] = useState(false);
12
+ const [emailFor2fa, setEmailFor2fa] = useState("");
13
+ const [code2fa, setCode2fa] = useState("");
14
+ const [loading, setLoading] = useState(true);
15
+ const code = params.get("code");
16
+ useEffect(() => {
17
+ if (!code) {
18
+ setError("Missing sign-in code \u2014 start again from the sign-in page.");
19
+ setLoading(false);
20
+ return;
21
+ }
22
+ let cancelled = false;
23
+ (async () => {
24
+ const result = await loginWithGoogle(code);
25
+ if (cancelled) return;
26
+ if (result.requires_2fa) {
27
+ setNeeds2fa(true);
28
+ setEmailFor2fa(result.email);
29
+ setLoading(false);
30
+ return;
31
+ }
32
+ if (result.success) {
33
+ const problem = onSignedIn?.(result);
34
+ if (typeof problem === "string") {
35
+ setError(problem);
36
+ setLoading(false);
37
+ }
38
+ return;
39
+ }
40
+ setError(result.message);
41
+ setLoading(false);
42
+ })();
43
+ return () => {
44
+ cancelled = true;
45
+ };
46
+ }, [code]);
47
+ const handle2fa = async (e) => {
48
+ e.preventDefault();
49
+ setLoading(true);
50
+ setError(null);
51
+ const result = await verify2fa(emailFor2fa, code2fa);
52
+ if (result.success) {
53
+ const problem = onSignedIn?.(result);
54
+ if (typeof problem === "string") setError(problem);
55
+ } else {
56
+ setError(result.message);
57
+ setLoading(false);
58
+ }
59
+ };
60
+ if (needs2fa) {
61
+ return /* @__PURE__ */ jsxs(
62
+ Layout,
63
+ {
64
+ title: "Two-step verification",
65
+ subtitle: "Enter the 6-digit code from your authenticator app to finish signing in.",
66
+ children: [
67
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
68
+ /* @__PURE__ */ jsx(TwoFactorForm, { id: "google-2fa-code", code: code2fa, onCode: setCode2fa, loading, onSubmit: handle2fa })
69
+ ]
70
+ }
71
+ );
72
+ }
73
+ return /* @__PURE__ */ jsxs(Layout, { title: "Signing you in", subtitle: "Finishing your Google sign-in\u2026", children: [
74
+ /* @__PURE__ */ jsx(AuthError, { children: error }),
75
+ !error && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted", children: "Hang tight." }),
76
+ error && /* @__PURE__ */ jsx("a", { href: signInPath, className: "inline-flex text-sm font-semibold text-body underline underline-offset-4", children: "Back to sign in" })
77
+ ] });
78
+ }
79
+ export {
80
+ GoogleCallbackPage as default
81
+ };
@@ -0,0 +1,149 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect, useRef } from "react";
3
+ import { useNavigate } from "react-router-dom";
4
+ import { motion, AnimatePresence } from "framer-motion";
5
+ import { Bell, BellRing, UserPlus, Gift, Mail, Calendar, CheckCircle, Settings } from "lucide-react";
6
+ import { useDashboard } from "./DashboardProvider.js";
7
+ const ICON_MAP = {
8
+ bell: BellRing,
9
+ user_plus: UserPlus,
10
+ gift: Gift,
11
+ mail: Mail,
12
+ calendar: Calendar,
13
+ check: CheckCircle,
14
+ settings: Settings
15
+ };
16
+ function timeAgo(dateStr) {
17
+ if (!dateStr) return "";
18
+ const now = /* @__PURE__ */ new Date();
19
+ const then = new Date(dateStr);
20
+ const seconds = Math.floor((now - then) / 1e3);
21
+ if (seconds < 60) return "Just now";
22
+ const minutes = Math.floor(seconds / 60);
23
+ if (minutes < 60) return `${minutes}m ago`;
24
+ const hours = Math.floor(minutes / 60);
25
+ if (hours < 24) return `${hours}h ago`;
26
+ const days = Math.floor(hours / 24);
27
+ if (days < 7) return `${days}d ago`;
28
+ return then.toLocaleDateString("en-US", { month: "short", day: "numeric" });
29
+ }
30
+ function NotificationIcon({ icon }) {
31
+ const IconComp = ICON_MAP[icon] || BellRing;
32
+ return /* @__PURE__ */ jsx(IconComp, { className: "w-4 h-4 text-accent" });
33
+ }
34
+ function NotificationsBell() {
35
+ const navigate = useNavigate();
36
+ const { api } = useDashboard();
37
+ const [showNotifications, setShowNotifications] = useState(false);
38
+ const [notifications, setNotifications] = useState([]);
39
+ const [unreadCount, setUnreadCount] = useState(0);
40
+ const fetchedRef = useRef(false);
41
+ const fetchNotifications = async () => {
42
+ try {
43
+ const res = await api.get("/notifications");
44
+ const payload = res.data;
45
+ const items = Array.isArray(payload) ? payload : Array.isArray(payload?.data) ? payload.data : [];
46
+ setNotifications(items);
47
+ setUnreadCount(items.filter((n) => !n.read_at).length);
48
+ } catch (e) {
49
+ console.error("Failed to fetch notifications", e);
50
+ }
51
+ };
52
+ useEffect(() => {
53
+ let cancelled = false;
54
+ const init = async () => {
55
+ if (!fetchedRef.current) {
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);
71
+ return () => {
72
+ cancelled = true;
73
+ clearInterval(interval);
74
+ };
75
+ }, []);
76
+ const handleMarkAllRead = async () => {
77
+ try {
78
+ await api.post("/notifications/mark-read");
79
+ fetchNotifications();
80
+ } catch (e) {
81
+ console.error("Failed to mark read", e);
82
+ }
83
+ };
84
+ return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
85
+ /* @__PURE__ */ jsxs(
86
+ "button",
87
+ {
88
+ onClick: () => setShowNotifications(!showNotifications),
89
+ "aria-label": unreadCount > 0 ? `Notifications, ${unreadCount} unread` : "Notifications",
90
+ "aria-haspopup": "true",
91
+ "aria-expanded": showNotifications,
92
+ className: "relative p-2 rounded-xl hover:bg-black/5",
93
+ children: [
94
+ /* @__PURE__ */ jsx(Bell, { className: "w-5 h-5 text-soft" }),
95
+ /* @__PURE__ */ jsx(
96
+ "span",
97
+ {
98
+ className: "absolute top-1 right-1 w-2 h-2 rounded-full",
99
+ style: { background: "#A67B5B", display: unreadCount > 0 ? "block" : "none" }
100
+ }
101
+ )
102
+ ]
103
+ }
104
+ ),
105
+ /* @__PURE__ */ jsx(AnimatePresence, { children: showNotifications && /* @__PURE__ */ jsxs(
106
+ motion.div,
107
+ {
108
+ initial: { opacity: 0, y: 10, scale: 0.95 },
109
+ animate: { opacity: 1, y: 0, scale: 1 },
110
+ exit: { opacity: 0, y: 10, scale: 0.95 },
111
+ className: "absolute top-full right-0 mt-2 w-80 bg-white rounded-2xl shadow-xl border border-tone-100 py-2 z-50 overflow-hidden",
112
+ children: [
113
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 border-b border-tone-50 flex justify-between items-center", children: [
114
+ /* @__PURE__ */ jsx("span", { className: "text-tone-800 font-medium", children: "Notifications" }),
115
+ /* @__PURE__ */ jsx("button", { onClick: handleMarkAllRead, className: "text-xs text-accent hover:text-accent-dark", children: "Mark all read" })
116
+ ] }),
117
+ /* @__PURE__ */ jsx("div", { className: "max-h-[300px] overflow-y-auto", children: notifications.length > 0 ? notifications.map((n) => {
118
+ const title = n.title || "Notification";
119
+ const message = n.message || "";
120
+ return /* @__PURE__ */ jsx(
121
+ "button",
122
+ {
123
+ type: "button",
124
+ className: "w-full text-left px-4 py-3 hover:bg-paper-warm focus:bg-paper-warm focus:outline-none border-b border-tone-50 last:border-0 transition-colors",
125
+ onClick: () => {
126
+ setShowNotifications(false);
127
+ if (n.link) navigate(n.link);
128
+ },
129
+ children: /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
130
+ /* @__PURE__ */ jsx("div", { className: "mt-0.5 p-1.5 rounded-lg bg-accent/10 shrink-0", children: /* @__PURE__ */ jsx(NotificationIcon, { icon: n.icon }) }),
131
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
132
+ /* @__PURE__ */ jsx("p", { className: `text-sm ${!n.read_at ? "font-bold text-tone-900" : "font-medium text-tone-700"}`, children: title }),
133
+ message && /* @__PURE__ */ jsx("p", { className: "text-xs text-tone-600 mt-0.5 truncate", children: message }),
134
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-tone-500 mt-1", children: timeAgo(n.created_at) })
135
+ ] }),
136
+ !n.read_at && /* @__PURE__ */ jsx("span", { className: "w-2 h-2 rounded-full bg-accent shrink-0 mt-1.5", "aria-label": "Unread" })
137
+ ] })
138
+ },
139
+ n.id
140
+ );
141
+ }) : /* @__PURE__ */ jsx("div", { className: "px-4 py-8 text-center text-xs text-tone-400 italic", children: "No notifications yet" }) })
142
+ ]
143
+ }
144
+ ) })
145
+ ] });
146
+ }
147
+ export {
148
+ NotificationsBell as default
149
+ };
@@ -0,0 +1,23 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { AlertTriangle, RefreshCw } from "lucide-react";
3
+ import { Button } from "@okjt/ui";
4
+ function QueryError({ what = "this data", onRetry, error }) {
5
+ const detail = error?.response?.data?.message || error?.message;
6
+ return /* @__PURE__ */ jsxs("div", { role: "alert", className: "p-6 rounded-2xl bg-red-50 border border-red-100 flex flex-col sm:flex-row sm:items-center gap-4", children: [
7
+ /* @__PURE__ */ jsx(AlertTriangle, { className: "w-6 h-6 text-red-600 shrink-0", "aria-hidden": "true" }),
8
+ /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
9
+ /* @__PURE__ */ jsxs("p", { className: "font-semibold text-red-800", children: [
10
+ "Couldn\u2019t load ",
11
+ what
12
+ ] }),
13
+ /* @__PURE__ */ jsxs("p", { className: "text-sm text-red-700", children: [
14
+ "The numbers below may be missing until it loads.",
15
+ detail ? ` (${detail})` : ""
16
+ ] })
17
+ ] }),
18
+ onRetry && /* @__PURE__ */ jsx(Button, { variant: "danger", icon: RefreshCw, onClick: onRetry, children: "Retry" })
19
+ ] });
20
+ }
21
+ export {
22
+ QueryError as default
23
+ };
@@ -0,0 +1,16 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useState } from "react";
3
+ const SearchContext = createContext(null);
4
+ const INERT_SEARCH = { searchQuery: "", setSearchQuery: () => {
5
+ } };
6
+ function SearchProvider({ children }) {
7
+ const [searchQuery, setSearchQuery] = useState("");
8
+ return /* @__PURE__ */ jsx(SearchContext.Provider, { value: { searchQuery, setSearchQuery }, children });
9
+ }
10
+ function useSearch() {
11
+ return useContext(SearchContext) ?? INERT_SEARCH;
12
+ }
13
+ export {
14
+ SearchProvider,
15
+ useSearch
16
+ };
@@ -0,0 +1,228 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useQuery, useQueryClient } from "@tanstack/react-query";
4
+ import { formatDistanceToNow } from "date-fns";
5
+ import { Copy, Link2, Send, Trash2, RefreshCw, Check } from "lucide-react";
6
+ import { Button, Spinner, notifyError, notifySuccess, usePermissions } from "@okjt/ui";
7
+ import AdminModal from "./AdminModal.js";
8
+ import { AdminInput, AdminTextarea } from "./AdminInput.js";
9
+ import useAdminAction from "./useAdminAction.js";
10
+ import { CollaboratorAvatar } from "./CollaboratorAvatars.js";
11
+ import { useDashboard } from "./DashboardProvider.js";
12
+ import { useModules } from "./modules.js";
13
+ const EMPTY_FORM = { name: "", email: "", message: "", role: "editor" };
14
+ const selectClass = "px-2 py-1.5 rounded-lg border border-tone-200 bg-white text-xs text-tone-700 focus:outline-none focus:ring-2 focus:ring-accent/20";
15
+ function CopyField({ value, label }) {
16
+ const [copied, setCopied] = useState(false);
17
+ const copy = async () => {
18
+ try {
19
+ await navigator.clipboard.writeText(value);
20
+ setCopied(true);
21
+ setTimeout(() => setCopied(false), 2e3);
22
+ } catch {
23
+ notifyError("Could not copy \u2014 select the link and copy it instead");
24
+ }
25
+ };
26
+ return /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
27
+ /* @__PURE__ */ jsx(
28
+ "input",
29
+ {
30
+ readOnly: true,
31
+ value,
32
+ "aria-label": label,
33
+ onFocus: (e) => e.target.select(),
34
+ className: "flex-1 min-w-0 px-3 py-2 rounded-lg border border-tone-200 bg-tone-50 text-xs font-mono text-tone-600"
35
+ }
36
+ ),
37
+ /* @__PURE__ */ jsx(Button, { size: "sm", icon: copied ? Check : Copy, onClick: copy, children: copied ? "Copied" : "Copy" })
38
+ ] });
39
+ }
40
+ function status(person, moduleByKey) {
41
+ if (person.is_you) return "You";
42
+ if (person.pending) return "Invitation pending";
43
+ if (person.online) {
44
+ const where = moduleByKey(person.current_module)?.label;
45
+ return where ? `Online \xB7 on ${where}` : "Online";
46
+ }
47
+ return person.last_active_at ? `Active ${formatDistanceToNow(new Date(person.last_active_at), { addSuffix: true })}` : "Not active yet";
48
+ }
49
+ function ShareModal({ isOpen, onClose }) {
50
+ const queryClient = useQueryClient();
51
+ const [form, setForm] = useState(EMPTY_FORM);
52
+ const [sending, setSending] = useState(false);
53
+ const [lastInvite, setLastInvite] = useState(null);
54
+ const { isOwner } = usePermissions();
55
+ const { api, roles: ROLES, roleLabel, removeCollaborator } = useDashboard();
56
+ const { moduleByKey } = useModules();
57
+ const { data: people = [], isLoading } = useQuery({
58
+ queryKey: ["collaborators"],
59
+ queryFn: async () => (await api.get("/collaborators")).data || [],
60
+ enabled: isOpen,
61
+ staleTime: 1e4
62
+ });
63
+ const sendInvite = async (payload) => {
64
+ setSending(true);
65
+ try {
66
+ const res = await api.post("/collaborators/invite", payload);
67
+ setLastInvite({ email: payload.email, ...res.data });
68
+ if (res.data?.emailed) notifySuccess(`Invitation sent to ${payload.email}`);
69
+ queryClient.invalidateQueries({ queryKey: ["collaborators"] });
70
+ return true;
71
+ } catch (err) {
72
+ notifyError(err, "Could not send the invitation");
73
+ return false;
74
+ } finally {
75
+ setSending(false);
76
+ }
77
+ };
78
+ const onSubmit = async (e) => {
79
+ e.preventDefault();
80
+ if (await sendInvite(form)) setForm(EMPTY_FORM);
81
+ };
82
+ const refreshPeople = () => queryClient.invalidateQueries({ queryKey: ["collaborators"] });
83
+ const removeAccessAction = useAdminAction((person) => removeCollaborator ? removeCollaborator(person) : api.delete(`/collaborators/${person.id}`), {
84
+ role: "owner",
85
+ key: (person) => person.id,
86
+ confirm: (person) => ({
87
+ title: `Remove ${person.name}?`,
88
+ message: `${person.email} will be signed out and can no longer open the dashboard.`,
89
+ confirmLabel: "Remove access",
90
+ tone: "danger"
91
+ }),
92
+ success: (_, person) => `${person.name} no longer has access`,
93
+ error: "Could not remove access",
94
+ onSuccess: refreshPeople
95
+ });
96
+ const removeAccess = removeAccessAction.run;
97
+ const changeRoleAction = useAdminAction((person, role) => api.patch(`/collaborators/${person.id}/role`, { role }), {
98
+ role: "owner",
99
+ key: (person) => person.id,
100
+ success: (res, person) => res.data?.role ? `${person.name} is now ${roleLabel(res.data.role).toLowerCase()}` : "Role updated",
101
+ error: "Could not change the role",
102
+ onSuccess: refreshPeople
103
+ });
104
+ const changeRole = changeRoleAction.run;
105
+ const close = () => {
106
+ setLastInvite(null);
107
+ onClose();
108
+ };
109
+ return /* @__PURE__ */ jsx(AdminModal, { isOpen, onClose: close, title: "Share dashboard", size: "lg", children: /* @__PURE__ */ jsxs("div", { className: "space-y-6 max-h-[70vh] overflow-y-auto -mx-1 px-1", children: [
110
+ !isOwner && /* @__PURE__ */ jsx("p", { className: "text-sm text-tone-600 p-3 rounded-xl bg-tone-50 border border-tone-100", children: "Only owners can invite people or change what they can do. Ask an owner below if someone needs access." }),
111
+ isOwner && /* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-3", children: [
112
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-tone-600", children: "Invite someone to plan with you. They get an email with a link to set their password." }),
113
+ /* @__PURE__ */ jsxs("div", { className: "grid sm:grid-cols-2 gap-3", children: [
114
+ /* @__PURE__ */ jsx(
115
+ AdminInput,
116
+ {
117
+ label: "Name",
118
+ required: true,
119
+ value: form.name,
120
+ placeholder: "e.g. Aunt Mei",
121
+ onChange: (e) => setForm({ ...form, name: e.target.value })
122
+ }
123
+ ),
124
+ /* @__PURE__ */ jsx(
125
+ AdminInput,
126
+ {
127
+ label: "Email",
128
+ type: "email",
129
+ required: true,
130
+ value: form.email,
131
+ placeholder: "name@example.com",
132
+ onChange: (e) => setForm({ ...form, email: e.target.value })
133
+ }
134
+ )
135
+ ] }),
136
+ /* @__PURE__ */ jsx(
137
+ AdminTextarea,
138
+ {
139
+ label: "Personal note (optional)",
140
+ rows: 2,
141
+ value: form.message,
142
+ maxLength: 1e3,
143
+ onChange: (e) => setForm({ ...form, message: e.target.value })
144
+ }
145
+ ),
146
+ /* @__PURE__ */ jsxs("fieldset", { children: [
147
+ /* @__PURE__ */ jsx("legend", { className: "block text-sm font-medium text-tone-600 mb-1", children: "They can" }),
148
+ /* @__PURE__ */ jsx("div", { className: "grid sm:grid-cols-3 gap-2", children: ROLES.map((r) => /* @__PURE__ */ jsxs("label", { className: `p-2.5 rounded-xl border cursor-pointer text-xs transition-colors ${form.role === r.value ? "border-accent/50 bg-accent/5" : "border-tone-200 hover:bg-tone-50"}`, children: [
149
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 font-medium text-sm text-tone-800", children: [
150
+ /* @__PURE__ */ jsx(
151
+ "input",
152
+ {
153
+ type: "radio",
154
+ name: "invite-role",
155
+ value: r.value,
156
+ checked: form.role === r.value,
157
+ onChange: () => setForm({ ...form, role: r.value }),
158
+ className: "text-accent focus:ring-accent"
159
+ }
160
+ ),
161
+ r.label
162
+ ] }),
163
+ /* @__PURE__ */ jsx("span", { className: "block mt-1 text-tone-500 leading-snug", children: r.description })
164
+ ] }, r.value)) })
165
+ ] }),
166
+ /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(Button, { type: "submit", variant: "secondary", icon: Send, loading: sending, children: "Send invite" }) })
167
+ ] }),
168
+ lastInvite?.invite_link && /* @__PURE__ */ jsxs("div", { className: `p-3 rounded-xl border space-y-2 ${lastInvite.emailed ? "bg-tone-50 border-tone-100" : "bg-amber-50 border-amber-200"}`, children: [
169
+ /* @__PURE__ */ jsxs("p", { className: "text-xs text-tone-700 flex items-center gap-1.5", children: [
170
+ /* @__PURE__ */ jsx(Link2, { className: "w-3.5 h-3.5" }),
171
+ lastInvite.emailed ? `Or share this link with ${lastInvite.email} directly (valid ${lastInvite.expires_in_days} days):` : `The email couldn't be sent \u2014 share this link with ${lastInvite.email} (valid ${lastInvite.expires_in_days} days):`
172
+ ] }),
173
+ /* @__PURE__ */ jsx(CopyField, { value: lastInvite.invite_link, label: "Invitation link" })
174
+ ] }),
175
+ /* @__PURE__ */ jsxs("div", { children: [
176
+ /* @__PURE__ */ jsx("h3", { className: "text-xs font-bold uppercase tracking-wider text-tone-500 mb-2", children: "People with access" }),
177
+ isLoading ? /* @__PURE__ */ jsx("div", { className: "py-6 flex justify-center", children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsx("ul", { className: "divide-y divide-tone-100 border border-tone-100 rounded-xl", children: people.map((person) => /* @__PURE__ */ jsxs("li", { className: "flex items-center gap-3 px-3 py-2", children: [
178
+ /* @__PURE__ */ jsxs("span", { className: "relative", children: [
179
+ /* @__PURE__ */ jsx(CollaboratorAvatar, { person }),
180
+ person.online && !person.is_you && /* @__PURE__ */ jsx("span", { className: "absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full bg-green-500 ring-2 ring-white", "aria-hidden": "true" })
181
+ ] }),
182
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
183
+ /* @__PURE__ */ jsx("span", { className: "block text-sm font-medium text-tone-800 truncate", children: person.name }),
184
+ /* @__PURE__ */ jsxs("span", { className: "block text-xs text-tone-500 truncate", children: [
185
+ person.email,
186
+ " \xB7 ",
187
+ status(person, moduleByKey)
188
+ ] })
189
+ ] }),
190
+ isOwner && !person.is_you ? /* @__PURE__ */ jsx(
191
+ "select",
192
+ {
193
+ value: person.role,
194
+ onChange: (e) => changeRole(person, e.target.value),
195
+ "aria-label": `What ${person.name} can do`,
196
+ className: selectClass,
197
+ children: ROLES.map((r) => /* @__PURE__ */ jsx("option", { value: r.value, children: r.label }, r.value))
198
+ }
199
+ ) : /* @__PURE__ */ jsx("span", { className: "px-2 py-0.5 rounded-full bg-tone-100 text-[11px] font-medium text-tone-600", children: roleLabel(person.role) }),
200
+ isOwner && person.pending && /* @__PURE__ */ jsx(
201
+ Button,
202
+ {
203
+ size: "icon-sm",
204
+ icon: RefreshCw,
205
+ "aria-label": `Resend invitation to ${person.name}`,
206
+ title: "Resend invitation",
207
+ onClick: () => sendInvite({ name: person.name, email: person.email, role: person.role }),
208
+ disabled: sending
209
+ }
210
+ ),
211
+ isOwner && !person.is_you && /* @__PURE__ */ jsx(
212
+ Button,
213
+ {
214
+ size: "icon-sm",
215
+ variant: "danger",
216
+ icon: Trash2,
217
+ "aria-label": `Remove ${person.name}`,
218
+ title: "Remove access",
219
+ onClick: () => removeAccess(person)
220
+ }
221
+ )
222
+ ] }, person.id)) })
223
+ ] })
224
+ ] }) });
225
+ }
226
+ export {
227
+ ShareModal as default
228
+ };