@tesouro/embedded-components-react 0.9.12 → 0.9.16

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.
@@ -74,6 +74,7 @@ function d({ labels: d, componentLabels: f, headingComponent: p = "h3", showHead
74
74
  onConfirm: g.deleteDialog.onConfirm,
75
75
  onCancel: g.deleteDialog.onCancel,
76
76
  isDeleting: g.deleteDialog.isDeleting,
77
+ confirmDisabled: g.deleteDialog.confirmDisabled,
77
78
  labels: f?.deleteDialog,
78
79
  testIds: {
79
80
  root: r.deleteDialog,
@@ -3,56 +3,57 @@
3
3
  "use client";
4
4
  "use client";
5
5
  import { toast as e } from "../../../../../../../packages/shared-ui-shadcn/dist/index.js";
6
- import { useEmbedApi as t } from "../../../../data-access/dist/lib/EmbedApiContext.js";
6
+ import { OrganizationStatus as t, isOrganizationOnItsWay as n } from "../../../../data-access/dist/lib/organizationStatus.js";
7
+ import { useEmbedApi as r } from "../../../../data-access/dist/lib/EmbedApiContext.js";
7
8
  import "../../../../data-access/dist/index.js";
8
9
  import "../../../../ui/dist/index.js";
9
- import { computeUncoveredAmountRanges as n } from "../../../util/dist/lib/amountCoverage.js";
10
- import { nextPolicyPriority as r } from "../../../util/dist/lib/policyPriority.js";
11
- import { buildApprovalPolicyScript as i, parseApprovalPolicyScript as a } from "../../../util/dist/lib/policyScript.js";
12
- import { buildApprovalPolicyTrigger as o, parseApprovalPolicyTrigger as s } from "../../../util/dist/lib/policyTrigger.js";
13
- import { validatePolicyDraft as c } from "../../../util/dist/lib/validatePolicyDraft.js";
14
- import { buildPolicySentence as l, buildPolicyTitle as u, buildUnlistedPoliciesHeading as ee, gapId as te, lockUnavailableApprovers as ne, toAmountConditionErrors as d, toAmountConditionValue as f, toApproverErrors as re, toApproverGroupRefs as ie, toApproverSteps as ae, toGapRanges as p } from "./policyViewModel.js";
15
- import { useApproverOptions as oe } from "./useApproverOptions.js";
16
- import { approvalPolicyTestIds as m } from "./testIds.js";
17
- import { ApprovalPolicyObjectType as se } from "../../../data-access/dist/lib/queryKeys.js";
18
- import { useDeleteApprovalPoliciesIdMutation as ce, useGetApprovalPoliciesQuery as le, usePatchApprovalPoliciesIdMutation as ue, usePostApprovalPoliciesMutation as h } from "../../../data-access/dist/lib/approvalPoliciesApi.js";
10
+ import { computeUncoveredAmountRanges as i } from "../../../util/dist/lib/amountCoverage.js";
11
+ import { nextPolicyPriority as a } from "../../../util/dist/lib/policyPriority.js";
12
+ import { buildApprovalPolicyScript as ee, parseApprovalPolicyScript as o } from "../../../util/dist/lib/policyScript.js";
13
+ import { buildApprovalPolicyTrigger as te, parseApprovalPolicyTrigger as s } from "../../../util/dist/lib/policyTrigger.js";
14
+ import { validatePolicyDraft as ne } from "../../../util/dist/lib/validatePolicyDraft.js";
15
+ import { buildPolicySentence as re, buildPolicyTitle as c, buildUnlistedPoliciesHeading as ie, gapId as ae, lockUnavailableApprovers as oe, toAmountConditionErrors as l, toAmountConditionValue as u, toApproverErrors as se, toApproverGroupRefs as ce, toApproverSteps as le, toGapRanges as d } from "./policyViewModel.js";
16
+ import { useApproverOptions as f } from "./useApproverOptions.js";
17
+ import { approvalPolicyTestIds as p } from "./testIds.js";
18
+ import { ApprovalPolicyObjectType as ue } from "../../../data-access/dist/lib/queryKeys.js";
19
+ import { useDeleteApprovalPoliciesIdMutation as de, useGetApprovalPoliciesQuery as fe, usePatchApprovalPoliciesIdMutation as pe, usePostApprovalPoliciesMutation as me } from "../../../data-access/dist/lib/approvalPoliciesApi.js";
19
20
  import "../../../data-access/dist/index.js";
20
- import { useCallback as g, useEffect as _, useMemo as v, useRef as y, useState as b } from "react";
21
+ import { useCallback as m, useEffect as h, useMemo as g, useRef as _, useState as v } from "react";
21
22
  //#region ../../libs/tesouro-embedded-components-react/shared/approval-policy/feature/dist/lib/useApprovalPolicyRules.js
22
- var x = "draft", de = {
23
+ var y = "draft", he = {
23
24
  lower: "",
24
25
  upper: ""
25
- }, S = {
26
+ }, b = {
26
27
  lower: !1,
27
28
  upper: !1
28
29
  };
29
- function fe(e) {
30
+ function ge(e) {
30
31
  return e.map((e) => {
31
- let t = s(e.trigger), n = a(e.script), r = t.currency === void 0 || t.currency === "USD", i = e.status === "active", o = t.hasKnownAmountBounds && r;
32
+ let t = s(e.trigger), n = o(e.script), r = t.currency === void 0 || t.currency === "USD", i = e.status === "active", a = t.hasKnownAmountBounds && r;
32
33
  return {
33
34
  id: e.id,
34
35
  priority: e.priority,
35
36
  condition: t.condition,
36
37
  groups: n.groups,
37
38
  isRepresentable: t.isSupported && t.hasWrittenGuards && n.isSupported && r && i,
38
- hasKnownCondition: o,
39
+ hasKnownCondition: a,
39
40
  isActive: i,
40
- coversNow: o && i
41
+ coversNow: a && i
41
42
  };
42
43
  });
43
44
  }
44
- function pe(e) {
45
+ function x(e) {
45
46
  return [...e].sort((e, t) => (e.condition.min ?? 0) - (t.condition.min ?? 0));
46
47
  }
47
- function C({ labels: a, componentLabels: s }) {
48
- let x = le(), C = h(), w = ue(), T = ce(), E = oe(), { organizationId: D } = t(), [O, k] = b(null), [A, j] = b(null), M = y(D);
49
- D && D !== M.current && (M.current = D, k(null), j(null));
50
- let N = y(0), P = g(() => (N.current += 1, {
48
+ function S({ labels: o, componentLabels: s }) {
49
+ let y = fe(), S = me(), C = pe(), w = de(), T = f(), { organizationId: E, organizationStatus: D } = r(), [O, k] = v(null), [A, j] = v(null), _e = n(D), M = _(E);
50
+ E && E !== M.current && (M.current = E, k(null), j(null)), D === t.None && (O || A) && (k(null), j(null));
51
+ let N = _(0), P = m(() => (N.current += 1, {
51
52
  id: `group-new-${N.current}`,
52
53
  selectedItems: []
53
- }), []), F = v(() => fe(x.data?.data ?? []), [x.data]), I = v(() => E.isResolving ? [] : pe(F.flatMap((e) => {
54
+ }), []), F = g(() => ge(y.data?.data ?? []), [y.data]), I = g(() => T.isResolving ? [] : x(F.flatMap((e) => {
54
55
  if (!e.isRepresentable) return [];
55
- let t = ae(e.groups, E.lookup);
56
+ let t = le(e.groups, T.lookup);
56
57
  return t === void 0 ? [] : [{
57
58
  id: e.id,
58
59
  priority: e.priority,
@@ -61,20 +62,20 @@ function C({ labels: a, componentLabels: s }) {
61
62
  }];
62
63
  })), [
63
64
  F,
64
- E.isResolving,
65
- E.lookup
66
- ]), L = O ? O.policyId ?? "draft" : null, R = !D && M.current != null || x.isResolving || E.isResolving, z = O?.policyId != null && O.policyId !== A && !R && !I.some((e) => e.id === O.policyId);
67
- _(() => {
68
- z && (k(null), e.error(a.approverUnavailable));
69
- }, [z, a.approverUnavailable]);
70
- let B = v(() => new Set(I.map((e) => e.id)), [I]), V = v(() => R ? [] : F.filter((e) => !B.has(e.id)), [
65
+ T.isResolving,
66
+ T.lookup
67
+ ]), L = O ? O.policyId ?? "draft" : null, R = _e || y.isResolving || T.isResolving, z = O?.policyId != null && O.policyId !== A && !!E && !R && !I.some((e) => e.id === O.policyId);
68
+ h(() => {
69
+ z && (k(null), e.error(o.approverUnavailable));
70
+ }, [z, o.approverUnavailable]);
71
+ let B = g(() => new Set(I.map((e) => e.id)), [I]), V = g(() => R ? [] : F.filter((e) => !B.has(e.id)), [
71
72
  R,
72
73
  F,
73
74
  B
74
- ]), H = v(() => {
75
+ ]), H = g(() => {
75
76
  if (!O) return;
76
77
  let e = (e) => e.id !== O.policyId;
77
- return c({
78
+ return ne({
78
79
  amount: O.amount,
79
80
  groups: O.steps.map((e) => ({
80
81
  id: e.id,
@@ -87,30 +88,30 @@ function C({ labels: a, componentLabels: s }) {
87
88
  O,
88
89
  I,
89
90
  V
90
- ]), U = v(() => n(F.filter((e) => e.coversNow).map((e) => e.condition)), [F]), W = v(() => F.filter((e) => e.hasKnownCondition).map((e) => e.condition), [F]), G = v(() => F.length === 0 ? [] : p(U, a, W), [
91
+ ]), U = g(() => i(F.filter((e) => e.coversNow).map((e) => e.condition)), [F]), W = g(() => F.filter((e) => e.hasKnownCondition).map((e) => e.condition), [F]), G = g(() => F.length === 0 ? [] : d(U, o, W), [
91
92
  F.length,
92
93
  U,
93
- a,
94
+ o,
94
95
  W
95
- ]), me = v(() => n(W), [W]), he = !R && F.length > 0 && me.length === 0 ? I.length === 0 ? a.addRuleFullyCoveredUnlisted : a.addRuleFullyCovered : void 0, [K, ge] = b(0), q = y(null);
96
- _(() => {
96
+ ]), ve = g(() => i(W), [W]), ye = !R && F.length > 0 && ve.length === 0 ? I.length === 0 ? o.addRuleFullyCoveredUnlisted : o.addRuleFullyCovered : void 0, [K, be] = v(0), q = _(null);
97
+ h(() => {
97
98
  K !== 0 && q.current?.scrollIntoView({
98
99
  behavior: globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth",
99
100
  block: "nearest"
100
101
  });
101
102
  }, [K]);
102
- let J = g((e) => {
103
+ let J = m((e) => {
103
104
  k({
104
105
  policyId: null,
105
106
  amount: e,
106
107
  steps: [P()],
107
- touchedAmount: S
108
- }), ge((e) => e + 1);
109
- }, [P]), _e = g(() => {
110
- J(de);
111
- }, [J]), ve = g((e) => {
112
- let t = U.find((t) => te(t) === e);
113
- t && G.find((t) => t.id === e)?.blockedReason === void 0 && J(f({
108
+ touchedAmount: b
109
+ }), be((e) => e + 1);
110
+ }, [P]), xe = m(() => {
111
+ J(he);
112
+ }, [J]), Se = m((e) => {
113
+ let t = U.find((t) => ae(t) === e);
114
+ t && G.find((t) => t.id === e)?.blockedReason === void 0 && J(u({
114
115
  type: "between",
115
116
  min: t.min,
116
117
  max: t.max
@@ -119,55 +120,56 @@ function C({ labels: a, componentLabels: s }) {
119
120
  U,
120
121
  G,
121
122
  J
122
- ]), Y = g(() => {
123
+ ]), Y = m(() => {
123
124
  k(null);
124
- }, []), X = C.isPending || w.isPending || T.isPending, Z = g(async () => {
125
+ }, []), X = S.isPending || C.isPending || w.isPending, Z = m(async () => {
125
126
  if (!O || !H || !H.isValid) return;
126
- let t = H.condition, n = ie(O.steps, E.lookup);
127
+ let t = H.condition, n = ce(O.steps, T.lookup);
127
128
  if (!n) {
128
- e.error(a.approverUnavailable);
129
+ e.error(o.approverUnavailable);
129
130
  return;
130
131
  }
131
- let s = o(t), c = i(n), l = u(t, a);
132
+ let r = te(t), i = ee(n), s = c(t, o);
132
133
  try {
133
- O.policyId === null ? await C.mutateAsync({ body: {
134
- object_type: se.Payable,
135
- name: l,
136
- trigger: s,
137
- script: c,
138
- priority: r(F.map((e) => e.priority))
139
- } }) : await w.mutateAsync({
134
+ O.policyId === null ? await S.mutateAsync({ body: {
135
+ object_type: ue.Payable,
136
+ name: s,
137
+ trigger: r,
138
+ script: i,
139
+ priority: a(F.map((e) => e.priority))
140
+ } }) : await C.mutateAsync({
140
141
  path: { approval_policy_id: O.policyId },
141
142
  body: {
142
- name: l,
143
- trigger: s,
144
- script: c
143
+ name: s,
144
+ trigger: r,
145
+ script: i
145
146
  }
146
- }), k(null), e.success(a.ruleSaved);
147
+ }), k(null), e.success(o.ruleSaved);
147
148
  } catch {
148
- e.error(a.ruleSaveFailed);
149
+ e.error(o.ruleSaveFailed);
149
150
  }
150
151
  }, [
151
152
  O,
152
153
  H,
153
- E.lookup,
154
- a,
154
+ T.lookup,
155
+ o,
155
156
  F,
156
- C,
157
- w
158
- ]), ye = g(async () => {
159
- if (A) try {
160
- await T.mutateAsync({ path: { approval_policy_id: A } }), j(null), k(null), e.success(a.ruleDeleted);
157
+ S,
158
+ C
159
+ ]), Ce = m(async () => {
160
+ if (A && E) try {
161
+ await w.mutateAsync({ path: { approval_policy_id: A } }), j(null), k(null), e.success(o.ruleDeleted);
161
162
  } catch {
162
- j(null), e.error(a.ruleDeleteFailed);
163
+ j(null), e.error(o.ruleDeleteFailed);
163
164
  }
164
165
  }, [
165
166
  A,
166
- T,
167
- a
168
- ]), be = R || X, Q = v(() => {
167
+ E,
168
+ w,
169
+ o
170
+ ]), we = R || X || !E, Q = g(() => {
169
171
  if (!O || !H || X) return;
170
- let e = d(H.amountErrors, a);
172
+ let e = l(H.amountErrors, o);
171
173
  if (e) return {
172
174
  lower: O.touchedAmount.lower ? e.lower : void 0,
173
175
  upper: O.touchedAmount.upper ? e.upper : void 0
@@ -176,18 +178,18 @@ function C({ labels: a, componentLabels: s }) {
176
178
  O,
177
179
  H,
178
180
  X,
179
- a
180
- ]), $ = v(() => {
181
+ o
182
+ ]), $ = g(() => {
181
183
  if (!H || H.isValid) return;
182
- let e = re(H.groupErrors, a), t = d(H.amountErrors, a), n = [
184
+ let e = se(H.groupErrors, o), t = l(H.amountErrors, o), n = [
183
185
  ...Object.values(e?.steps ?? {}),
184
186
  t?.lower,
185
187
  t?.upper
186
188
  ].filter((e) => !!e), r = [...new Set(n)];
187
189
  return r.length > 0 ? r : void 0;
188
- }, [H, a]);
190
+ }, [H, o]);
189
191
  return {
190
- items: v(() => {
192
+ items: g(() => {
191
193
  let e = {
192
194
  onAmountConditionChange: (e) => k((t) => t && {
193
195
  ...t,
@@ -212,46 +214,46 @@ function C({ labels: a, componentLabels: s }) {
212
214
  ...t,
213
215
  steps: t.steps.filter((t) => t.id !== e)
214
216
  })
215
- }, t = (t, n, r, i, o) => ({
217
+ }, t = (t, n, r, i, a) => ({
216
218
  id: t,
217
- title: u(n, a),
218
- sentence: l(n, a),
219
- approverSteps: r.map((e) => ne(e, {
220
- lookup: E.lookup,
221
- labels: a,
219
+ title: c(n, o),
220
+ sentence: re(n, o),
221
+ approverSteps: r.map((e) => oe(e, {
222
+ lookup: T.lookup,
223
+ labels: o,
222
224
  usedByOtherSteps: i ? new Set(r.filter((t) => t.id !== e.id).flatMap((e) => e.selectedItems.map((e) => e.id))) : void 0
223
225
  })),
224
226
  addApproverStepDisabled: r.some((e) => e.selectedItems.length === 0),
225
- approverOptions: E.options,
226
- amountCondition: f(n),
227
+ approverOptions: T.options,
228
+ amountCondition: u(n),
227
229
  amountConditionErrors: i ? Q : void 0,
228
230
  onEdit: () => {
229
231
  k({
230
232
  policyId: t,
231
- amount: f(n),
233
+ amount: u(n),
232
234
  steps: r,
233
- touchedAmount: S
235
+ touchedAmount: b
234
236
  });
235
237
  },
236
238
  onCancel: Y,
237
239
  onSave: () => void Z(),
238
- onDelete: o,
240
+ onDelete: a,
239
241
  saveDisabled: i && H ? !H.isValid : !1,
240
242
  saveDisabledReasons: i ? $ : void 0,
241
243
  labels: s?.policyCard,
242
244
  testIds: {
243
245
  amountConditionBuilder: {
244
- root: m.amountConditionBuilder,
245
- lowerInput: m.amountConditionLowerInput,
246
- upperInput: m.amountConditionUpperInput
246
+ root: p.amountConditionBuilder,
247
+ lowerInput: p.amountConditionLowerInput,
248
+ upperInput: p.amountConditionUpperInput
247
249
  },
248
250
  approverGroupsBuilder: {
249
- root: m.approverGroupsBuilder,
250
- loading: m.approverGroupsLoading,
251
- error: m.approverGroupsError,
252
- description: m.approverGroupsDescription,
253
- empty: m.approverGroupsEmpty,
254
- addStepButton: m.approverGroupsAddStep
251
+ root: p.approverGroupsBuilder,
252
+ loading: p.approverGroupsLoading,
253
+ error: p.approverGroupsError,
254
+ description: p.approverGroupsDescription,
255
+ empty: p.approverGroupsEmpty,
256
+ addStepButton: p.approverGroupsAddStep
255
257
  }
256
258
  },
257
259
  ...e
@@ -274,38 +276,39 @@ function C({ labels: a, componentLabels: s }) {
274
276
  Q,
275
277
  $,
276
278
  H,
277
- a,
279
+ o,
278
280
  s?.policyCard,
279
- E.options,
280
- E.lookup,
281
+ T.options,
282
+ T.lookup,
281
283
  Y,
282
284
  P,
283
285
  Z
284
286
  ]),
285
287
  editingId: L,
286
288
  gaps: G,
287
- unlistedPoliciesHeading: ee(V.length, a),
289
+ unlistedPoliciesHeading: ie(V.length, o),
288
290
  unlistedPoliciesBlockAmounts: V.some((e) => e.hasKnownCondition),
289
291
  unlistedPoliciesStillApply: V.some((e) => e.isActive),
290
- onAddRule: _e,
291
- addRuleDisabledReason: he,
292
- onSelectGap: ve,
293
- isBusy: be,
292
+ onAddRule: xe,
293
+ addRuleDisabledReason: ye,
294
+ onSelectGap: Se,
295
+ isBusy: we,
294
296
  isLoading: R,
295
- isError: x.isError || E.isError,
297
+ isError: y.isError || T.isError,
296
298
  onRetry: () => {
297
- x.refetch(), E.refetch();
299
+ y.refetch(), T.refetch();
298
300
  },
299
301
  deleteDialog: {
300
302
  open: A !== null,
301
- isDeleting: T.isPending,
303
+ isDeleting: w.isPending,
304
+ confirmDisabled: !E,
302
305
  onOpenChange: (e) => {
303
306
  e || j(null);
304
307
  },
305
- onConfirm: () => void ye(),
308
+ onConfirm: () => void Ce(),
306
309
  onCancel: () => j(null)
307
310
  }
308
311
  };
309
312
  }
310
313
  //#endregion
311
- export { x as DRAFT_POLICY_ID, C as useApprovalPolicyRules };
314
+ export { y as DRAFT_POLICY_ID, S as useApprovalPolicyRules };
@@ -4,16 +4,16 @@ import { useMemo as c } from "react";
4
4
  import { jsx as l, jsxs as u } from "react/jsx-runtime";
5
5
  import { Trash2 as d } from "lucide-react";
6
6
  //#region ../../libs/tesouro-embedded-components-react/shared/approval-policy/ui/dist/index18.js
7
- var f = ({ open: f, onOpenChange: p, onConfirm: m, onCancel: h, isDeleting: g, labels: _, testIds: v }) => {
8
- let y = c(() => ({
7
+ var f = ({ open: f, onOpenChange: p, onConfirm: m, onCancel: h, isDeleting: g, confirmDisabled: _, labels: v, testIds: y }) => {
8
+ let b = c(() => ({
9
9
  ...s,
10
- ..._
11
- }), [_]);
10
+ ...v
11
+ }), [v]);
12
12
  return /* @__PURE__ */ l(e, {
13
13
  open: f,
14
14
  onOpenChange: p,
15
15
  children: /* @__PURE__ */ u(t, {
16
- "data-testid": v?.root,
16
+ "data-testid": y?.root,
17
17
  className: "ttw:sm:max-w-sm",
18
18
  children: [/* @__PURE__ */ u(i, {
19
19
  className: "ttw:items-center ttw:text-center",
@@ -25,8 +25,8 @@ var f = ({ open: f, onOpenChange: p, onConfirm: m, onCancel: h, isDeleting: g, l
25
25
  "aria-hidden": "true"
26
26
  })
27
27
  }),
28
- /* @__PURE__ */ l(a, { children: y.Title }),
29
- /* @__PURE__ */ l(n, { children: y.Description })
28
+ /* @__PURE__ */ l(a, { children: b.Title }),
29
+ /* @__PURE__ */ l(n, { children: b.Description })
30
30
  ]
31
31
  }), /* @__PURE__ */ u(r, {
32
32
  className: "ttw:sm:justify-center",
@@ -36,17 +36,17 @@ var f = ({ open: f, onOpenChange: p, onConfirm: m, onCancel: h, isDeleting: g, l
36
36
  onClick: h,
37
37
  disabled: g,
38
38
  className: "ttw:flex-1",
39
- "data-testid": v?.cancelButton,
40
- children: y.Cancel
39
+ "data-testid": y?.cancelButton,
40
+ children: b.Cancel
41
41
  }), /* @__PURE__ */ u(o, {
42
42
  type: "button",
43
43
  variant: "destructive",
44
44
  onClick: m,
45
- disabled: g,
45
+ disabled: g || _,
46
46
  loading: g,
47
47
  className: "ttw:flex-1",
48
- "data-testid": v?.confirmButton,
49
- children: [/* @__PURE__ */ l(d, {}), y.Delete]
48
+ "data-testid": y?.confirmButton,
49
+ children: [/* @__PURE__ */ l(d, {}), b.Delete]
50
50
  })]
51
51
  })]
52
52
  })
@@ -1,5 +1,5 @@
1
1
  //#region ../../libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js
2
- var e = "@tesouro/embedded-components-react", t = "0.9.12", n = "6a8f7eb26d422fb576772449733b1e7c26e91e44", r = Object.freeze({
2
+ var e = "@tesouro/embedded-components-react", t = "0.9.16", n = "36bb794db8cb36d284be2cceae8a572f21b708d0", r = Object.freeze({
3
3
  library_name: e,
4
4
  library_version: t,
5
5
  library_sha: n
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tesouro/embedded-components-react",
3
- "version": "0.9.12",
3
+ "version": "0.9.16",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": [