@nivaro/react 0.3.89 → 0.3.91

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,105 +1,119 @@
1
- import { jsxs as a, jsx as o } from "react/jsx-runtime";
2
- import { useMutation as y } from "@tanstack/react-query";
3
- import { MoveRight as C, Loader2 as w } from "lucide-react";
4
- import { useState as l, useMemo as S } from "react";
5
- import { toast as P } from "sonner";
6
- import { useNivaroClient as R } from "../../context.js";
7
- import { post as $ } from "../../lib/commands.js";
8
- import { toastError as A } from "../../lib/error-toast.js";
9
- import { Button as h } from "../ui/button.js";
10
- import { SimpleSelect as E } from "../ui/SimpleSelect.js";
11
- import { Textarea as O } from "../ui/textarea.js";
12
- const x = 5;
13
- function V({
14
- collection: g,
15
- item: v,
16
- states: m,
17
- currentStateId: c,
18
- onMoved: b
1
+ import { jsxs as o, jsx as s } from "react/jsx-runtime";
2
+ import { useQuery as F, useMutation as L } from "@tanstack/react-query";
3
+ import { MoveRight as O, Loader2 as T } from "lucide-react";
4
+ import { useState as h, useEffect as U, useMemo as j } from "react";
5
+ import { toast as z } from "sonner";
6
+ import { useNivaroClient as W } from "../../context.js";
7
+ import { get as B, post as K } from "../../lib/commands.js";
8
+ import { toastError as Q } from "../../lib/error-toast.js";
9
+ import { Button as C } from "../ui/button.js";
10
+ import { SimpleSelect as V } from "../ui/SimpleSelect.js";
11
+ import { Textarea as G } from "../ui/textarea.js";
12
+ const $ = 5;
13
+ function re({
14
+ collection: m,
15
+ item: d,
16
+ states: n,
17
+ currentStateId: R,
18
+ onMoved: E,
19
+ openSignal: x = 0,
20
+ standalone: c = !1,
21
+ onCancel: p
19
22
  }) {
20
- const f = R(), [N, n] = l(!1), [i, d] = l(""), [r, p] = l(""), k = S(
23
+ var M, w, S, P;
24
+ const f = W(), [I, i] = h(c), [u, g] = h(""), [l, v] = h("");
25
+ U(() => {
26
+ x > 0 && i(!0);
27
+ }, [x]);
28
+ const { data: t, isLoading: b } = F({
29
+ queryKey: ["move-state-instance", m, String(d)],
30
+ queryFn: () => f.request(
31
+ B(`/pipelines/instance/${m}/${encodeURIComponent(String(d))}`)
32
+ ),
33
+ enabled: !n
34
+ }), N = n ?? ((M = t == null ? void 0 : t.data) == null ? void 0 : M.states) ?? [], y = n ? R ?? null : ((S = (w = t == null ? void 0 : t.data) == null ? void 0 : w.instance) == null ? void 0 : S.current_state) ?? null, _ = !n && !b && !((P = t == null ? void 0 : t.data) != null && P.instance), q = j(
21
35
  () => [
22
36
  { value: "", label: "Pick a state" },
23
- ...m.filter((e) => String(e.id).toUpperCase() !== String(c ?? "").toUpperCase()).map((e) => ({ value: String(e.id), label: e.label }))
37
+ ...N.filter((e) => String(e.id).toUpperCase() !== String(y ?? "").toUpperCase()).map((e) => ({ value: String(e.id), label: e.label }))
24
38
  ],
25
- [m, c]
26
- ), s = y({
39
+ [N, y]
40
+ ), r = L({
27
41
  mutationFn: () => f.request(
28
- $(`/pipelines/instance/${g}/${encodeURIComponent(String(v))}/move-state`, {
29
- to_state: i,
30
- reason: r.trim()
42
+ K(`/pipelines/instance/${m}/${encodeURIComponent(String(d))}/move-state`, {
43
+ to_state: u,
44
+ reason: l.trim()
31
45
  })
32
46
  ),
33
47
  onSuccess: (e) => {
34
- const t = e == null ? void 0 : e.data;
35
- P.success(
36
- t != null && t.ended ? `Moved to ${t.to.label}, then an automatic rule took it to ${t.ended.label}` : `Moved to ${(t == null ? void 0 : t.to.label) ?? "the new state"}`
37
- ), n(!1), d(""), p(""), b();
48
+ const a = e == null ? void 0 : e.data;
49
+ z.success(
50
+ a != null && a.ended ? `Moved to ${a.to.label}, then an automatic rule took it to ${a.ended.label}` : `Moved to ${(a == null ? void 0 : a.to.label) ?? "the new state"}`
51
+ ), c || i(!1), g(""), v(""), E();
38
52
  },
39
- onError: (e) => A(e, "Could not move it")
40
- }), u = r.trim().length >= x, M = !!i && u && !s.isPending;
41
- return N ? /* @__PURE__ */ a(
53
+ onError: (e) => Q(e, "Could not move it")
54
+ }), k = l.trim().length >= $, A = !!u && k && !r.isPending;
55
+ return I ? _ ? /* @__PURE__ */ s("p", { className: "text-[12px] text-slate-500", "data-move-to-state-none": !0, children: "This record has no pipeline to move." }) : /* @__PURE__ */ o(
42
56
  "div",
43
57
  {
44
58
  className: "space-y-3 rounded-lg border border-amber-200 bg-amber-50/60 p-3 dark:border-amber-500/25 dark:bg-amber-500/[0.06]",
45
59
  "data-move-to-state-form": !0,
46
60
  children: [
47
- /* @__PURE__ */ a("div", { className: "space-y-1", children: [
48
- /* @__PURE__ */ o("p", { className: "text-[12px] font-medium text-slate-800 dark:text-slate-200", children: "Move to state" }),
49
- /* @__PURE__ */ o("p", { className: "text-[11px] leading-relaxed text-slate-600 dark:text-slate-400", children: "Administrators only. Puts this record straight into the state you pick. No transition steps run: no Fusion or MWF pushes, emails or flows. Automatic rules are checked again afterwards, so it may move on by itself." })
61
+ /* @__PURE__ */ o("div", { className: "space-y-1", children: [
62
+ /* @__PURE__ */ s("p", { className: "text-[12px] font-medium text-slate-800 dark:text-slate-200", children: "Move to state" }),
63
+ /* @__PURE__ */ s("p", { className: "text-[11px] leading-relaxed text-slate-600 dark:text-slate-400", children: "Administrators only. Puts this record straight into the state you pick. No transition steps run: no Fusion or MWF pushes, emails or flows. Automatic rules are checked again afterwards, so it may move on by itself." })
50
64
  ] }),
51
- /* @__PURE__ */ a("div", { className: "grid gap-2 sm:grid-cols-[minmax(0,220px)_1fr]", children: [
52
- /* @__PURE__ */ o(
53
- E,
65
+ /* @__PURE__ */ o("div", { className: "grid gap-2 sm:grid-cols-[minmax(0,220px)_1fr]", children: [
66
+ /* @__PURE__ */ s(
67
+ V,
54
68
  {
55
- value: i,
56
- onChange: d,
57
- options: k,
69
+ value: u,
70
+ onChange: g,
71
+ options: q,
58
72
  ariaLabel: "New state",
59
- disabled: s.isPending
73
+ disabled: r.isPending || !n && b
60
74
  }
61
75
  ),
62
- /* @__PURE__ */ o(
63
- O,
76
+ /* @__PURE__ */ s(
77
+ G,
64
78
  {
65
- value: r,
66
- onChange: (e) => p(e.target.value),
79
+ value: l,
80
+ onChange: (e) => v(e.target.value),
67
81
  placeholder: "Why? Saved in the history.",
68
82
  rows: 2,
69
83
  maxLength: 500,
70
- disabled: s.isPending,
84
+ disabled: r.isPending,
71
85
  className: "min-h-[38px] text-[12px]",
72
86
  "aria-label": "Reason"
73
87
  }
74
88
  )
75
89
  ] }),
76
- /* @__PURE__ */ a("div", { className: "flex items-center justify-end gap-2", children: [
77
- !u && r.length > 0 && /* @__PURE__ */ a("span", { className: "mr-auto text-[11px] text-slate-500", children: [
90
+ /* @__PURE__ */ o("div", { className: "flex items-center justify-end gap-2", children: [
91
+ !k && l.length > 0 && /* @__PURE__ */ o("span", { className: "mr-auto text-[11px] text-slate-500", children: [
78
92
  "A few more words, please (",
79
- x,
93
+ $,
80
94
  " characters or more)."
81
95
  ] }),
82
- /* @__PURE__ */ o(
83
- h,
96
+ /* @__PURE__ */ s(
97
+ C,
84
98
  {
85
99
  size: "sm",
86
100
  variant: "ghost",
87
101
  className: "h-7 text-[12px]",
88
- onClick: () => n(!1),
89
- disabled: s.isPending,
102
+ onClick: () => c ? p == null ? void 0 : p() : i(!1),
103
+ disabled: r.isPending,
90
104
  children: "Cancel"
91
105
  }
92
106
  ),
93
- /* @__PURE__ */ a(
94
- h,
107
+ /* @__PURE__ */ o(
108
+ C,
95
109
  {
96
110
  size: "sm",
97
111
  className: "h-7 gap-1.5 bg-nvr-cyan text-[12px] text-white hover:bg-nvr-cyan/90",
98
- onClick: () => s.mutate(),
99
- disabled: !M,
112
+ onClick: () => r.mutate(),
113
+ disabled: !A,
100
114
  "data-move-to-state-submit": !0,
101
115
  children: [
102
- s.isPending && /* @__PURE__ */ o(w, { className: "h-3 w-3 animate-spin" }),
116
+ r.isPending && /* @__PURE__ */ s(T, { className: "h-3 w-3 animate-spin" }),
103
117
  "Move"
104
118
  ]
105
119
  }
@@ -107,21 +121,21 @@ function V({
107
121
  ] })
108
122
  ]
109
123
  }
110
- ) : /* @__PURE__ */ a(
124
+ ) : /* @__PURE__ */ o(
111
125
  "button",
112
126
  {
113
127
  type: "button",
114
128
  className: "flex items-center gap-1.5 text-[12px] text-slate-400 transition-colors hover:text-slate-600 dark:hover:text-slate-300",
115
- onClick: () => n(!0),
129
+ onClick: () => i(!0),
116
130
  "data-move-to-state-open": !0,
117
131
  children: [
118
- /* @__PURE__ */ o(C, { className: "h-3.5 w-3.5" }),
132
+ /* @__PURE__ */ s(O, { className: "h-3.5 w-3.5" }),
119
133
  "Move to state…"
120
134
  ]
121
135
  }
122
136
  );
123
137
  }
124
138
  export {
125
- x as MOVE_REASON_MIN,
126
- V as MoveToStatePanel
139
+ $ as MOVE_REASON_MIN,
140
+ re as MoveToStatePanel
127
141
  };