@nivaro/react 0.3.83 → 0.3.84
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/full.css +1 -1
- package/dist/hooks/useSessionRecorder.js +1 -1
- package/dist/index.d.ts +79 -0
- package/dist/index.js +818 -802
- package/dist/shared/components/SignOutNoteBanner.js +97 -0
- package/dist/shared/components/item-edit/UserChip.js +224 -219
- package/dist/shared/components/profile/BulkRestrictedScopes.js +240 -0
- package/dist/shared/components/profile/PersonAdminTools.js +129 -112
- package/dist/shared/components/profile/SignOutMessageInput.js +37 -0
- package/dist/shared/components/profile/session-actions.js +36 -30
- package/dist/shared/lib/sign-out-note.js +54 -0
- package/package.json +1 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { jsx as t, jsxs as r } from "react/jsx-runtime";
|
|
2
|
+
import { useQueryClient as R, useQuery as E, useMutation as F } from "@tanstack/react-query";
|
|
3
|
+
import { Plus as M, Minus as T, X as B, Loader2 as O, Check as X, AlertTriangle as z } from "lucide-react";
|
|
4
|
+
import { useState as g, useMemo as G } from "react";
|
|
5
|
+
import { toast as A } from "sonner";
|
|
6
|
+
import { useNivaroClient as H } from "../../context.js";
|
|
7
|
+
import { get as L, post as J } from "../../lib/commands.js";
|
|
8
|
+
import { toastError as U } from "../../lib/error-toast.js";
|
|
9
|
+
import { cn as C } from "../../lib/utils.js";
|
|
10
|
+
import { ErrorNotice as V } from "../ErrorNotice.js";
|
|
11
|
+
function W(u, p) {
|
|
12
|
+
const c = u.filter((i) => i.is_active !== !1);
|
|
13
|
+
return p ? c.find((i) => i.name === p) ?? null : c.find((i) => i.target_collection === "divisions") ?? c[0] ?? null;
|
|
14
|
+
}
|
|
15
|
+
function ne({
|
|
16
|
+
userIds: u,
|
|
17
|
+
dimension: p,
|
|
18
|
+
onDone: c,
|
|
19
|
+
onClose: i
|
|
20
|
+
}) {
|
|
21
|
+
const y = H(), P = R(), [h, j] = g("add"), [f, S] = g([]), [_, K] = g(!1), [n, k] = g(null), m = E({
|
|
22
|
+
queryKey: ["scope-dimensions"],
|
|
23
|
+
staleTime: 6e4,
|
|
24
|
+
queryFn: () => y.request(L("/scope-dimensions")).then((e) => e.data ?? [])
|
|
25
|
+
}), a = G(() => W(m.data ?? [], p), [m.data, p]), b = (a == null ? void 0 : a.display_field) || "id", x = E({
|
|
26
|
+
enabled: !!a,
|
|
27
|
+
queryKey: ["bulk-scope-options", a == null ? void 0 : a.target_collection, b],
|
|
28
|
+
staleTime: 6e4,
|
|
29
|
+
queryFn: () => y.request(
|
|
30
|
+
L(`/items/${a.target_collection}`, {
|
|
31
|
+
fields: b === "id" ? "id" : `id,${b}`,
|
|
32
|
+
limit: 500,
|
|
33
|
+
sort: a.options_sort || b
|
|
34
|
+
})
|
|
35
|
+
).then(
|
|
36
|
+
(e) => (e.data ?? []).map((s) => ({
|
|
37
|
+
id: s.id,
|
|
38
|
+
label: String(s[b] ?? s.id)
|
|
39
|
+
}))
|
|
40
|
+
)
|
|
41
|
+
}), o = ((a == null ? void 0 : a.label) ?? "value").toLowerCase(), d = F({
|
|
42
|
+
mutationFn: (e) => y.request(
|
|
43
|
+
J("/user-scopes/bulk", {
|
|
44
|
+
user_ids: u,
|
|
45
|
+
dimension: a == null ? void 0 : a.name,
|
|
46
|
+
op: h,
|
|
47
|
+
values: f,
|
|
48
|
+
preview: e,
|
|
49
|
+
allow_empty: _
|
|
50
|
+
})
|
|
51
|
+
).then((s) => s.data),
|
|
52
|
+
onSuccess: (e, s) => {
|
|
53
|
+
if (s) {
|
|
54
|
+
k(e);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const l = e.counts, $ = l.change ?? 0, q = (l.unchanged ?? 0) + (l.refused ?? 0) + (l.not_found ?? 0);
|
|
58
|
+
(l.failed ?? 0) > 0 ? A.error(
|
|
59
|
+
`${$} updated, ${l.failed} could not be saved — open Preview again to see who`
|
|
60
|
+
) : A.success(
|
|
61
|
+
`${$} ${$ === 1 ? "person" : "people"} updated${q ? `, ${q} left as they were` : ""}`
|
|
62
|
+
), k(null), S([]), P.invalidateQueries({ queryKey: ["user-scopes"] }), P.invalidateQueries({ queryKey: ["users"] }), c == null || c();
|
|
63
|
+
},
|
|
64
|
+
onError: (e) => {
|
|
65
|
+
U(e, `Could not change restricted ${o}s`);
|
|
66
|
+
}
|
|
67
|
+
}), v = () => k(null), Q = (e) => {
|
|
68
|
+
v(), S(
|
|
69
|
+
(s) => s.some((l) => String(l) === String(e)) ? s.filter((l) => String(l) !== String(e)) : [...s, e]
|
|
70
|
+
);
|
|
71
|
+
}, N = (n == null ? void 0 : n.counts.change) ?? 0, w = (n == null ? void 0 : n.counts.refused) ?? 0;
|
|
72
|
+
return m.isError || x.isError ? /* @__PURE__ */ t(
|
|
73
|
+
V,
|
|
74
|
+
{
|
|
75
|
+
error: m.error ?? x.error,
|
|
76
|
+
what: `the ${o}s`,
|
|
77
|
+
onRetry: () => {
|
|
78
|
+
m.refetch(), x.refetch();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
) : /* @__PURE__ */ r(
|
|
82
|
+
"div",
|
|
83
|
+
{
|
|
84
|
+
className: "w-full space-y-3 rounded-xl border border-slate-200 bg-white p-3 text-[12px] shadow-sm dark:border-border dark:bg-card",
|
|
85
|
+
"data-bulk-restricted-scopes": !0,
|
|
86
|
+
children: [
|
|
87
|
+
/* @__PURE__ */ r("div", { className: "flex items-center gap-2", children: [
|
|
88
|
+
/* @__PURE__ */ r("p", { className: "font-semibold text-slate-800 dark:text-slate-100", children: [
|
|
89
|
+
"Restricted ",
|
|
90
|
+
o,
|
|
91
|
+
"s · ",
|
|
92
|
+
u.length,
|
|
93
|
+
" ",
|
|
94
|
+
u.length === 1 ? "person" : "people"
|
|
95
|
+
] }),
|
|
96
|
+
/* @__PURE__ */ t("div", { className: "ml-auto inline-flex rounded-lg border border-slate-200 p-0.5 dark:border-border", children: ["add", "remove"].map((e) => /* @__PURE__ */ r(
|
|
97
|
+
"button",
|
|
98
|
+
{
|
|
99
|
+
type: "button",
|
|
100
|
+
"aria-pressed": h === e,
|
|
101
|
+
onClick: () => {
|
|
102
|
+
v(), j(e);
|
|
103
|
+
},
|
|
104
|
+
className: C(
|
|
105
|
+
"inline-flex items-center gap-1 rounded-md px-2 py-1 font-medium transition-colors",
|
|
106
|
+
h === e ? "bg-nvr-cyan text-white" : "text-slate-600 hover:bg-muted dark:text-slate-300"
|
|
107
|
+
),
|
|
108
|
+
children: [
|
|
109
|
+
e === "add" ? /* @__PURE__ */ t(M, { className: "h-3 w-3" }) : /* @__PURE__ */ t(T, { className: "h-3 w-3" }),
|
|
110
|
+
e === "add" ? "Add" : "Remove"
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
e
|
|
114
|
+
)) }),
|
|
115
|
+
i && /* @__PURE__ */ t(
|
|
116
|
+
"button",
|
|
117
|
+
{
|
|
118
|
+
type: "button",
|
|
119
|
+
onClick: i,
|
|
120
|
+
"aria-label": "Close",
|
|
121
|
+
className: "rounded-md p-1 text-slate-400 hover:bg-muted hover:text-slate-600 dark:hover:text-slate-200",
|
|
122
|
+
children: /* @__PURE__ */ t(B, { className: "h-3.5 w-3.5" })
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
] }),
|
|
126
|
+
/* @__PURE__ */ t("fieldset", { className: "m-0 flex flex-wrap gap-1.5 border-0 p-0", "aria-label": `${o}s`, children: x.isLoading || m.isLoading ? /* @__PURE__ */ r("span", { className: "inline-flex items-center gap-1 text-slate-500", children: [
|
|
127
|
+
/* @__PURE__ */ t(O, { className: "h-3 w-3 animate-spin" }),
|
|
128
|
+
" Loading ",
|
|
129
|
+
o,
|
|
130
|
+
"s…"
|
|
131
|
+
] }) : (x.data ?? []).map((e) => {
|
|
132
|
+
const s = f.some((l) => String(l) === String(e.id));
|
|
133
|
+
return /* @__PURE__ */ r(
|
|
134
|
+
"button",
|
|
135
|
+
{
|
|
136
|
+
type: "button",
|
|
137
|
+
"aria-pressed": s,
|
|
138
|
+
onClick: () => Q(e.id),
|
|
139
|
+
className: C(
|
|
140
|
+
"inline-flex items-center gap-1 rounded-full border px-2.5 py-1 font-medium transition-colors",
|
|
141
|
+
s ? "border-nvr-cyan bg-nvr-cyan/10 text-slate-900 dark:text-slate-100" : "border-slate-200 text-slate-600 hover:bg-muted dark:border-border dark:text-slate-300"
|
|
142
|
+
),
|
|
143
|
+
children: [
|
|
144
|
+
s && /* @__PURE__ */ t(X, { className: "h-3 w-3 text-nvr-cyan" }),
|
|
145
|
+
e.label
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
String(e.id)
|
|
149
|
+
);
|
|
150
|
+
}) }),
|
|
151
|
+
n && /* @__PURE__ */ t("div", { className: "overflow-hidden rounded-lg border border-slate-200 dark:border-border", children: /* @__PURE__ */ t("div", { className: "max-h-72 overflow-y-auto", children: /* @__PURE__ */ r("table", { className: "w-full text-[11.5px]", children: [
|
|
152
|
+
/* @__PURE__ */ t("thead", { className: "sticky top-0 bg-slate-50 text-left text-slate-500 dark:bg-muted dark:text-slate-400", children: /* @__PURE__ */ r("tr", { children: [
|
|
153
|
+
/* @__PURE__ */ t("th", { className: "px-2 py-1.5 font-medium", children: "Person" }),
|
|
154
|
+
/* @__PURE__ */ t("th", { className: "px-2 py-1.5 font-medium", children: "Now" }),
|
|
155
|
+
/* @__PURE__ */ t("th", { className: "px-2 py-1.5 font-medium", children: "After" }),
|
|
156
|
+
/* @__PURE__ */ t("th", { className: "px-2 py-1.5 font-medium", children: "Note" })
|
|
157
|
+
] }) }),
|
|
158
|
+
/* @__PURE__ */ t("tbody", { children: n.rows.map((e) => /* @__PURE__ */ r(
|
|
159
|
+
"tr",
|
|
160
|
+
{
|
|
161
|
+
className: "border-t border-slate-100 dark:border-border",
|
|
162
|
+
"data-bulk-scope-row": e.status,
|
|
163
|
+
children: [
|
|
164
|
+
/* @__PURE__ */ t("td", { className: "px-2 py-1.5 font-medium text-slate-800 dark:text-slate-100", children: e.name }),
|
|
165
|
+
/* @__PURE__ */ t("td", { className: "px-2 py-1.5 text-slate-600 dark:text-slate-300", children: e.before_labels.join(", ") || `Every ${o}` }),
|
|
166
|
+
/* @__PURE__ */ t(
|
|
167
|
+
"td",
|
|
168
|
+
{
|
|
169
|
+
className: C(
|
|
170
|
+
"px-2 py-1.5",
|
|
171
|
+
e.status === "change" ? "font-medium text-slate-900 dark:text-slate-50" : "text-slate-400"
|
|
172
|
+
),
|
|
173
|
+
children: e.status === "change" ? e.after_labels.join(", ") || `Every ${o}` : "—"
|
|
174
|
+
}
|
|
175
|
+
),
|
|
176
|
+
/* @__PURE__ */ t("td", { className: "px-2 py-1.5", children: e.status === "change" ? /* @__PURE__ */ t("span", { className: "text-emerald-700 dark:text-emerald-300", children: "Changes" }) : e.status === "refused" ? /* @__PURE__ */ r("span", { className: "inline-flex items-start gap-1 text-amber-700 dark:text-amber-300", children: [
|
|
177
|
+
/* @__PURE__ */ t(z, { className: "mt-px h-3 w-3 shrink-0" }),
|
|
178
|
+
e.reason
|
|
179
|
+
] }) : /* @__PURE__ */ t("span", { className: "text-slate-500 dark:text-slate-400", children: e.reason }) })
|
|
180
|
+
]
|
|
181
|
+
},
|
|
182
|
+
e.user_id
|
|
183
|
+
)) })
|
|
184
|
+
] }) }) }),
|
|
185
|
+
n && h === "remove" && w > 0 && /* @__PURE__ */ r("label", { className: "flex items-start gap-2 text-amber-800 dark:text-amber-200", children: [
|
|
186
|
+
/* @__PURE__ */ t(
|
|
187
|
+
"input",
|
|
188
|
+
{
|
|
189
|
+
type: "checkbox",
|
|
190
|
+
className: "mt-0.5",
|
|
191
|
+
checked: _,
|
|
192
|
+
onChange: (e) => {
|
|
193
|
+
K(e.target.checked), v();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
),
|
|
197
|
+
/* @__PURE__ */ r("span", { children: [
|
|
198
|
+
"Also remove the last restricted ",
|
|
199
|
+
o,
|
|
200
|
+
" for ",
|
|
201
|
+
w,
|
|
202
|
+
" ",
|
|
203
|
+
w === 1 ? "person" : "people",
|
|
204
|
+
" — they would then see every ",
|
|
205
|
+
o
|
|
206
|
+
] })
|
|
207
|
+
] }),
|
|
208
|
+
/* @__PURE__ */ r("div", { className: "flex items-center gap-2", children: [
|
|
209
|
+
/* @__PURE__ */ t(
|
|
210
|
+
"button",
|
|
211
|
+
{
|
|
212
|
+
type: "button",
|
|
213
|
+
disabled: f.length === 0 || d.isPending || !a,
|
|
214
|
+
onClick: () => d.mutate(!0),
|
|
215
|
+
className: "rounded-lg border border-slate-200 px-3 py-1.5 font-medium text-slate-700 transition-colors hover:bg-muted disabled:opacity-40 dark:border-border dark:text-slate-200",
|
|
216
|
+
"data-bulk-scope-preview": !0,
|
|
217
|
+
children: d.isPending && d.variables === !0 ? "Checking…" : "Preview"
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
/* @__PURE__ */ t(
|
|
221
|
+
"button",
|
|
222
|
+
{
|
|
223
|
+
type: "button",
|
|
224
|
+
disabled: !n || N === 0 || d.isPending,
|
|
225
|
+
onClick: () => d.mutate(!1),
|
|
226
|
+
className: "rounded-lg bg-nvr-cyan px-3 py-1.5 font-medium text-white transition-opacity hover:opacity-90 disabled:opacity-40",
|
|
227
|
+
"data-bulk-scope-apply": !0,
|
|
228
|
+
children: d.isPending && d.variables === !1 ? "Saving…" : `Apply to ${N} ${N === 1 ? "person" : "people"}`
|
|
229
|
+
}
|
|
230
|
+
),
|
|
231
|
+
/* @__PURE__ */ t("span", { className: "text-[11px] text-slate-500 dark:text-slate-400", children: n ? null : f.length === 0 ? `Pick the ${o}s to ${h}` : "Preview shows who changes — nothing is saved until Apply" })
|
|
232
|
+
] })
|
|
233
|
+
]
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
export {
|
|
238
|
+
ne as BulkRestrictedScopes,
|
|
239
|
+
W as pickBulkDimension
|
|
240
|
+
};
|