@nivaro/react 0.3.88 → 0.3.90

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.
@@ -0,0 +1,141 @@
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
22
+ }) {
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(
35
+ () => [
36
+ { value: "", label: "Pick a state" },
37
+ ...N.filter((e) => String(e.id).toUpperCase() !== String(y ?? "").toUpperCase()).map((e) => ({ value: String(e.id), label: e.label }))
38
+ ],
39
+ [N, y]
40
+ ), r = L({
41
+ mutationFn: () => f.request(
42
+ K(`/pipelines/instance/${m}/${encodeURIComponent(String(d))}/move-state`, {
43
+ to_state: u,
44
+ reason: l.trim()
45
+ })
46
+ ),
47
+ onSuccess: (e) => {
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();
52
+ },
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(
56
+ "div",
57
+ {
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]",
59
+ "data-move-to-state-form": !0,
60
+ children: [
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." })
64
+ ] }),
65
+ /* @__PURE__ */ o("div", { className: "grid gap-2 sm:grid-cols-[minmax(0,220px)_1fr]", children: [
66
+ /* @__PURE__ */ s(
67
+ V,
68
+ {
69
+ value: u,
70
+ onChange: g,
71
+ options: q,
72
+ ariaLabel: "New state",
73
+ disabled: r.isPending || !n && b
74
+ }
75
+ ),
76
+ /* @__PURE__ */ s(
77
+ G,
78
+ {
79
+ value: l,
80
+ onChange: (e) => v(e.target.value),
81
+ placeholder: "Why? Saved in the history.",
82
+ rows: 2,
83
+ maxLength: 500,
84
+ disabled: r.isPending,
85
+ className: "min-h-[38px] text-[12px]",
86
+ "aria-label": "Reason"
87
+ }
88
+ )
89
+ ] }),
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: [
92
+ "A few more words, please (",
93
+ $,
94
+ " characters or more)."
95
+ ] }),
96
+ /* @__PURE__ */ s(
97
+ C,
98
+ {
99
+ size: "sm",
100
+ variant: "ghost",
101
+ className: "h-7 text-[12px]",
102
+ onClick: () => c ? p == null ? void 0 : p() : i(!1),
103
+ disabled: r.isPending,
104
+ children: "Cancel"
105
+ }
106
+ ),
107
+ /* @__PURE__ */ o(
108
+ C,
109
+ {
110
+ size: "sm",
111
+ className: "h-7 gap-1.5 bg-nvr-cyan text-[12px] text-white hover:bg-nvr-cyan/90",
112
+ onClick: () => r.mutate(),
113
+ disabled: !A,
114
+ "data-move-to-state-submit": !0,
115
+ children: [
116
+ r.isPending && /* @__PURE__ */ s(T, { className: "h-3 w-3 animate-spin" }),
117
+ "Move"
118
+ ]
119
+ }
120
+ )
121
+ ] })
122
+ ]
123
+ }
124
+ ) : /* @__PURE__ */ o(
125
+ "button",
126
+ {
127
+ type: "button",
128
+ className: "flex items-center gap-1.5 text-[12px] text-slate-400 transition-colors hover:text-slate-600 dark:hover:text-slate-300",
129
+ onClick: () => i(!0),
130
+ "data-move-to-state-open": !0,
131
+ children: [
132
+ /* @__PURE__ */ s(O, { className: "h-3.5 w-3.5" }),
133
+ "Move to state…"
134
+ ]
135
+ }
136
+ );
137
+ }
138
+ export {
139
+ $ as MOVE_REASON_MIN,
140
+ re as MoveToStatePanel
141
+ };