@tesouro/embedded-components-react 0.9.44 → 0.9.45

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.
@@ -680,11 +680,19 @@ interface ApprovalRequestsListLabels {
680
680
  status: Record<ApprovalRequestStatus, string>;
681
681
  filters: ApprovalRequestsFilterLabels;
682
682
  }
683
+ /** Toast copy for approve and reject; the error copy is the fallback when the API gives no reason. */
684
+ interface ApprovalRequestsMessageLabels {
685
+ approved: string;
686
+ rejected: string;
687
+ approveError: string;
688
+ rejectError: string;
689
+ }
683
690
 
684
691
  interface ApprovalRequestsWidgetOwnProps {
685
692
  screenLabels?: PartialDeep<ApprovalRequestsScreenLabels>;
686
693
  listLabels?: PartialDeep<ApprovalRequestsListLabels>;
687
- rejectDialogLabels?: Partial<RejectApprovalRequestDialogLabels>;
694
+ rejectDialogLabels?: PartialDeep<RejectApprovalRequestDialogLabels>;
695
+ messageLabels?: PartialDeep<ApprovalRequestsMessageLabels>;
688
696
  }
689
697
  /** Public props for {@link ApprovalRequestsWidget}. */
690
698
  type ApprovalRequestsWidgetProps = WidgetProviderProps & ApprovalRequestsWidgetOwnProps;
@@ -692,7 +700,7 @@ type ApprovalRequestsWidgetProps = WidgetProviderProps & ApprovalRequestsWidgetO
692
700
  * Self-contained approval requests widget, a native port of Monite's approval
693
701
  * requests (FOPS-97). Exported only from the package's `/experimental` entry.
694
702
  */
695
- declare function ApprovalRequestsWidget({ screenLabels, listLabels, rejectDialogLabels, ...widgetProviderProps }: ApprovalRequestsWidgetProps): React.JSX.Element;
703
+ declare function ApprovalRequestsWidget({ screenLabels, listLabels, rejectDialogLabels, messageLabels, ...widgetProviderProps }: ApprovalRequestsWidgetProps): React.JSX.Element;
696
704
 
697
705
  export { ApprovalRequestsWidget };
698
706
  export type { ApprovalRequestsWidgetProps };
@@ -680,11 +680,19 @@ interface ApprovalRequestsListLabels {
680
680
  status: Record<ApprovalRequestStatus, string>;
681
681
  filters: ApprovalRequestsFilterLabels;
682
682
  }
683
+ /** Toast copy for approve and reject; the error copy is the fallback when the API gives no reason. */
684
+ interface ApprovalRequestsMessageLabels {
685
+ approved: string;
686
+ rejected: string;
687
+ approveError: string;
688
+ rejectError: string;
689
+ }
683
690
 
684
691
  interface ApprovalRequestsWidgetOwnProps {
685
692
  screenLabels?: PartialDeep<ApprovalRequestsScreenLabels>;
686
693
  listLabels?: PartialDeep<ApprovalRequestsListLabels>;
687
- rejectDialogLabels?: Partial<RejectApprovalRequestDialogLabels>;
694
+ rejectDialogLabels?: PartialDeep<RejectApprovalRequestDialogLabels>;
695
+ messageLabels?: PartialDeep<ApprovalRequestsMessageLabels>;
688
696
  }
689
697
  /** Public props for {@link ApprovalRequestsWidget}. */
690
698
  type ApprovalRequestsWidgetProps = WidgetProviderProps & ApprovalRequestsWidgetOwnProps;
@@ -692,7 +700,7 @@ type ApprovalRequestsWidgetProps = WidgetProviderProps & ApprovalRequestsWidgetO
692
700
  * Self-contained approval requests widget, a native port of Monite's approval
693
701
  * requests (FOPS-97). Exported only from the package's `/experimental` entry.
694
702
  */
695
- declare function ApprovalRequestsWidget({ screenLabels, listLabels, rejectDialogLabels, ...widgetProviderProps }: ApprovalRequestsWidgetProps): React.JSX.Element;
703
+ declare function ApprovalRequestsWidget({ screenLabels, listLabels, rejectDialogLabels, messageLabels, ...widgetProviderProps }: ApprovalRequestsWidgetProps): React.JSX.Element;
696
704
 
697
705
  interface CheckAmountAndDetailScreenLabels {
698
706
  title: string;
@@ -5,76 +5,86 @@
5
5
  import { isOrganizationOnItsWay as e } from "../../../../../shared/data-access/dist/lib/organizationStatus.js";
6
6
  import { useEmbedApi as t } from "../../../../../shared/data-access/dist/lib/EmbedApiContext.js";
7
7
  import "../../../../../shared/data-access/dist/index.js";
8
- import { useAnalyticsTrack as n } from "../../../../../shared/feature/dist/lib/analytics/hooks.js";
9
- import { WidgetProvider as r } from "../../../../../shared/feature/dist/lib/WidgetProvider/WidgetProvider.js";
10
- import { useRefetchWidget as i, useWidgetConfig as a, useWidgetError as o, useWidgetInitStaleForToken as s, useWidgetLoading as c } from "../../../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
8
+ import { EmbeddedToaster as n } from "../../../../../shared/ui/dist/lib/EmbeddedToaster.js";
9
+ import "../../../../../shared/ui/dist/index.js";
10
+ import { useAnalyticsTrack as r } from "../../../../../shared/feature/dist/lib/analytics/hooks.js";
11
+ import { WidgetProvider as i } from "../../../../../shared/feature/dist/lib/WidgetProvider/WidgetProvider.js";
12
+ import { useRefetchWidget as a, useWidgetConfig as o, useWidgetError as s, useWidgetInitStaleForToken as c, useWidgetLoading as l } from "../../../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
11
13
  import "../../../../../shared/feature/dist/index.js";
12
- import { ApprovalRequestsWidgetAnalyticsEvent as l, WIDGET_NAME as u } from "../analytics/events.js";
13
- import { APPROVAL_REQUESTS_LIST_LABELS_EN as d } from "./labels.js";
14
- import { getApprovalRequestPermissions as f } from "./permissions.js";
15
- import { useApprovalRequestDecisions as p } from "./useApprovalRequestDecisions.js";
16
- import { ApprovalRequestsScreen as m } from "../../../../ui/dist/index4.js";
17
- import { RejectApprovalRequestDialog as h } from "../../../../ui/dist/index5.js";
14
+ import { ApprovalRequestsWidgetAnalyticsEvent as u, WIDGET_NAME as d } from "../analytics/events.js";
15
+ import { APPROVAL_REQUESTS_LIST_LABELS_EN as f, APPROVAL_REQUESTS_MESSAGE_LABELS_EN as p } from "./labels.js";
16
+ import { getApprovalRequestPermissions as m } from "./permissions.js";
17
+ import { useApprovalRequestDecisions as h } from "./useApprovalRequestDecisions.js";
18
+ import { ApprovalRequestsScreen as g } from "../../../../ui/dist/index4.js";
19
+ import { RejectApprovalRequestDialog as _ } from "../../../../ui/dist/index5.js";
18
20
  import "../../../../ui/dist/index.js";
19
- import { useApprovalRequestsTable as g } from "./useApprovalRequestsTable.js";
20
- import { useEffect as _, useMemo as v } from "react";
21
- import { Fragment as y, jsx as b, jsxs as x } from "react/jsx-runtime";
21
+ import { useApprovalRequestsTable as v } from "./useApprovalRequestsTable.js";
22
+ import { useEffect as y, useMemo as b } from "react";
23
+ import { Fragment as x, jsx as S, jsxs as C } from "react/jsx-runtime";
22
24
  //#region ../../libs/tesouro-embedded-components-react/approval-requests-widget/feature/dist/lib/ApprovalRequestsWidget/ApprovalRequestsWidget.js
23
- function S({ screenLabels: r, listLabels: u, rejectDialogLabels: S }) {
24
- let C = n();
25
- _(() => {
26
- C(l.Mounted);
27
- }, [C]);
28
- let w = v(() => ({
25
+ function w({ screenLabels: i, listLabels: d, rejectDialogLabels: w, messageLabels: T }) {
26
+ let E = r();
27
+ y(() => {
28
+ E(u.Mounted);
29
+ }, [E]);
30
+ let D = b(() => ({
31
+ ...f,
29
32
  ...d,
30
- ...u,
31
33
  status: {
32
- ...d.status,
33
- ...u?.status
34
+ ...f.status,
35
+ ...d?.status
34
36
  },
35
37
  filters: {
36
- ...d.filters,
37
- ...u?.filters
38
+ ...f.filters,
39
+ ...d?.filters
38
40
  }
39
- }), [u]), { initResponse: T, widgetToken: E } = a(), D = c(), O = o(), k = s(), A = i(), { organizationStatus: j } = t(), M = v(() => f(k ? void 0 : T?.scopes), [k, T?.scopes]), N = !(!E || T || O) || D && !T || k, P = !!O && (!T || k), F = p(), I = g({
40
- labels: w,
41
- enabled: M.canRead,
42
- pendingRequestIds: F.pendingRequestIds,
43
- areDecisionsPaused: F.areDecisionsPaused
41
+ }), [d]), { initResponse: O, widgetToken: k } = o(), A = l(), j = s(), M = c(), N = a(), { organizationStatus: P } = t(), F = b(() => m(M ? void 0 : O?.scopes), [M, O?.scopes]), I = !(!k || O || j) || A && !O || M, L = !!j && (!O || M), R = b(() => ({
42
+ ...p,
43
+ ...T
44
+ }), [T]), z = h({ messages: R }), B = v({
45
+ labels: D,
46
+ enabled: F.canRead,
47
+ pendingRequestIds: z.pendingRequestIds,
48
+ areDecisionsPaused: z.areDecisionsPaused
44
49
  });
45
- return /* @__PURE__ */ x(y, { children: [/* @__PURE__ */ b(m, {
46
- rows: I.rows,
47
- isLoading: I.isLoading || (N || e(j)) && I.rows.length === 0,
48
- isError: P || I.isError,
49
- isAccessRestricted: !N && !P && !M.canRead,
50
- pageSize: I.pageSize,
51
- onPageSizeChange: I.onPageSizeChange,
52
- pageSizeOptions: I.pageSizeOptions,
53
- hasNextPage: I.hasNextPage,
54
- hasPrevPage: I.hasPrevPage,
55
- onNextPage: I.onNextPage,
56
- onPrevPage: I.onPrevPage,
57
- emptyState: I.emptyState,
58
- filters: I.filters,
59
- onRetry: P ? A : I.onRetry,
60
- onApprove: F.onApprove,
61
- onReject: F.onReject,
62
- labels: r
63
- }), /* @__PURE__ */ b(h, {
64
- ...F.rejectDialog,
65
- labels: S
66
- })] });
50
+ return /* @__PURE__ */ C(x, { children: [
51
+ /* @__PURE__ */ S(n, {}),
52
+ /* @__PURE__ */ S(g, {
53
+ rows: B.rows,
54
+ isLoading: B.isLoading || (I || e(P)) && B.rows.length === 0,
55
+ isError: L || B.isError,
56
+ isAccessRestricted: !I && !L && !F.canRead,
57
+ pageSize: B.pageSize,
58
+ onPageSizeChange: B.onPageSizeChange,
59
+ pageSizeOptions: B.pageSizeOptions,
60
+ hasNextPage: B.hasNextPage,
61
+ hasPrevPage: B.hasPrevPage,
62
+ onNextPage: B.onNextPage,
63
+ onPrevPage: B.onPrevPage,
64
+ emptyState: B.emptyState,
65
+ filters: B.filters,
66
+ onRetry: L ? N : B.onRetry,
67
+ onApprove: z.onApprove,
68
+ onReject: z.onReject,
69
+ labels: i
70
+ }),
71
+ /* @__PURE__ */ S(_, {
72
+ ...z.rejectDialog,
73
+ labels: w
74
+ })
75
+ ] });
67
76
  }
68
- function C({ screenLabels: e, listLabels: t, rejectDialogLabels: n, ...i }) {
69
- return /* @__PURE__ */ b(r, {
70
- ...i,
71
- widgetName: u,
72
- children: /* @__PURE__ */ b(S, {
77
+ function T({ screenLabels: e, listLabels: t, rejectDialogLabels: n, messageLabels: r, ...a }) {
78
+ return /* @__PURE__ */ S(i, {
79
+ ...a,
80
+ widgetName: d,
81
+ children: /* @__PURE__ */ S(w, {
73
82
  screenLabels: e,
74
83
  listLabels: t,
75
- rejectDialogLabels: n
84
+ rejectDialogLabels: n,
85
+ messageLabels: r
76
86
  })
77
87
  });
78
88
  }
79
89
  //#endregion
80
- export { C as ApprovalRequestsWidget, C as default };
90
+ export { T as ApprovalRequestsWidget, T as default };
@@ -19,6 +19,11 @@ var e = {
19
19
  moreSelected: (e, t) => `${e} + ${t} more`,
20
20
  dateRange: (e, t) => `${e} - ${t}`
21
21
  }
22
+ }, t = {
23
+ approved: "Request was approved",
24
+ rejected: "Request was rejected",
25
+ approveError: "Couldn't approve the request. Try again.",
26
+ rejectError: "Couldn't reject the request. Try again."
22
27
  };
23
28
  //#endregion
24
- export { e as APPROVAL_REQUESTS_LIST_LABELS_EN };
29
+ export { e as APPROVAL_REQUESTS_LIST_LABELS_EN, t as APPROVAL_REQUESTS_MESSAGE_LABELS_EN };
@@ -2,75 +2,93 @@
2
2
  "use client";
3
3
  "use client";
4
4
  "use client";
5
- import { isOrganizationOnItsWay as e } from "../../../../../shared/data-access/dist/lib/organizationStatus.js";
6
- import { useEmbedApi as t } from "../../../../../shared/data-access/dist/lib/EmbedApiContext.js";
5
+ import { toast as e } from "../../../../../../../packages/shared-ui-shadcn/dist/index.js";
6
+ import { extractApiErrorMessage as t } from "../../../../../shared/util/dist/lib/apiErrors.js";
7
+ import "../../../../../shared/util/dist/index.js";
8
+ import { isOrganizationOnItsWay as n } from "../../../../../shared/data-access/dist/lib/organizationStatus.js";
9
+ import { useEmbedApi as r } from "../../../../../shared/data-access/dist/lib/EmbedApiContext.js";
7
10
  import "../../../../../shared/data-access/dist/index.js";
8
- import { useWidgetConfig as n, useWidgetInitStaleForToken as r } from "../../../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
11
+ import "../../../../../shared/ui/dist/index.js";
12
+ import { useWidgetConfig as i, useWidgetInitStaleForToken as a } from "../../../../../shared/feature/dist/lib/WidgetProvider/hooks.js";
9
13
  import "../../../../../shared/feature/dist/index.js";
10
- import { useApproveApprovalRequestMutation as i } from "../../../../data-access/dist/index4.js";
11
- import { useRejectApprovalRequestMutation as a } from "../../../../data-access/dist/index5.js";
14
+ import { useApproveApprovalRequestMutation as o } from "../../../../data-access/dist/index4.js";
15
+ import { useRejectApprovalRequestMutation as s } from "../../../../data-access/dist/index5.js";
12
16
  import "../../../../data-access/dist/index.js";
13
- import { useCallback as o, useState as s } from "react";
17
+ import { useCallback as c, useState as l } from "react";
14
18
  //#region ../../libs/tesouro-embedded-components-react/approval-requests-widget/feature/dist/lib/ApprovalRequestsWidget/useApprovalRequestDecisions.js
15
- var c = /* @__PURE__ */ new Set();
16
- function l() {
17
- let { mutateAsync: l } = i(), { mutateAsync: u } = a(), [d, f] = s(c), [p, m] = s(), [h, g] = s(""), { client: _, organizationId: v, organizationStatus: y } = t(), b = r(), x = e(y) || b, S = n().initResponse?.userId, C = b ? void 0 : S, [w, T] = s({
18
- client: _,
19
- organizationId: v,
20
- userId: C
19
+ var u = /* @__PURE__ */ new Set();
20
+ function d({ messages: d }) {
21
+ let { mutateAsync: f } = o(), { mutateAsync: p } = s(), [m, h] = l(u), [g, _] = l(), [v, y] = l(""), { client: b, organizationId: x, organizationStatus: S } = r(), C = a(), w = n(S) || C, T = i().initResponse?.userId, E = C ? void 0 : T, [D, O] = l({
22
+ client: b,
23
+ organizationId: x,
24
+ userId: E
21
25
  });
22
- (_ !== w.client || v !== void 0 && v !== w.organizationId || C !== void 0 && C !== w.userId) && (T({
23
- client: _,
24
- organizationId: v === void 0 ? w.organizationId : v,
25
- userId: C === void 0 ? w.userId : C
26
- }), m(void 0));
27
- let E = o(async (e, t) => {
28
- f((t) => new Set(t).add(e));
26
+ (b !== D.client || x !== void 0 && x !== D.organizationId || E !== void 0 && E !== D.userId) && (O({
27
+ client: b,
28
+ organizationId: x === void 0 ? D.organizationId : x,
29
+ userId: E === void 0 ? D.userId : E
30
+ }), _(void 0));
31
+ let k = c(async (n, { decide: r, successMessage: i, errorFallback: a }) => {
32
+ h((e) => new Set(e).add(n));
29
33
  try {
30
- return await t(), !0;
31
- } catch {
32
- return !1;
34
+ return await r(), e.success(i), !0;
35
+ } catch (n) {
36
+ return e.error(t(n) ?? a), !1;
33
37
  } finally {
34
- f((t) => {
35
- let n = new Set(t);
36
- return n.delete(e), n;
38
+ h((e) => {
39
+ let t = new Set(e);
40
+ return t.delete(n), t;
37
41
  });
38
42
  }
39
- }, []), D = o((e) => {
40
- E(e, () => l({ approvalRequestId: e }));
41
- }, [l, E]), O = o((e) => {
42
- m(e), g("");
43
- }, []), k = !!(p && d.has(p)), A = o(() => {
44
- p && !x && E(p, () => u({
45
- approvalRequestId: p,
46
- rejectReason: h
47
- })).then((e) => {
48
- e && m((e) => e === p ? void 0 : e);
43
+ }, []), A = c((e) => {
44
+ w || k(e, {
45
+ decide: () => f({ approvalRequestId: e }),
46
+ successMessage: d.approved,
47
+ errorFallback: d.approveError
49
48
  });
50
49
  }, [
51
- x,
52
- u,
53
- h,
50
+ f,
51
+ w,
52
+ d,
53
+ k
54
+ ]), j = c((e) => {
55
+ _(e), y("");
56
+ }, []), M = !!(g && m.has(g)), N = c(() => {
57
+ g && !w && k(g, {
58
+ decide: () => p({
59
+ approvalRequestId: g,
60
+ rejectReason: v
61
+ }),
62
+ successMessage: d.rejected,
63
+ errorFallback: d.rejectError
64
+ }).then((e) => {
65
+ e && _((e) => e === g ? void 0 : e);
66
+ });
67
+ }, [
68
+ w,
69
+ d,
54
70
  p,
55
- E
56
- ]), j = o(() => {
57
- k || m(void 0);
58
- }, [k]);
71
+ v,
72
+ g,
73
+ k
74
+ ]), P = c(() => {
75
+ M || _(void 0);
76
+ }, [M]);
59
77
  return {
60
- pendingRequestIds: d,
61
- areDecisionsPaused: x,
62
- onApprove: D,
63
- onReject: O,
78
+ pendingRequestIds: m,
79
+ areDecisionsPaused: w,
80
+ onApprove: A,
81
+ onReject: j,
64
82
  rejectDialog: {
65
- open: !!p,
66
- reason: h,
67
- onReasonChange: g,
68
- onConfirm: A,
69
- onCancel: j,
70
- isPending: k,
71
- isConfirmDisabled: x
83
+ open: !!g,
84
+ reason: v,
85
+ onReasonChange: y,
86
+ onConfirm: N,
87
+ onCancel: P,
88
+ isPending: M,
89
+ isConfirmDisabled: w
72
90
  }
73
91
  };
74
92
  }
75
93
  //#endregion
76
- export { l as useApprovalRequestDecisions };
94
+ export { d as useApprovalRequestDecisions };
@@ -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.44", n = "0566ca36c3657385b52cd990c71145af70b75966", r = Object.freeze({
2
+ var e = "@tesouro/embedded-components-react", t = "0.9.45", n = "0d9dec8b8927b2abd568eb61986dd26ca14843b6", 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.44",
3
+ "version": "0.9.45",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": [