@nivaro/react 0.3.5 → 0.3.7

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.
@@ -1,44 +1,46 @@
1
- import { jsxs as s, jsx as e, Fragment as E } from "react/jsx-runtime";
1
+ import { jsxs as o, jsx as e, Fragment as E } from "react/jsx-runtime";
2
2
  import { useMutation as f, useQuery as M } from "@tanstack/react-query";
3
- import { RefreshCw as S, GitMerge as U, UserMinus as B } from "lucide-react";
4
- import { useState as c } from "react";
3
+ import { RefreshCw as P, GitMerge as U, UserMinus as B } from "lucide-react";
4
+ import { useState as m } from "react";
5
5
  import { toast as g } from "sonner";
6
- import { useNivaroClient as k } from "../../context.js";
7
- import { post as w, get as $ } from "../../lib/commands.js";
6
+ import { useNivaroClient as y } from "../../context.js";
7
+ import { post as v, get as $ } from "../../lib/commands.js";
8
8
  import { cn as I } from "../../lib/utils.js";
9
- import { SectionCard as C, EmptyLine as R } from "./primitives.js";
10
- import { errorText as v, useInvalidatePerson as j } from "./types.js";
9
+ import { SectionCard as C, EmptyLine as S } from "./primitives.js";
10
+ import { errorText as w, useInvalidatePerson as j } from "./types.js";
11
11
  function te({ profile: d }) {
12
- const m = k(), [p, t] = c("15"), [h, i] = c(""), l = f({
13
- mutationFn: () => m.request(
14
- w("/realtime/force-refresh", {
12
+ const u = y(), [p, t] = m("15"), [h, i] = m(""), l = f({
13
+ mutationFn: () => u.request(
14
+ v("/realtime/force-refresh", {
15
15
  user_ids: [d.id],
16
16
  seconds: Number(p) || 15,
17
17
  message: h
18
18
  })
19
- ).then((a) => a.data),
20
- onSuccess: ({ sockets: a }) => g.success(
21
- a > 0 ? `Reload pushed to ${a} open tab${a === 1 ? "" : "s"}` : "Reload sent — they have no tab connected to this node right now"
19
+ ).then((n) => n.data),
20
+ // The reload rides the person's room on every server; only the tab count can fall short.
21
+ // A server without `nodes` counts only the tabs on the server that took this request.
22
+ onSuccess: ({ sockets: n, nodes: s, partial: c }) => g.success(
23
+ n > 0 ? `Reload pushed to ${n} open tab${n === 1 ? "" : "s"}${c ? " (another server did not answer — there may be more)" : ""}` : c ? "Reload sent — another server did not answer, so their open tabs could not be counted" : s != null ? "Reload sent — they have no tab open right now" : "Reload sent to every tab they have open (tabs on other servers are not counted)"
22
24
  ),
23
- onError: (a) => g.error(v(a, "Failed to push the reload"))
25
+ onError: (n) => g.error(w(n, "Failed to push the reload"))
24
26
  });
25
- return /* @__PURE__ */ s(
27
+ return /* @__PURE__ */ o(
26
28
  C,
27
29
  {
28
- icon: /* @__PURE__ */ e(S, { className: "h-4 w-4" }),
30
+ icon: /* @__PURE__ */ e(P, { className: "h-4 w-4" }),
29
31
  title: "Force a reload",
30
32
  hint: "Every tab they have open shows a countdown, then reloads onto the current build",
31
33
  tone: "danger",
32
34
  testId: "force-reload",
33
35
  children: [
34
- /* @__PURE__ */ s("div", { className: "flex flex-wrap items-center gap-2", "data-user-force-reload": !0, children: [
35
- /* @__PURE__ */ s("label", { className: "flex items-center gap-1.5 text-[12px] text-slate-600 dark:text-slate-300", children: [
36
+ /* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-2", "data-user-force-reload": !0, children: [
37
+ /* @__PURE__ */ o("label", { className: "flex items-center gap-1.5 text-[12px] text-slate-600 dark:text-slate-300", children: [
36
38
  "Countdown",
37
39
  /* @__PURE__ */ e(
38
40
  "input",
39
41
  {
40
42
  value: p,
41
- onChange: (a) => t(a.target.value),
43
+ onChange: (n) => t(n.target.value),
42
44
  inputMode: "numeric",
43
45
  className: "h-7 w-14 rounded-md border border-slate-200 bg-white px-2 text-right text-[12px] dark:border-border dark:bg-background"
44
46
  }
@@ -49,12 +51,12 @@ function te({ profile: d }) {
49
51
  "input",
50
52
  {
51
53
  value: h,
52
- onChange: (a) => i(a.target.value),
54
+ onChange: (n) => i(n.target.value),
53
55
  placeholder: "Optional message in their banner",
54
56
  className: "h-7 min-w-[200px] flex-1 rounded-md border border-slate-200 bg-white px-2.5 text-[12px] dark:border-border dark:bg-background"
55
57
  }
56
58
  ),
57
- /* @__PURE__ */ s(
59
+ /* @__PURE__ */ o(
58
60
  "button",
59
61
  {
60
62
  type: "button",
@@ -62,7 +64,7 @@ function te({ profile: d }) {
62
64
  onClick: () => l.mutate(),
63
65
  className: "inline-flex h-7 items-center gap-1.5 rounded-md border border-amber-300 px-2.5 text-[11.5px] font-medium text-amber-800 transition-colors hover:bg-amber-50 disabled:opacity-50 dark:border-amber-500/40 dark:text-amber-300 dark:hover:bg-amber-500/10",
64
66
  children: [
65
- /* @__PURE__ */ e(S, { className: I("h-3 w-3", l.isPending && "animate-spin") }),
67
+ /* @__PURE__ */ e(P, { className: I("h-3 w-3", l.isPending && "animate-spin") }),
66
68
  l.isPending ? "Sending…" : "Reload their tabs"
67
69
  ]
68
70
  }
@@ -75,17 +77,17 @@ function te({ profile: d }) {
75
77
  }
76
78
  function D({
77
79
  excludeId: d,
78
- value: m,
80
+ value: u,
79
81
  label: p,
80
82
  onPick: t
81
83
  }) {
82
- const h = k(), [i, l] = c(""), { data: a = [] } = M({
84
+ const h = y(), [i, l] = m(""), { data: n = [] } = M({
83
85
  queryKey: ["nvr-offboard-user-search", i],
84
- queryFn: () => h.request($("/users", { search: i, limit: 8 })).then((o) => o.data),
86
+ queryFn: () => h.request($("/users", { search: i, limit: 8 })).then((s) => s.data),
85
87
  enabled: i.length > 1
86
88
  });
87
- return m ? /* @__PURE__ */ s("span", { className: "inline-flex items-center gap-1.5 rounded-full bg-nvr-cyan/10 px-2.5 py-1 text-[12px] font-medium text-nvr-navy dark:text-nvr-cyan", children: [
88
- m.name,
89
+ return u ? /* @__PURE__ */ o("span", { className: "inline-flex items-center gap-1.5 rounded-full bg-nvr-cyan/10 px-2.5 py-1 text-[12px] font-medium text-nvr-navy dark:text-nvr-cyan", children: [
90
+ u.name,
89
91
  /* @__PURE__ */ e(
90
92
  "button",
91
93
  {
@@ -96,32 +98,32 @@ function D({
96
98
  children: "✕"
97
99
  }
98
100
  )
99
- ] }) : /* @__PURE__ */ s("div", { className: "relative", children: [
101
+ ] }) : /* @__PURE__ */ o("div", { className: "relative", children: [
100
102
  /* @__PURE__ */ e(
101
103
  "input",
102
104
  {
103
105
  value: i,
104
- onChange: (o) => l(o.target.value),
106
+ onChange: (s) => l(s.target.value),
105
107
  placeholder: p,
106
108
  className: "h-8 w-[260px] rounded-md border border-slate-200 bg-white px-2.5 text-[12.5px] dark:border-border dark:bg-background"
107
109
  }
108
110
  ),
109
- i.length > 1 && a.length > 0 && /* @__PURE__ */ e("div", { className: "absolute z-10 mt-1 w-[260px] rounded-md border border-slate-200 bg-white shadow-lg dark:border-border dark:bg-card", children: a.filter((o) => o.id.toUpperCase() !== d.toUpperCase()).map((o) => {
110
- const u = `${o.first_name ?? ""} ${o.last_name ?? ""}`.trim() || o.email;
111
- return /* @__PURE__ */ s(
111
+ i.length > 1 && n.length > 0 && /* @__PURE__ */ e("div", { className: "absolute z-10 mt-1 w-[260px] rounded-md border border-slate-200 bg-white shadow-lg dark:border-border dark:bg-card", children: n.filter((s) => s.id.toUpperCase() !== d.toUpperCase()).map((s) => {
112
+ const c = `${s.first_name ?? ""} ${s.last_name ?? ""}`.trim() || s.email;
113
+ return /* @__PURE__ */ o(
112
114
  "button",
113
115
  {
114
116
  type: "button",
115
117
  onClick: () => {
116
- t({ id: o.id, name: u }), l("");
118
+ t({ id: s.id, name: c }), l("");
117
119
  },
118
120
  className: "block w-full px-2.5 py-1.5 text-left text-[12.5px] text-slate-700 hover:bg-muted dark:text-foreground",
119
121
  children: [
120
- u,
121
- /* @__PURE__ */ e("span", { className: "ml-1.5 text-[11px] text-slate-400", children: o.email })
122
+ c,
123
+ /* @__PURE__ */ e("span", { className: "ml-1.5 text-[11px] text-slate-400", children: s.email })
122
124
  ]
123
125
  },
124
- o.id
126
+ s.id
125
127
  );
126
128
  }) })
127
129
  ] });
@@ -146,18 +148,18 @@ const q = {
146
148
  field_watches: "notification_subscriptions"
147
149
  };
148
150
  function re({ profile: d }) {
149
- const m = k(), p = j(d.id), [t, h] = c(null), [i, l] = c({}), [a, o] = c(!0), [u, x] = c(null), { data: n, refetch: N } = M({
151
+ const u = y(), p = j(d.id), [t, h] = m(null), [i, l] = m({}), [n, s] = m(!0), [c, x] = m(null), { data: a, refetch: k } = M({
150
152
  queryKey: ["nvr-offboarding", d.id],
151
- queryFn: () => m.request($(`/offboarding/${d.id}`)).then((r) => r.data)
152
- }), y = f({
153
- mutationFn: () => m.request(
154
- w(`/offboarding/${d.id}/run`, { successor: t == null ? void 0 : t.id, include: i, suspend: a })
153
+ queryFn: () => u.request($(`/offboarding/${d.id}`)).then((r) => r.data)
154
+ }), N = f({
155
+ mutationFn: () => u.request(
156
+ v(`/offboarding/${d.id}/run`, { successor: t == null ? void 0 : t.id, include: i, suspend: n })
155
157
  ).then((r) => r.data),
156
158
  onSuccess: (r) => {
157
- x(r), g.success("Offboarding complete"), N(), p();
159
+ x(r), g.success("Offboarding complete"), k(), p();
158
160
  },
159
- onError: (r) => g.error(v(r, "Offboarding failed"))
160
- }), L = Object.values((n == null ? void 0 : n.holdings) ?? {}).reduce((r, b) => r + b, 0), [O, A] = c("");
161
+ onError: (r) => g.error(w(r, "Offboarding failed"))
162
+ }), L = Object.values((a == null ? void 0 : a.holdings) ?? {}).reduce((r, b) => r + b, 0), [O, A] = m("");
161
163
  return /* @__PURE__ */ e(
162
164
  C,
163
165
  {
@@ -166,16 +168,16 @@ function re({ profile: d }) {
166
168
  hint: "Hand everything they hold to a successor in one pass",
167
169
  tone: "danger",
168
170
  testId: "offboarding",
169
- children: n ? /* @__PURE__ */ s("div", { className: "space-y-3", children: [
170
- /* @__PURE__ */ e("div", { className: "grid gap-x-6 gap-y-1 sm:grid-cols-2", children: Object.entries(n.holdings).map(([r, b]) => {
171
+ children: a ? /* @__PURE__ */ o("div", { className: "space-y-3", children: [
172
+ /* @__PURE__ */ e("div", { className: "grid gap-x-6 gap-y-1 sm:grid-cols-2", children: Object.entries(a.holdings).map(([r, b]) => {
171
173
  const _ = H[r], F = I(
172
174
  "flex items-center gap-2 text-[12.5px]",
173
175
  b === 0 ? "text-slate-300 dark:text-slate-600" : "text-slate-700 dark:text-slate-200"
174
- ), P = /* @__PURE__ */ s(E, { children: [
176
+ ), R = /* @__PURE__ */ o(E, { children: [
175
177
  /* @__PURE__ */ e("span", { className: "flex-1", children: q[r] ?? r }),
176
178
  /* @__PURE__ */ e("span", { className: "font-semibold tabular-nums", children: b })
177
179
  ] });
178
- return _ ? /* @__PURE__ */ s("label", { className: F, children: [
180
+ return _ ? /* @__PURE__ */ o("label", { className: F, children: [
179
181
  /* @__PURE__ */ e(
180
182
  "input",
181
183
  {
@@ -186,13 +188,13 @@ function re({ profile: d }) {
186
188
  className: "h-3.5 w-3.5"
187
189
  }
188
190
  ),
189
- P
190
- ] }, r) : /* @__PURE__ */ s("div", { className: F, children: [
191
+ R
192
+ ] }, r) : /* @__PURE__ */ o("div", { className: F, children: [
191
193
  /* @__PURE__ */ e("span", { className: "w-3.5" }),
192
- P
194
+ R
193
195
  ] }, r);
194
196
  }) }),
195
- L === 0 ? /* @__PURE__ */ e(R, { children: "Nothing to hand over — this account holds no work." }) : /* @__PURE__ */ s("div", { className: "flex flex-wrap items-center gap-2.5", children: [
197
+ L === 0 ? /* @__PURE__ */ e(S, { children: "Nothing to hand over — this account holds no work." }) : /* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-2.5", children: [
196
198
  /* @__PURE__ */ e(
197
199
  D,
198
200
  {
@@ -202,13 +204,13 @@ function re({ profile: d }) {
202
204
  onPick: h
203
205
  }
204
206
  ),
205
- /* @__PURE__ */ s("label", { className: "flex items-center gap-1.5 text-[12px] text-slate-600 dark:text-slate-300", children: [
207
+ /* @__PURE__ */ o("label", { className: "flex items-center gap-1.5 text-[12px] text-slate-600 dark:text-slate-300", children: [
206
208
  /* @__PURE__ */ e(
207
209
  "input",
208
210
  {
209
211
  type: "checkbox",
210
- checked: a,
211
- onChange: (r) => o(r.target.checked),
212
+ checked: n,
213
+ onChange: (r) => s(r.target.checked),
212
214
  className: "h-3.5 w-3.5"
213
215
  }
214
216
  ),
@@ -229,35 +231,35 @@ function re({ profile: d }) {
229
231
  "button",
230
232
  {
231
233
  type: "button",
232
- disabled: !t || O !== "OFFBOARD" || y.isPending,
233
- onClick: () => y.mutate(),
234
+ disabled: !t || O !== "OFFBOARD" || N.isPending,
235
+ onClick: () => N.mutate(),
234
236
  className: "h-8 rounded-md bg-amber-500 px-4 text-[12.5px] font-semibold text-white hover:bg-amber-600 disabled:opacity-50",
235
- children: y.isPending ? "Reassigning…" : "Run offboarding"
237
+ children: N.isPending ? "Reassigning…" : "Run offboarding"
236
238
  }
237
239
  )
238
240
  ] }),
239
- u && /* @__PURE__ */ s("p", { className: "rounded-md bg-emerald-50 px-3 py-2 text-[12px] text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-400", children: [
241
+ c && /* @__PURE__ */ o("p", { className: "rounded-md bg-emerald-50 px-3 py-2 text-[12px] text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-400", children: [
240
242
  "Done:",
241
243
  " ",
242
- Object.entries(u).map(([r, b]) => `${(q[r] ?? r).toLowerCase()} ${b}`).join(" · ")
244
+ Object.entries(c).map(([r, b]) => `${(q[r] ?? r).toLowerCase()} ${b}`).join(" · ")
243
245
  ] })
244
- ] }) : /* @__PURE__ */ e(R, { children: "Loading what they hold…" })
246
+ ] }) : /* @__PURE__ */ e(S, { children: "Loading what they hold…" })
245
247
  }
246
248
  );
247
249
  }
248
- function ae({ profile: d }) {
249
- const m = k(), p = j(d.id), [t, h] = c(null), [i, l] = c(null), [a, o] = c(""), u = f({
250
- mutationFn: () => m.request(
251
- w(`/offboarding/${d.id}/merge`, { into: t == null ? void 0 : t.id, dry_run: !0 })
252
- ).then((n) => n.data),
253
- onSuccess: (n) => l(n.references),
254
- onError: (n) => g.error(v(n, "Preview failed"))
250
+ function ne({ profile: d }) {
251
+ const u = y(), p = j(d.id), [t, h] = m(null), [i, l] = m(null), [n, s] = m(""), c = f({
252
+ mutationFn: () => u.request(
253
+ v(`/offboarding/${d.id}/merge`, { into: t == null ? void 0 : t.id, dry_run: !0 })
254
+ ).then((a) => a.data),
255
+ onSuccess: (a) => l(a.references),
256
+ onError: (a) => g.error(w(a, "Preview failed"))
255
257
  }), x = f({
256
- mutationFn: () => m.request(w(`/offboarding/${d.id}/merge`, { into: t == null ? void 0 : t.id })),
258
+ mutationFn: () => u.request(v(`/offboarding/${d.id}/merge`, { into: t == null ? void 0 : t.id })),
257
259
  onSuccess: () => {
258
- g.success("Accounts merged — the duplicate is suspended"), l(null), o(""), p();
260
+ g.success("Accounts merged — the duplicate is suspended"), l(null), s(""), p();
259
261
  },
260
- onError: (n) => g.error(v(n, "Merge failed"))
262
+ onError: (a) => g.error(w(a, "Merge failed"))
261
263
  });
262
264
  return /* @__PURE__ */ e(
263
265
  C,
@@ -267,16 +269,16 @@ function ae({ profile: d }) {
267
269
  hint: "For duplicate or legacy twins: every reference moves to the survivor, then this account is suspended",
268
270
  tone: "danger",
269
271
  testId: "merge",
270
- children: /* @__PURE__ */ s("div", { className: "space-y-3", children: [
271
- /* @__PURE__ */ s("div", { className: "flex flex-wrap items-center gap-2.5", children: [
272
+ children: /* @__PURE__ */ o("div", { className: "space-y-3", children: [
273
+ /* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-2.5", children: [
272
274
  /* @__PURE__ */ e(
273
275
  D,
274
276
  {
275
277
  excludeId: d.id,
276
278
  value: t,
277
279
  label: "Survivor account (keeps everything)…",
278
- onPick: (n) => {
279
- h(n), l(null);
280
+ onPick: (a) => {
281
+ h(a), l(null);
280
282
  }
281
283
  }
282
284
  ),
@@ -284,31 +286,31 @@ function ae({ profile: d }) {
284
286
  "button",
285
287
  {
286
288
  type: "button",
287
- disabled: !t || u.isPending,
288
- onClick: () => u.mutate(),
289
+ disabled: !t || c.isPending,
290
+ onClick: () => c.mutate(),
289
291
  className: "h-8 rounded-md border border-slate-200 px-3 text-[12.5px] font-medium text-slate-600 hover:bg-slate-50 disabled:opacity-50 dark:border-border dark:text-slate-300 dark:hover:bg-muted",
290
- children: u.isPending ? "Scanning…" : "Preview references"
292
+ children: c.isPending ? "Scanning…" : "Preview references"
291
293
  }
292
294
  )
293
295
  ] }),
294
- i && /* @__PURE__ */ s(E, { children: [
295
- /* @__PURE__ */ e("div", { className: "max-h-[220px] overflow-y-auto rounded-md border border-slate-100 dark:border-border/60", children: Object.keys(i).length === 0 ? /* @__PURE__ */ e("p", { className: "px-3 py-2 text-[12px] text-slate-400", children: "Nothing references this account." }) : Object.entries(i).map(([n, N]) => /* @__PURE__ */ s(
296
+ i && /* @__PURE__ */ o(E, { children: [
297
+ /* @__PURE__ */ e("div", { className: "max-h-[220px] overflow-y-auto rounded-md border border-slate-100 dark:border-border/60", children: Object.keys(i).length === 0 ? /* @__PURE__ */ e("p", { className: "px-3 py-2 text-[12px] text-slate-400", children: "Nothing references this account." }) : Object.entries(i).map(([a, k]) => /* @__PURE__ */ o(
296
298
  "div",
297
299
  {
298
300
  className: "flex items-center justify-between border-b border-slate-50 px-3 py-1 text-[12px] last:border-0 dark:border-border/40",
299
301
  children: [
300
- /* @__PURE__ */ e("span", { className: "font-mono text-slate-600 dark:text-slate-300", children: n }),
301
- /* @__PURE__ */ e("span", { className: "font-semibold tabular-nums text-slate-700 dark:text-slate-200", children: N })
302
+ /* @__PURE__ */ e("span", { className: "font-mono text-slate-600 dark:text-slate-300", children: a }),
303
+ /* @__PURE__ */ e("span", { className: "font-semibold tabular-nums text-slate-700 dark:text-slate-200", children: k })
302
304
  ]
303
305
  },
304
- n
306
+ a
305
307
  )) }),
306
- /* @__PURE__ */ s("div", { className: "flex flex-wrap items-center gap-2", children: [
308
+ /* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-2", children: [
307
309
  /* @__PURE__ */ e(
308
310
  "input",
309
311
  {
310
- value: a,
311
- onChange: (n) => o(n.target.value),
312
+ value: n,
313
+ onChange: (a) => s(a.target.value),
312
314
  placeholder: "Type MERGE to confirm",
313
315
  "aria-label": "Type MERGE to confirm",
314
316
  className: "h-8 w-[180px] rounded-md border border-amber-300 bg-white px-2.5 text-[12.5px] dark:border-amber-500/40 dark:bg-background"
@@ -318,7 +320,7 @@ function ae({ profile: d }) {
318
320
  "button",
319
321
  {
320
322
  type: "button",
321
- disabled: a !== "MERGE" || x.isPending,
323
+ disabled: n !== "MERGE" || x.isPending,
322
324
  onClick: () => x.mutate(),
323
325
  className: "h-8 rounded-md bg-amber-500 px-4 text-[12.5px] font-semibold text-white hover:bg-amber-600 disabled:opacity-50",
324
326
  children: x.isPending ? "Merging…" : `Merge into ${(t == null ? void 0 : t.name) ?? ""}`
@@ -332,7 +334,7 @@ function ae({ profile: d }) {
332
334
  }
333
335
  export {
334
336
  te as ForceReloadCard,
335
- ae as MergeCard,
337
+ ne as MergeCard,
336
338
  re as OffboardingCard,
337
339
  D as UserPicker
338
340
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",