@tesouro/embedded-components-react 0.11.101 → 0.11.104

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.
Files changed (50) hide show
  1. package/dist/index.css +21 -17
  2. package/dist/index.d.ts +10 -6
  3. package/dist/lib/CardDetailsWidget.d.ts +6 -4
  4. package/dist/lib/CreditCardsWidget.d.ts +6 -4
  5. package/dist/lib/DebitCardsWidget.d.ts +6 -4
  6. package/dist/lib/SettingsWidget.d.ts +2 -1
  7. package/dist/lib/WidgetSuite.d.ts +8 -5
  8. package/dist/libs/tesouro-embedded-components-react/card-details-widget/ui/dist/lib/CardDetailsPanel/CardDetailsPanel.js +199 -168
  9. package/dist/libs/tesouro-embedded-components-react/card-details-widget/ui/dist/lib/CardDetailsPanel/labels.js +1 -0
  10. package/dist/libs/tesouro-embedded-components-react/cards-widget/ui/dist/lib/CardsList/CardsList.js +44 -43
  11. package/dist/libs/tesouro-embedded-components-react/counterparts-widget/feature/dist/lib/CounterpartsWidget/CounterpartsWidget.js +56 -52
  12. package/dist/libs/tesouro-embedded-components-react/counterparts-widget/ui/dist/index3.js +68 -63
  13. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/feature/dist/index.js +1 -1
  14. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/feature/dist/index3.js +9 -9
  15. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/feature/dist/index4.js +2 -2
  16. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/feature/dist/index6.js +25 -284
  17. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/feature/dist/index7.js +291 -0
  18. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/ui/dist/index.js +3 -3
  19. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/ui/dist/index3.js +28 -17
  20. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/ui/dist/index5.js +21 -34
  21. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/ui/dist/index6.js +71 -78
  22. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/ui/dist/index7.js +71 -77
  23. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/ui/dist/index8.js +43 -49
  24. package/dist/libs/tesouro-embedded-components-react/expense-management-widget/feature/dist/index.js +1 -1
  25. package/dist/libs/tesouro-embedded-components-react/linked-accounts-widget/ui/dist/index2.js +8 -1
  26. package/dist/libs/tesouro-embedded-components-react/settings-widget/chart-of-accounts/ui/dist/index3.js +98 -91
  27. package/dist/libs/tesouro-embedded-components-react/settings-widget/feature/dist/lib/ExpenseSettingsTabs/ExpenseSettingsTabs.js +24 -21
  28. package/dist/libs/tesouro-embedded-components-react/settings-widget/feature/dist/lib/SettingsWidget/SettingsWidget.js +14 -8
  29. package/dist/libs/tesouro-embedded-components-react/settings-widget/help/ui/shadcn/dist/index3.js +2 -2
  30. package/dist/libs/tesouro-embedded-components-react/settings-widget/invoice-settings/feature/dist/index10.js +87 -81
  31. package/dist/libs/tesouro-embedded-components-react/settings-widget/invoice-settings/ui/dist/index3.js +63 -44
  32. package/dist/libs/tesouro-embedded-components-react/settings-widget/invoice-settings/ui/dist/index6.js +9 -6
  33. package/dist/libs/tesouro-embedded-components-react/settings-widget/team/feature/dist/index17.js +302 -276
  34. package/dist/libs/tesouro-embedded-components-react/settings-widget/team/ui/dist/index.js +10 -10
  35. package/dist/libs/tesouro-embedded-components-react/settings-widget/team/ui/dist/index12.js +36 -36
  36. package/dist/libs/tesouro-embedded-components-react/settings-widget/team/ui/dist/index17.js +27 -13
  37. package/dist/libs/tesouro-embedded-components-react/settings-widget/ui/dist/lib/SettingsWidgetUi/SettingsSectionContent.js +22 -0
  38. package/dist/libs/tesouro-embedded-components-react/settings-widget/ui/dist/lib/SettingsWidgetUi/SettingsWidgetUi.js +6 -7
  39. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/feature/dist/lib/ApprovalPoliciesSettings.js +39 -37
  40. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/ui/dist/index.js +9 -9
  41. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/ui/dist/index11.js +39 -35
  42. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/ui/dist/index16.js +59 -61
  43. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/ui/dist/index4.js +2 -2
  44. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/ui/dist/index6.js +2 -2
  45. package/dist/libs/tesouro-embedded-components-react/shared/approval-policy/ui/dist/index7.js +3 -3
  46. package/dist/libs/tesouro-embedded-components-react/shared/counterpart-management/feature/dist/lib/helpers.js +114 -103
  47. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  48. package/dist/libs/tesouro-embedded-components-react/shared/util/dist/index.js +12 -12
  49. package/dist/packages/shared-ui-shadcn/dist/index.js +18 -15
  50. package/package.json +1 -1
@@ -1,289 +1,30 @@
1
- "use client";
2
- "use client";
3
- "use client";
4
- "use client";
5
- import { toast as e } from "../../../../../../packages/shared-ui-shadcn/dist/index.js";
6
- import { isOrganizationOnItsWay as t } from "../../../../shared/data-access/dist/lib/organizationStatus.js";
7
- import { useEmbedApi as n } from "../../../../shared/data-access/dist/lib/EmbedApiContext.js";
8
- import { Scope as r } from "../../../../shared/data-access/dist/lib/scopes.js";
9
- import { useAllOrganizationRolesQuery as i } from "../../../../shared/data-access/dist/lib/role/useAllOrganizationRolesQuery.js";
10
- import "../../../../shared/data-access/dist/index.js";
11
- import { EmbeddedToaster as a } from "../../../../shared/ui/dist/lib/EmbeddedToaster.js";
12
- import { ErrorState as o } from "../../../../shared/ui/dist/lib/ErrorState/ErrorState.js";
13
- import "../../../../shared/ui/dist/index.js";
14
- import { useAnalyticsTrack as s } from "../../../../shared/feature/dist/lib/analytics/hooks.js";
15
- import { WidgetProvider as c } from "../../../../shared/feature/dist/lib/WidgetProvider/WidgetProvider.js";
16
- import { useWidgetConfig as ee, useWidgetLoading as te } from "../../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
17
- import "../../../../shared/feature/dist/index.js";
18
- import { DeleteRuleDialogDefaultLabels as ne } from "../../../../shared/approval-policy/ui/dist/index18.js";
19
- import { DeleteRuleDialog as re } from "../../../../shared/approval-policy/ui/dist/index19.js";
20
- import "../../../../shared/approval-policy/ui/dist/index.js";
21
- import { ApproverOptionLabels as l, PermissionErrorLabels as ie, ValidationErrorLabels as u } from "./index4.js";
22
- import { ExpenseApprovalPoliciesAnalyticsEvent as ae, WIDGET_NAME as d } from "./index2.js";
23
- import { AmountConditionType as f, ApprovalOutcomeType as p } from "../../ui/dist/index2.js";
24
- import { ApprovalRuleCardLabels as oe, ApprovalRuleToastLabels as se } from "../../ui/dist/index3.js";
25
- import { formatAmount as m } from "../../ui/dist/index4.js";
26
- import { ExpenseApprovalsPage as ce } from "../../ui/dist/index8.js";
1
+ import { formatMoneyExact as e } from "../../../../shared/util/dist/lib/formatMoneyExact.js";
2
+ import "../../../../shared/util/dist/index.js";
3
+ import { formatMinorUnitsAsAmountInput as t, parseAmountInputToMinorUnits as n } from "../../../../shared/approval-policy/util/dist/lib/amountInput.js";
4
+ import { ApprovalOutcomeType as r } from "../../ui/dist/index2.js";
5
+ import { ApprovalRuleCardLabels as i } from "../../ui/dist/index3.js";
27
6
  import "../../ui/dist/index.js";
28
- import { useApprovalPolicies as le } from "./index3.js";
29
- import { expenseApprovalPoliciesTestIds as h } from "./index5.js";
30
- import { useEffect as g, useMemo as _, useRef as ue, useState as v } from "react";
31
- import { Fragment as de, jsx as y, jsxs as fe } from "react/jsx-runtime";
32
7
  // ../../libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/feature/dist/index6.js
33
- var b = {
34
- minAmount: "",
35
- maxAmount: "",
36
- outcome: p.AutoApprove,
37
- approvers: []
38
- };
39
- function x(e, t) {
40
- let n = (e ?? "").trim().toLowerCase();
41
- return n === t || n === `embedded:${t}`;
42
- }
43
- function S(e, t) {
44
- return (e ?? "").toLowerCase().split(":").map((e) => e.trim()).filter(Boolean).some((e) => e === t);
45
- }
46
- function C(e) {
47
- return x(e, "cfo") || x(e, "finance_admin") || x(e, "finance-admin");
48
- }
49
- function w(e, t = l) {
50
- let n = e.find((e) => e.isSystemRole === !0 && x(e.key, "admin")), r = e.find((e) => e.isSystemRole === !0 && C(e.key)), i = e.filter((e) => e.isSystemRole === !0 && e !== n && e !== r && !S(e.key, "employee") && !S(e.key, "bookkeeper")).map((e) => ({
51
- id: e.id,
52
- label: e.name
53
- })), a = e.filter((e) => !e.isSystemRole && e.status?.toLowerCase() === "active").map((e) => ({
54
- id: e.id,
55
- label: e.name
56
- }));
57
- return [
58
- ...n ? [{
59
- id: n.id,
60
- label: t.AdminLabel,
61
- sublabel: t.AdminSublabel
62
- }] : [],
63
- {
64
- id: "reporting_manager",
65
- label: t.ReportingManagerLabel,
66
- sublabel: t.ReportingManagerSublabel
67
- },
68
- ...r ? [{
69
- id: r.id,
70
- label: t.CfoLabel,
71
- sublabel: t.CfoSublabel
72
- }] : [],
73
- ...i,
74
- ...a
75
- ];
76
- }
77
- function T(e) {
78
- let t = e.minAmount.trim() !== "", n = e.maxAmount.trim() !== "";
79
- return t && n ? f.InRange : t ? f.GreaterThanOrEqual : n ? f.LessThan : f.All;
80
- }
81
- function E(e) {
82
- return [e.conditionType === f.LessThan || e.conditionType === f.All ? 0 : e.minAmount ?? 0, e.conditionType === f.GreaterThanOrEqual || e.conditionType === f.All ? Infinity : e.maxAmount ?? 0];
83
- }
84
- function pe(e) {
85
- if (e.length === 0) return !1;
86
- let t = e.map(E).sort((e, t) => e[0] - t[0]);
87
- if (t[0][0] > 0) return !1;
88
- let n = 0;
89
- for (let [e, r] of t) {
90
- if (e > n) return !1;
91
- n = Math.max(n, r);
92
- }
93
- return n === Infinity;
94
- }
95
- function me(e) {
96
- if (e.length === 0) return [];
97
- let t = e.map(E).sort((e, t) => e[0] - t[0]), n = [], r = 0;
98
- for (let [e, i] of t) e > r && n.push({
99
- from: r,
100
- to: e
101
- }), r = Math.max(r, i);
102
- return r !== Infinity && n.push({
103
- from: r,
104
- to: null
105
- }), n;
106
- }
107
- function D(e) {
108
- let t = Number(e.minAmount) || 0, n = Number(e.maxAmount) || 0, r = T(e);
109
- return [r === f.LessThan || r === f.All ? 0 : t, r === f.GreaterThanOrEqual || r === f.All ? Infinity : n];
110
- }
111
- function O(e, t, n) {
112
- let [r, i] = D(e);
113
- return t.filter((e) => e.id !== n).some((e) => {
114
- let [t, n] = E(e);
115
- return r < n && t < i;
116
- });
117
- }
118
- function k(e, t, n, r = u) {
119
- let i = {}, a = e.minAmount.trim() !== "", o = e.maxAmount.trim() !== "", s = Number(e.minAmount.trim()), c = Number(e.maxAmount.trim());
120
- return a && (!Number.isFinite(s) || s < 0) && (i.minAmount = r.InvalidMinAmount), o && (!Number.isFinite(c) || c <= 0) && (i.maxAmount = r.InvalidMaxAmount), a && o && !i.minAmount && !i.maxAmount && s >= c && (i.maxAmount = r.MaxLessThanOrEqualToMin), e.outcome === p.RequireApproval && e.approvers.length === 0 && (i.approvers = r.ApproversRequired), !i.minAmount && !i.maxAmount && O(e, t, n) && (o ? i.maxAmount = r.ConflictsWithAnotherRule : i.minAmount = r.ConflictsWithAnotherRule), i;
121
- }
122
- function A(e, t) {
123
- let n = T(t);
124
- return {
125
- id: e,
126
- conditionType: n,
127
- minAmount: n === f.InRange || n === f.GreaterThanOrEqual ? Number(t.minAmount) : void 0,
128
- maxAmount: n === f.LessThan || n === f.InRange ? Number(t.maxAmount) : void 0,
129
- outcome: t.outcome,
130
- approvers: t.outcome === p.RequireApproval ? t.approvers : []
131
- };
132
- }
133
- function he(e) {
8
+ function a(e) {
9
+ return (Math.round(e * 100) - 1) / 100;
10
+ }
11
+ function o(e) {
12
+ return t(Math.round(e * 100) - 1);
13
+ }
14
+ function s(e) {
15
+ let t = n(e);
16
+ if (t.status !== "ok") throw Error("Invalid maximum amount");
17
+ return (t.minorUnits + 1) / 100;
18
+ }
19
+ function c(t, n = i) {
20
+ let o = t.minAmount, s = t.maxAmount === void 0 ? void 0 : a(t.maxAmount), c = (t) => e(t, {
21
+ currencyCode: "USD",
22
+ includeSpaceAfterCurrencySymbol: !1
23
+ }), l = (e) => e.replace("{lower}", o === void 0 ? "" : c(o)).replace("{upper}", s === void 0 ? "" : c(s)), u = o !== void 0 && s !== void 0 ? n.TitleRange : s === void 0 ? o === void 0 ? n.TitleAll : n.TitleFrom : n.TitleUpTo, d = t.outcome === r.AutoApprove ? n.SentenceAutoApprove : o !== void 0 && s !== void 0 ? n.SentenceRange : s === void 0 ? o === void 0 ? n.SentenceAll : n.SentenceFrom : n.SentenceUpTo;
134
24
  return {
135
- minAmount: e.minAmount == null ? "" : String(e.minAmount),
136
- maxAmount: e.maxAmount == null ? "" : String(e.maxAmount),
137
- outcome: e.outcome,
138
- approvers: e.approvers
139
- };
140
- }
141
- function j({ headerActionContainer: c, labels: d }) {
142
- let S = _(() => ({
143
- ...l,
144
- ...d?.approvers
145
- }), [d?.approvers]), T = _(() => ({
146
- ...u,
147
- ...d?.validation
148
- }), [d?.validation]), E = _(() => ({
149
- ...ie,
150
- ...d?.errors
151
- }), [d?.errors]), D = _(() => ({
152
- ...se,
153
- ...d?.toast
154
- }), [d?.toast]), O = s();
155
- g(() => {
156
- O(ae.Mounted);
157
- }, [O]);
158
- let { initResponse: j } = ee(), M = te(), ge = t(n().organizationStatus), N = j?.scopes?.includes(r.RoleReadOrg) ?? !1, { data: P, isResolving: _e, isError: ve, refetch: ye } = i({ enabled: N }), be = _(() => w(P?.data ?? [], S), [P, S]), xe = _(() => {
159
- let e = P?.data ?? [], t = e.find((e) => e.isSystemRole === !0 && x(e.key, "admin")), n = e.find((e) => e.isSystemRole === !0 && C(e.key)), r = { reporting_manager: S.ReportingManagerLabel };
160
- t && (r[t.id] = S.AdminLabel), n && (r[n.id] = S.CfoLabel);
161
- for (let t of e) r[t.id] || (r[t.id] = t.name);
162
- return r;
163
- }, [P, S]), { rules: F, isLoading: I, isError: Se, refetch: Ce, hasLoaded: L, saveStatus: R, createRule: we, updateRule: Te, deleteRule: Ee } = le(xe), [z, B] = v(!1), [V, H] = v(null), [U, W] = v(!1), [G, K] = v(b), [q, J] = v(null), [Y, X] = v(null), Z = ue(D);
164
- g(() => {
165
- Z.current = D;
166
- }, [D]), g(() => {
167
- R === "success" && e.success(Z.current.Saved), R === "error" && e.error(Z.current.FailedToSave);
168
- }, [R]);
169
- let Q = I || M && !j || ge && !L, De = pe(F), Oe = me(F), $ = Q || _e || R === "saving", ke = U && z ? k(G, F, void 0, T) : {}, Ae = Y && q && z ? k(Y, F, q, T) : {}, je = () => {
170
- B(!1), W(!0), K(b);
171
- }, Me = () => {
172
- B(!1), W(!1);
173
- }, Ne = async () => {
174
- B(!0);
175
- let e = k(G, F, void 0, T);
176
- if (Object.keys(e).length > 0) return;
177
- let t = crypto.randomUUID();
178
- await we(A(t, G)) && (W(!1), K(b));
179
- }, Pe = (e) => {
180
- K(e);
181
- }, Fe = (e) => {
182
- B(!1);
183
- let t = F.find((t) => t.id === e);
184
- t && (W(!1), K(b), J(e), X(he(t)));
185
- }, Ie = () => {
186
- B(!1), J(null), X(null);
187
- }, Le = async () => {
188
- if (B(!0), !q || !Y) return;
189
- let e = k(Y, F, q, T);
190
- Object.keys(e).length > 0 || await Te(q, A(q, Y)) && (J(null), X(null));
191
- }, Re = (e) => {
192
- X(e);
193
- }, ze = (() => {
194
- let e = F.find((e) => e.id === V);
195
- if (!e) return;
196
- let t = {
197
- ...ne,
198
- ...d?.deleteDialog
199
- }, n = {
200
- ...oe,
201
- ...d?.ruleCard
202
- }, r = `${n.For} ${n.Expenses}`, i = `${n.For} ${n.All} ${n.Expenses}`;
203
- e.conditionType === f.LessThan && (i = `${r} ${n.LessThan} ${m(e.maxAmount ?? 0)}`), e.conditionType === f.GreaterThanOrEqual && (i = `${r} ${n.GreaterThanOrEqual} ${m(e.minAmount ?? 0)}`), e.conditionType === f.InRange && (i = `${r} ${n.GreaterThanOrEqual} ${m(e.minAmount ?? 0)} ${n.AndLessThan} ${m(e.maxAmount ?? 0)}`);
204
- let a = e.outcome === p.AutoApprove ? n.AutoApprove : `${n.RequireApprovalFrom} ${e.approvers.map((e) => e.label).join(` ${n.ApproverSeparator} `)}`;
205
- return [{
206
- label: t.Range,
207
- value: i
208
- }, {
209
- label: t.Outcome,
210
- value: a
211
- }];
212
- })(), Be = async () => {
213
- V && await Ee(V) && (q === V && (J(null), X(null)), H(null));
25
+ ...t,
26
+ title: l(u),
27
+ sentence: l(d)
214
28
  };
215
- return j !== void 0 && !N ? /* @__PURE__ */ y(o, {
216
- title: E.MissingRolePermissionTitle,
217
- description: E.MissingRolePermissionDescription
218
- }) : ve ? /* @__PURE__ */ y(o, {
219
- title: E.RolesUnavailableTitle,
220
- description: E.RolesUnavailableDescription,
221
- retryLabel: E.Retry,
222
- onRetry: () => void ye()
223
- }) : Se && !I && !L ? /* @__PURE__ */ y(o, {
224
- title: E.PoliciesUnavailableTitle,
225
- description: E.PoliciesUnavailableDescription,
226
- retryLabel: E.Retry,
227
- onRetry: () => void Ce()
228
- }) : /* @__PURE__ */ fe(de, { children: [
229
- /* @__PURE__ */ y(a, {}),
230
- /* @__PURE__ */ y(ce, {
231
- rules: F,
232
- labels: d,
233
- isBusy: $,
234
- isLoading: Q,
235
- isAddingRule: U,
236
- newRuleFormValues: G,
237
- newRuleValidationErrors: ke,
238
- editingRuleId: q,
239
- editingRuleFormValues: Y,
240
- editingRuleValidationErrors: Ae,
241
- approverOptions: $ ? [] : be,
242
- allExpensesAreCovered: De,
243
- gapIntervals: Oe,
244
- onAddRuleClick: je,
245
- headerActionContainer: c,
246
- onCancelAddRule: Me,
247
- onSaveNewRule: () => void Ne(),
248
- onNewRuleFormChange: Pe,
249
- onEditRule: Fe,
250
- onCancelEditRule: Ie,
251
- onSaveEditRule: () => void Le(),
252
- onEditRuleFormChange: Re,
253
- onDeleteRule: H,
254
- testIds: {
255
- ruleCard: { root: h.ruleCard },
256
- ruleForm: {
257
- root: h.ruleForm,
258
- saveButton: h.ruleFormSaveButton,
259
- minAmountInput: h.ruleFormMinAmountInput,
260
- maxAmountInput: h.ruleFormMaxAmountInput
261
- }
262
- }
263
- }),
264
- /* @__PURE__ */ y(re, {
265
- labels: d?.deleteDialog,
266
- details: ze,
267
- open: V !== null,
268
- onOpenChange: (e) => {
269
- e || H(null);
270
- },
271
- onCancel: () => H(null),
272
- onConfirm: () => void Be(),
273
- isDeleting: R === "saving"
274
- })
275
- ] });
276
- }
277
- function M({ token: e, orgId: t, widgetToken: n, organizationId: r, headerActionContainer: i, labels: a, ...o } = {}) {
278
- return /* @__PURE__ */ y(c, {
279
- ...o,
280
- widgetName: d,
281
- widgetToken: n === void 0 ? e : n,
282
- organizationId: r === void 0 ? t : r,
283
- children: /* @__PURE__ */ y(j, {
284
- headerActionContainer: i,
285
- labels: a
286
- })
287
- });
288
29
  }
289
- export { M as ExpenseApprovalPoliciesWidget, M as default, w as buildApproverOptions, x as isEmbeddedSystemRoleKey, S as roleKeyHasSegment };
30
+ export { a as maximumForDisplay, s as maximumForSave, o as maximumInputForDisplay, c as ruleForDisplay };
@@ -0,0 +1,291 @@
1
+ "use client";
2
+ "use client";
3
+ "use client";
4
+ "use client";
5
+ import { toast as e } from "../../../../../../packages/shared-ui-shadcn/dist/index.js";
6
+ import { isOrganizationOnItsWay as t } from "../../../../shared/data-access/dist/lib/organizationStatus.js";
7
+ import { useEmbedApi as n } from "../../../../shared/data-access/dist/lib/EmbedApiContext.js";
8
+ import { Scope as r } from "../../../../shared/data-access/dist/lib/scopes.js";
9
+ import { useAllOrganizationRolesQuery as i } from "../../../../shared/data-access/dist/lib/role/useAllOrganizationRolesQuery.js";
10
+ import "../../../../shared/data-access/dist/index.js";
11
+ import { EmbeddedToaster as a } from "../../../../shared/ui/dist/lib/EmbeddedToaster.js";
12
+ import { ErrorState as o } from "../../../../shared/ui/dist/lib/ErrorState/ErrorState.js";
13
+ import "../../../../shared/ui/dist/index.js";
14
+ import { useAnalyticsTrack as s } from "../../../../shared/feature/dist/lib/analytics/hooks.js";
15
+ import { WidgetProvider as c } from "../../../../shared/feature/dist/lib/WidgetProvider/WidgetProvider.js";
16
+ import { useWidgetConfig as ee, useWidgetLoading as te } from "../../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
17
+ import "../../../../shared/feature/dist/index.js";
18
+ import { parseAmountInputToMinorUnits as l } from "../../../../shared/approval-policy/util/dist/lib/amountInput.js";
19
+ import { DeleteRuleDialogDefaultLabels as ne } from "../../../../shared/approval-policy/ui/dist/index18.js";
20
+ import { DeleteRuleDialog as re } from "../../../../shared/approval-policy/ui/dist/index19.js";
21
+ import "../../../../shared/approval-policy/ui/dist/index.js";
22
+ import { ApproverOptionLabels as u, PermissionErrorLabels as ie, ValidationErrorLabels as d } from "./index4.js";
23
+ import { ExpenseApprovalPoliciesAnalyticsEvent as ae, WIDGET_NAME as f } from "./index2.js";
24
+ import { AmountConditionType as p, ApprovalOutcomeType as m } from "../../ui/dist/index2.js";
25
+ import { ApprovalRuleCardLabels as h, ApprovalRuleToastLabels as oe } from "../../ui/dist/index3.js";
26
+ import { ExpenseApprovalsPage as se } from "../../ui/dist/index8.js";
27
+ import "../../ui/dist/index.js";
28
+ import { useApprovalPolicies as ce } from "./index3.js";
29
+ import { expenseApprovalPoliciesTestIds as g } from "./index5.js";
30
+ import { maximumForSave as _, maximumInputForDisplay as v, ruleForDisplay as y } from "./index6.js";
31
+ import { useEffect as b, useMemo as x, useRef as le, useState as S } from "react";
32
+ import { Fragment as ue, jsx as C, jsxs as de } from "react/jsx-runtime";
33
+ // ../../libs/tesouro-embedded-components-react/expense-management-widget/approval-policies/feature/dist/index7.js
34
+ var w = {
35
+ minAmount: "",
36
+ maxAmount: "",
37
+ outcome: m.AutoApprove,
38
+ approvers: []
39
+ };
40
+ function T(e, t) {
41
+ let n = (e ?? "").trim().toLowerCase();
42
+ return n === t || n === `embedded:${t}`;
43
+ }
44
+ function E(e, t) {
45
+ return (e ?? "").toLowerCase().split(":").map((e) => e.trim()).filter(Boolean).some((e) => e === t);
46
+ }
47
+ function fe(e) {
48
+ return T(e, "cfo") || T(e, "finance_admin") || T(e, "finance-admin");
49
+ }
50
+ function pe(e, t = u) {
51
+ let n = e.find((e) => e.isSystemRole === !0 && T(e.key, "admin")), r = e.find((e) => e.isSystemRole === !0 && fe(e.key)), i = e.filter((e) => e.isSystemRole === !0 && e !== n && e !== r && !E(e.key, "employee") && !E(e.key, "bookkeeper")).map((e) => ({
52
+ id: e.id,
53
+ label: e.name
54
+ })), a = e.filter((e) => !e.isSystemRole && e.status?.toLowerCase() === "active").map((e) => ({
55
+ id: e.id,
56
+ label: e.name
57
+ }));
58
+ return [
59
+ ...n ? [{
60
+ id: n.id,
61
+ label: t.AdminLabel,
62
+ sublabel: t.AdminSublabel
63
+ }] : [],
64
+ {
65
+ id: "reporting_manager",
66
+ label: t.ReportingManagerLabel,
67
+ sublabel: t.ReportingManagerSublabel
68
+ },
69
+ ...r ? [{
70
+ id: r.id,
71
+ label: t.CfoLabel,
72
+ sublabel: t.CfoSublabel
73
+ }] : [],
74
+ ...i,
75
+ ...a
76
+ ];
77
+ }
78
+ function D(e) {
79
+ let t = e.minAmount.trim() !== "", n = e.maxAmount.trim() !== "";
80
+ return t && n ? p.InRange : t ? p.GreaterThanOrEqual : n ? p.LessThan : p.All;
81
+ }
82
+ function O(e) {
83
+ return [e.conditionType === p.LessThan || e.conditionType === p.All ? 0 : Math.round((e.minAmount ?? 0) * 100), e.conditionType === p.GreaterThanOrEqual || e.conditionType === p.All ? Infinity : Math.round((e.maxAmount ?? 0) * 100)];
84
+ }
85
+ function me(e) {
86
+ if (e.length === 0) return !1;
87
+ let t = e.map(O).sort((e, t) => e[0] - t[0]);
88
+ if (t[0][0] > 0) return !1;
89
+ let n = 0;
90
+ for (let [e, r] of t) {
91
+ if (e > n) return !1;
92
+ n = Math.max(n, r);
93
+ }
94
+ return n === Infinity;
95
+ }
96
+ function he(e) {
97
+ if (e.length === 0) return [];
98
+ let t = e.map(O).sort((e, t) => e[0] - t[0]), n = [], r = 0;
99
+ for (let [e, i] of t) e > r && n.push({
100
+ from: r / 100,
101
+ to: (e - 1) / 100
102
+ }), r = Math.max(r, i);
103
+ return r !== Infinity && n.push({
104
+ from: r / 100,
105
+ to: null
106
+ }), n;
107
+ }
108
+ function k(e) {
109
+ let t = l(e.minAmount), n = l(e.maxAmount), r = t.status === "ok" ? t.minorUnits : 0, i = n.status === "ok" ? n.minorUnits + 1 : 0, a = D(e);
110
+ return [a === p.LessThan || a === p.All ? 0 : r, a === p.GreaterThanOrEqual || a === p.All ? Infinity : i];
111
+ }
112
+ function A(e, t, n) {
113
+ let [r, i] = k(e);
114
+ return t.filter((e) => e.id !== n).some((e) => {
115
+ let [t, n] = O(e);
116
+ return r < n && t < i;
117
+ });
118
+ }
119
+ function j(e, t, n, r = d) {
120
+ let i = {}, a = e.minAmount.trim() !== "", o = e.maxAmount.trim() !== "", s = l(e.minAmount), c = l(e.maxAmount);
121
+ return a && s.status !== "ok" && (i.minAmount = r.InvalidMinAmount), o && (c.status !== "ok" || !Number.isSafeInteger(c.minorUnits + 1)) && (i.maxAmount = r.InvalidMaxAmount), a && o && !i.minAmount && !i.maxAmount && s.status === "ok" && c.status === "ok" && s.minorUnits > c.minorUnits && (i.maxAmount = r.MaxLessThanOrEqualToMin), e.outcome === m.RequireApproval && e.approvers.length === 0 && (i.approvers = r.ApproversRequired), !i.minAmount && !i.maxAmount && A(e, t, n) && (o ? i.maxAmount = r.ConflictsWithAnotherRule : i.minAmount = r.ConflictsWithAnotherRule), i;
122
+ }
123
+ function M(e, t) {
124
+ let n = D(t), r = l(t.minAmount);
125
+ return {
126
+ id: e,
127
+ conditionType: n,
128
+ minAmount: (n === p.InRange || n === p.GreaterThanOrEqual) && r.status === "ok" ? r.minorUnits / 100 : void 0,
129
+ maxAmount: n === p.LessThan || n === p.InRange ? _(t.maxAmount) : void 0,
130
+ outcome: t.outcome,
131
+ approvers: t.outcome === m.RequireApproval ? t.approvers : []
132
+ };
133
+ }
134
+ function ge(e) {
135
+ return {
136
+ minAmount: e.minAmount == null ? "" : String(e.minAmount),
137
+ maxAmount: e.maxAmount == null ? "" : v(e.maxAmount),
138
+ outcome: e.outcome,
139
+ approvers: e.approvers
140
+ };
141
+ }
142
+ function N({ headerActionContainer: c, labels: l }) {
143
+ let f = x(() => ({
144
+ ...u,
145
+ ...l?.approvers
146
+ }), [l?.approvers]), p = x(() => ({
147
+ ...d,
148
+ ...l?.validation
149
+ }), [l?.validation]), _ = x(() => ({
150
+ ...ie,
151
+ ...l?.errors
152
+ }), [l?.errors]), v = x(() => ({
153
+ ...oe,
154
+ ...l?.toast
155
+ }), [l?.toast]), E = s();
156
+ b(() => {
157
+ E(ae.Mounted);
158
+ }, [E]);
159
+ let { initResponse: D } = ee(), O = te(), k = t(n().organizationStatus), A = D?.scopes?.includes(r.RoleReadOrg) ?? !1, { data: N, isResolving: P, isError: _e, refetch: ve } = i({ enabled: A }), ye = x(() => pe(N?.data ?? [], f), [N, f]), be = x(() => {
160
+ let e = N?.data ?? [], t = e.find((e) => e.isSystemRole === !0 && T(e.key, "admin")), n = e.find((e) => e.isSystemRole === !0 && fe(e.key)), r = { reporting_manager: f.ReportingManagerLabel };
161
+ t && (r[t.id] = f.AdminLabel), n && (r[n.id] = f.CfoLabel);
162
+ for (let t of e) r[t.id] || (r[t.id] = t.name);
163
+ return r;
164
+ }, [N, f]), { rules: F, isLoading: I, isError: xe, refetch: Se, hasLoaded: L, saveStatus: R, createRule: Ce, updateRule: we, deleteRule: Te } = ce(be), [z, B] = S(!1), [V, H] = S(null), [U, W] = S(!1), [G, K] = S(w), [q, J] = S(null), [Y, X] = S(null), Z = le(v);
165
+ b(() => {
166
+ Z.current = v;
167
+ }, [v]), b(() => {
168
+ R === "success" && e.success(Z.current.Saved), R === "error" && e.error(Z.current.FailedToSave);
169
+ }, [R]);
170
+ let Q = I || O && !D || k && !L, Ee = me(F), De = he(F), $ = Q || P || R === "saving", Oe = U && z ? j(G, F, void 0, p) : {}, ke = Y && q && z ? j(Y, F, q, p) : {}, Ae = () => {
171
+ B(!1), W(!0), K(w);
172
+ }, je = () => {
173
+ B(!1), W(!1);
174
+ }, Me = async () => {
175
+ B(!0);
176
+ let e = j(G, F, void 0, p);
177
+ if (Object.keys(e).length > 0) return;
178
+ let t = crypto.randomUUID();
179
+ await Ce(M(t, G)) && (W(!1), K(w));
180
+ }, Ne = (e) => {
181
+ K(e);
182
+ }, Pe = (e) => {
183
+ B(!1);
184
+ let t = F.find((t) => t.id === e);
185
+ t && (W(!1), K(w), J(e), X(ge(t)));
186
+ }, Fe = () => {
187
+ B(!1), J(null), X(null);
188
+ }, Ie = async () => {
189
+ if (B(!0), !q || !Y) return;
190
+ let e = j(Y, F, q, p);
191
+ Object.keys(e).length > 0 || await we(q, M(q, Y)) && (J(null), X(null));
192
+ }, Le = (e) => {
193
+ X(e);
194
+ }, Re = (() => {
195
+ let e = F.find((e) => e.id === V);
196
+ if (!e) return;
197
+ let t = {
198
+ ...ne,
199
+ ...l?.deleteDialog
200
+ }, n = {
201
+ ...h,
202
+ ...l?.ruleCard
203
+ }, r = y(e, n).title ?? "", i = e.outcome === m.AutoApprove ? n.AutoApprove : `${n.RequireApprovalFrom} ${e.approvers.map((e) => e.label).join(` ${n.ApproverSeparator} `)}`;
204
+ return [{
205
+ label: t.Range,
206
+ value: r
207
+ }, {
208
+ label: t.Outcome,
209
+ value: i
210
+ }];
211
+ })(), ze = async () => {
212
+ V && await Te(V) && (q === V && (J(null), X(null)), H(null));
213
+ };
214
+ return D !== void 0 && !A ? /* @__PURE__ */ C(o, {
215
+ title: _.MissingRolePermissionTitle,
216
+ description: _.MissingRolePermissionDescription
217
+ }) : _e ? /* @__PURE__ */ C(o, {
218
+ title: _.RolesUnavailableTitle,
219
+ description: _.RolesUnavailableDescription,
220
+ retryLabel: _.Retry,
221
+ onRetry: () => void ve()
222
+ }) : xe && !I && !L ? /* @__PURE__ */ C(o, {
223
+ title: _.PoliciesUnavailableTitle,
224
+ description: _.PoliciesUnavailableDescription,
225
+ retryLabel: _.Retry,
226
+ onRetry: () => void Se()
227
+ }) : /* @__PURE__ */ de(ue, { children: [
228
+ /* @__PURE__ */ C(a, {}),
229
+ /* @__PURE__ */ C(se, {
230
+ rules: F.map((e) => y(e, {
231
+ ...h,
232
+ ...l?.ruleCard
233
+ })),
234
+ labels: l,
235
+ isBusy: $,
236
+ isLoading: Q,
237
+ isAddingRule: U,
238
+ newRuleFormValues: G,
239
+ newRuleValidationErrors: Oe,
240
+ editingRuleId: q,
241
+ editingRuleFormValues: Y,
242
+ editingRuleValidationErrors: ke,
243
+ approverOptions: $ ? [] : ye,
244
+ allExpensesAreCovered: Ee,
245
+ gapIntervals: De,
246
+ onAddRuleClick: Ae,
247
+ headerActionContainer: c,
248
+ onCancelAddRule: je,
249
+ onSaveNewRule: () => void Me(),
250
+ onNewRuleFormChange: Ne,
251
+ onEditRule: Pe,
252
+ onCancelEditRule: Fe,
253
+ onSaveEditRule: () => void Ie(),
254
+ onEditRuleFormChange: Le,
255
+ onDeleteRule: H,
256
+ testIds: {
257
+ ruleCard: { root: g.ruleCard },
258
+ ruleForm: {
259
+ root: g.ruleForm,
260
+ saveButton: g.ruleFormSaveButton,
261
+ minAmountInput: g.ruleFormMinAmountInput,
262
+ maxAmountInput: g.ruleFormMaxAmountInput
263
+ }
264
+ }
265
+ }),
266
+ /* @__PURE__ */ C(re, {
267
+ labels: l?.deleteDialog,
268
+ details: Re,
269
+ open: V !== null,
270
+ onOpenChange: (e) => {
271
+ e || H(null);
272
+ },
273
+ onCancel: () => H(null),
274
+ onConfirm: () => void ze(),
275
+ isDeleting: R === "saving"
276
+ })
277
+ ] });
278
+ }
279
+ function P({ token: e, orgId: t, widgetToken: n, organizationId: r, headerActionContainer: i, labels: a, ...o } = {}) {
280
+ return /* @__PURE__ */ C(c, {
281
+ ...o,
282
+ widgetName: f,
283
+ widgetToken: n === void 0 ? e : n,
284
+ organizationId: r === void 0 ? t : r,
285
+ children: /* @__PURE__ */ C(N, {
286
+ headerActionContainer: i,
287
+ labels: a
288
+ })
289
+ });
290
+ }
291
+ export { P as ExpenseApprovalPoliciesWidget, P as default, pe as buildApproverOptions, T as isEmbeddedSystemRoleKey, E as roleKeyHasSegment };
@@ -1,8 +1,8 @@
1
1
  import { AmountConditionType as e, ApprovalOutcomeType as t } from "./index2.js";
2
2
  import { ApprovalRuleCardLabels as n, ApprovalRuleToastLabels as r } from "./index3.js";
3
- import { formatAmount as i } from "./index4.js";
3
+ import "./index4.js";
4
4
  import "./index5.js";
5
5
  import "./index6.js";
6
6
  import "./index7.js";
7
- import { ExpenseApprovalsPage as a } from "./index8.js";
8
- export { e as AmountConditionType, t as ApprovalOutcomeType, n as ApprovalRuleCardLabels, r as ApprovalRuleToastLabels, a as ExpenseApprovalsPage, i as formatAmount };
7
+ import { ExpenseApprovalsPage as i } from "./index8.js";
8
+ export { e as AmountConditionType, t as ApprovalOutcomeType, n as ApprovalRuleCardLabels, r as ApprovalRuleToastLabels, i as ExpenseApprovalsPage };