@tesouro/embedded-components-react 0.5.295 → 0.5.296

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.
@@ -14,110 +14,110 @@ import { usePayableSuggestionsQuery as i } from "../../data-access/dist/index19.
14
14
  import "../../data-access/dist/index.js";
15
15
  import { resolvePaymentInstructionsGestures as a } from "./index14.js";
16
16
  import { COUNTERPART_MESSAGE_LABELS_EN as o } from "../../../../shared/counterpart-management/feature/dist/lib/labels.js";
17
- import { counterpartFormBankAccountToCreatePayload as te, counterpartFormBankAccountToUpdatePayload as ne, getAchInstructions as s, getCounterpartEmail as c, getCounterpartName as l, getPayableAchInstructions as re, isAchCompatibleBankAccount as u, resolveCounterpartBankAccountWrite as ie, validateAchFormValues as ae } from "../../../../shared/counterpart-management/feature/dist/lib/helpers.js";
18
- import { useCounterpartsQuery as oe } from "../../../../shared/counterpart-management/data-access/dist/index3.js";
19
- import { useCreateCounterpartBankAccountMutation as se, useUpdateCounterpartBankAccountMutation as ce } from "../../../../shared/counterpart-management/data-access/dist/index5.js";
20
- import { useCounterpartDetails as le } from "../../../../shared/counterpart-management/feature/dist/lib/useCounterpartDetails.js";
21
- import { useCounterpartForm as ue } from "../../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
17
+ import { counterpartFormBankAccountToCreatePayload as te, counterpartFormBankAccountToUpdatePayload as ne, getAchInstructions as s, getCounterpartEmail as c, getCounterpartName as re, getPayableAchInstructions as ie, hasCounterpartFormErrors as ae, isAchCompatibleBankAccount as l, resolveCounterpartBankAccountWrite as oe, validateAchFormValues as se, validateCounterpartForm as ce } from "../../../../shared/counterpart-management/feature/dist/lib/helpers.js";
18
+ import { useCounterpartsQuery as le } from "../../../../shared/counterpart-management/data-access/dist/index3.js";
19
+ import { useCreateCounterpartBankAccountMutation as ue, useUpdateCounterpartBankAccountMutation as de } from "../../../../shared/counterpart-management/data-access/dist/index5.js";
20
+ import { useCounterpartDetails as fe } from "../../../../shared/counterpart-management/feature/dist/lib/useCounterpartDetails.js";
21
+ import { useCounterpartForm as pe } from "../../../../shared/counterpart-management/feature/dist/lib/useCounterpartForm.js";
22
22
  import "../../../../shared/counterpart-management/feature/dist/index.js";
23
- import { buildVendorPrefill as de, canAutoCreateVendor as fe } from "./index27.js";
24
- import { VendorInlineForm as pe } from "./index28.js";
25
- import { useCallback as d, useEffect as f, useLayoutEffect as me, useMemo as p, useRef as m, useState as h } from "react";
26
- import { jsx as he } from "react/jsx-runtime";
23
+ import { buildVendorPrefill as me, canAutoCreateVendor as he, toCounterpartRawData as ge } from "./index27.js";
24
+ import { VendorInlineForm as _e } from "./index28.js";
25
+ import { useCallback as u, useEffect as d, useLayoutEffect as ve, useMemo as f, useRef as p, useState as m } from "react";
26
+ import { jsx as ye } from "react/jsx-runtime";
27
27
  //#region ../../libs/tesouro-embedded-components-react/bill-pay-widget/bill-detail/feature/dist/index29.js
28
- var ge = 10, _e = 300, g = {
28
+ var be = 10, xe = 300, h = {
29
29
  accountHolderName: "",
30
30
  routingNumber: "",
31
31
  accountNumber: ""
32
32
  };
33
- function ve(e) {
33
+ function Se(e) {
34
34
  return {
35
35
  accountHolderName: e.account_holder_name ?? "",
36
36
  routingNumber: e.routing_number ?? "",
37
37
  accountNumber: e.account_number ?? ""
38
38
  };
39
39
  }
40
- function _(e, t) {
40
+ function g(e, t) {
41
41
  return e.accountHolderName.trim() === t.accountHolderName.trim() && e.routingNumber.trim() === t.routingNumber.trim() && e.accountNumber.trim() === t.accountNumber.trim();
42
42
  }
43
- function ye(e, t) {
44
- return e?.find((e) => e.id === t && u(e)) ?? s(e);
43
+ function Ce(e, t) {
44
+ return e?.find((e) => e.id === t && l(e)) ?? s(e);
45
45
  }
46
- function v({ payableId: s, counterpartId: u, payableCounterpartId: v, payableCounterpartBankAccountId: be, isVendorKnown: xe = !0, onCounterpartChange: Se, requiredError: Ce, extractedVendor: y, readOnly: b = !1, canEditVendor: x = !0, canEditPaymentInstructions: we = !0, canAddPaymentInstructions: Te = !0, confirmDiscard: S = (e) => e(), labels: Ee }) {
47
- let C = {
46
+ function _({ payableId: s, counterpartId: l, payableCounterpartId: _, payableCounterpartBankAccountId: we, isVendorKnown: Te = !0, onCounterpartChange: Ee, requiredError: De, extractedVendor: v, readOnly: y = !1, canEditVendor: b = !0, canEditPaymentInstructions: Oe = !0, canAddPaymentInstructions: ke = !0, confirmDiscard: x = (e) => e(), labels: Ae }) {
47
+ let S = {
48
48
  ...r,
49
- ...Ee
50
- }, De = Ee?.messages, Oe = p(() => ({
49
+ ...Ae
50
+ }, je = Ae?.messages, C = f(() => ({
51
51
  ...o,
52
- ...De
53
- }), [De]), { initResponse: ke } = n(), Ae = t(ke?.scopes, [ee.CounterpartReadOrg]), [w, je] = h(""), [T, Me] = h(""), Ne = m(T), [E, Pe] = h(), [Fe, Ie] = h("none"), [Le, Re] = h(), [ze, D] = h(!1), [O, k] = h(!1), [A, j] = h(g), Be = m(A);
54
- Be.current = A;
55
- let M = m(g), [Ve, N] = h(), [He, Ue] = h(), We = He?.bankAccountId, P = m(void 0), Ge = m(u), [Ke, qe] = h(!1), [Je, Ye] = h(!1), Xe = m(void 0), F = d(() => {
56
- k(!1), j(g), M.current = g, N(void 0);
57
- }, []), I = d((e) => {
58
- qe(!0), Se(e);
59
- }, [Se]), Ze = i(s, { enabled: !b && !!s && !u && !v }), L = Ze.data?.suggested_counterpart?.id, Qe = y?.name;
60
- f(() => {
61
- !b && !Ke && !u && !v && L && I(L);
52
+ ...je
53
+ }), [je]), { initResponse: Me } = n(), Ne = t(Me?.scopes, [ee.CounterpartReadOrg]), [w, Pe] = m(""), [T, Fe] = m(""), Ie = p(T), [E, Le] = m(), [Re, ze] = m("none"), [Be, Ve] = m(), [He, D] = m(!1), [O, k] = m(!1), [A, Ue] = m(h), j = p(A);
54
+ j.current = A;
55
+ let M = p(h), [We, N] = m(), [Ge, Ke] = m(), qe = Ge?.bankAccountId, P = p(void 0), Je = p(l), [Ye, Xe] = m(!1), [Ze, Qe] = m(!1), F = p(void 0), I = u(() => {
56
+ k(!1), Ue(h), M.current = h, N(void 0);
57
+ }, []), L = u((e) => {
58
+ Xe(!0), Ee(e);
59
+ }, [Ee]), $e = i(s, { enabled: !y && !!s && !l && !_ }), R = $e.data?.suggested_counterpart?.id, et = v?.name;
60
+ d(() => {
61
+ !y && !Ye && !l && !_ && R && L(R);
62
62
  }, [
63
- u,
64
- v,
65
- b,
66
- Ke,
67
- L,
68
- I
69
- ]), f(() => {
70
- Ge.current !== u && (Ge.current = u, F(), Ue((e) => e?.counterpartId === u ? e : void 0));
71
- }, [u, F]), f(() => {
63
+ l,
64
+ _,
65
+ y,
66
+ Ye,
67
+ R,
68
+ L
69
+ ]), d(() => {
70
+ Je.current !== l && (Je.current = l, I(), Ke((e) => e?.counterpartId === l ? e : void 0));
71
+ }, [l, I]), d(() => {
72
72
  let e = setTimeout(() => {
73
- Me(w.trim());
74
- }, _e);
73
+ Fe(w.trim());
74
+ }, xe);
75
75
  return () => clearTimeout(e);
76
76
  }, [w]);
77
- let R = p(() => de(y), [y]), z = R?.bankAccount, B = p(() => fe(y), [y]), $e = E === "create" ? !_(A, z ?? g) : O && !_(A, M.current), et = !b && (E === "edit" || E === "create" && !!R), V = oe({
77
+ let z = f(() => me(v), [v]), B = z?.bankAccount, tt = f(() => he(v), [v]), nt = E === "create" ? !g(A, B ?? h) : O && !g(A, M.current), rt = !y && (E === "edit" || E === "create" && !!z), V = le({
78
78
  sort: "counterpart_name",
79
79
  order: "asc",
80
- limit: ge,
80
+ limit: be,
81
81
  counterpart_name__icontains: T || void 0,
82
82
  is_vendor: !0,
83
- enabled: (et || !b && !E && !u) && xe && Ae
83
+ enabled: (rt || !y && !E && !l) && Te && Ne
84
84
  });
85
- f(() => {
86
- V.isPlaceholderData || (Ne.current = T);
85
+ d(() => {
86
+ V.isPlaceholderData || (Ie.current = T);
87
87
  }, [T, V.isPlaceholderData]);
88
- let tt = V.isPlaceholderData && Ne.current !== T, H = le({
89
- selectedId: u,
90
- enabled: Ae
91
- }), nt = se(), rt = ce(), U = ue({
92
- view: Fe,
93
- setView: Ie,
94
- selectedId: Le,
95
- setSelectedId: Re,
96
- messages: Oe,
88
+ let it = V.isPlaceholderData && Ie.current !== T, H = fe({
89
+ selectedId: l,
90
+ enabled: Ne
91
+ }), at = ue(), ot = de(), U = pe({
92
+ view: Re,
93
+ setView: ze,
94
+ selectedId: Be,
95
+ setSelectedId: Ve,
96
+ messages: C,
97
97
  counterpartType: "vendor",
98
98
  counterpart: H.counterpart,
99
99
  primaryAddress: H.primaryAddress,
100
100
  includeBankAccount: !1
101
- }), { openCreate: it, openEdit: at, close: ot, setValues: W, submit: st } = U, G = p(() => {
101
+ }), { openCreate: st, openEdit: ct, close: lt, setValues: W, submit: ut, values: dt } = U, G = f(() => {
102
102
  let e = H.counterpart;
103
103
  if (!e) return;
104
104
  if (H.isBankAccountsLoading) return {
105
- name: l(e),
105
+ name: re(e),
106
106
  email: c(e),
107
- methodLabel: C.paymentMethodLoading,
107
+ methodLabel: S.paymentMethodLoading,
108
108
  hasPaymentInstructions: !1
109
109
  };
110
110
  if (H.isBankAccountsError) return {
111
- name: l(e),
111
+ name: re(e),
112
112
  email: c(e),
113
- methodLabel: C.paymentMethodUnavailable,
113
+ methodLabel: S.paymentMethodUnavailable,
114
114
  hasPaymentInstructions: !1
115
115
  };
116
- let t = re(H.bankAccounts);
116
+ let t = ie(H.bankAccounts);
117
117
  return {
118
- name: l(e),
118
+ name: re(e),
119
119
  email: c(e),
120
- methodLabel: t ? C.paymentInstructionsValue(t.account_number?.slice(-4) ?? "") : C.noMethod,
120
+ methodLabel: t ? S.paymentInstructionsValue(t.account_number?.slice(-4) ?? "") : S.noMethod,
121
121
  hasPaymentInstructions: !!t
122
122
  };
123
123
  }, [
@@ -125,108 +125,126 @@ function v({ payableId: s, counterpartId: u, payableCounterpartId: v, payableCou
125
125
  H.counterpart,
126
126
  H.isBankAccountsError,
127
127
  H.isBankAccountsLoading,
128
- C
129
- ]), K = p(() => {
130
- let e = Qe?.trim();
131
- if (!e || u || E) return;
132
- let t = z?.accountNumber;
128
+ S
129
+ ]), K = f(() => {
130
+ let e = et?.trim();
131
+ if (!e || l || E) return;
132
+ let t = B?.accountNumber;
133
133
  return {
134
134
  name: e,
135
- email: y?.email ?? "",
136
- description: B ? C.pendingVendorDescription : C.pendingVendorIncompleteDescription,
137
- methodLabel: t ? C.paymentInstructionsValue(t.slice(-4)) : "",
135
+ email: v?.email ?? "",
136
+ description: tt ? S.pendingVendorDescription : S.pendingVendorIncompleteDescription,
137
+ methodLabel: t ? S.paymentInstructionsValue(t.slice(-4)) : "",
138
138
  hasPaymentInstructions: !!t
139
139
  };
140
140
  }, [
141
- u,
142
- z?.accountNumber,
143
- y?.email,
144
- Qe,
141
+ l,
142
+ B?.accountNumber,
143
+ v?.email,
144
+ et,
145
145
  E,
146
- B,
147
- C.paymentInstructionsValue,
148
- C.pendingVendorDescription,
149
- C.pendingVendorIncompleteDescription
150
- ]), ct = !!K && !B, q = u === v ? be : void 0, J = p(() => ye(H.bankAccounts, q), [H.bankAccounts, q]), lt = p(() => re(H.bankAccounts)?.id, [H.bankAccounts]), ut = !H.counterpart || H.isLoading || H.isFetching || H.isError || H.isBankAccountsLoading || H.isBankAccountsFetching || H.isBankAccountsError, dt = ut || H.isAddressesLoading || H.isAddressesFetching || H.isAddressesError, ft = x && !ut && H.isAddressesError ? { onRetry: H.refetchAddresses } : void 0, Y = d(() => {
151
- ot(), Pe(void 0), D(!1), P.current = void 0;
152
- }, [ot]), X = d((e) => {
153
- if (D(!1), P.current = void 0, e === "edit") Re(u), at();
146
+ tt,
147
+ S.paymentInstructionsValue,
148
+ S.pendingVendorDescription,
149
+ S.pendingVendorIncompleteDescription
150
+ ]), ft = !!K && !tt, q = l === _ ? we : void 0, J = f(() => Ce(H.bankAccounts, q), [H.bankAccounts, q]), pt = f(() => ie(H.bankAccounts)?.id, [H.bankAccounts]), mt = !H.counterpart || H.isLoading || H.isFetching || H.isError || H.isBankAccountsLoading || H.isBankAccountsFetching || H.isBankAccountsError, ht = mt || H.isAddressesLoading || H.isAddressesFetching || H.isAddressesError, gt = b && !mt && H.isAddressesError ? { onRetry: H.refetchAddresses } : void 0, Y = u(() => {
151
+ lt(), Le(void 0), D(!1), P.current = void 0;
152
+ }, [lt]), X = u((e) => {
153
+ if (D(!1), P.current = void 0, e === "edit") Ve(l), ct();
154
154
  else {
155
- it();
155
+ st();
156
156
  let e = w.trim();
157
157
  W((t) => ({
158
158
  ...t,
159
159
  entityType: "organization",
160
- legalName: e || R?.legalName || t.legalName,
161
- email: R?.email || t.email,
162
- phone: R?.phone || t.phone,
163
- address: R?.address ?? t.address
164
- })), j(z ?? g), N(void 0), M.current = g;
160
+ legalName: e || z?.legalName || t.legalName,
161
+ email: z?.email || t.email,
162
+ phone: z?.phone || t.phone,
163
+ address: z?.address ?? t.address
164
+ })), Ue(B ?? h), N(void 0), M.current = h;
165
165
  }
166
- Pe(e);
166
+ Le(e);
167
167
  }, [
168
- u,
169
- z,
170
- it,
171
- at,
168
+ l,
169
+ B,
170
+ st,
171
+ ct,
172
172
  w,
173
173
  W,
174
- R
175
- ]), pt = U.revealErrors, mt = d(() => {
176
- qe(!0), X("create"), pt();
177
- let e = z ? ae(z) : {};
174
+ z
175
+ ]), _t = U.revealErrors, vt = u(() => {
176
+ Xe(!0), X("create"), _t();
177
+ let e = B ? se(B, C) : {};
178
178
  Object.keys(e).length && N(e);
179
179
  }, [
180
- z,
180
+ B,
181
+ C,
181
182
  X,
182
- pt
183
- ]), ht = m(!1), gt = !ht.current && !b && x && xe && !v && !L && !Ke && ct, _t = gt && !Ze.isLoading;
184
- me(() => {
185
- _t && (ht.current = !0, mt());
186
- }, [mt, _t]);
187
- let vt = d(() => {
188
- let e = J ? ve(J) : g;
189
- M.current = e, j(e), N(void 0), k(!0);
190
- }, [J]), yt = d((e) => {
191
- j((t) => ({
192
- ...t,
183
+ _t
184
+ ]), yt = p(!1), bt = !yt.current && !y && b && Te && !_ && !R && !Ye && ft, xt = bt && !$e.isLoading;
185
+ ve(() => {
186
+ xt && (yt.current = !0, vt());
187
+ }, [vt, xt]);
188
+ let St = u(() => {
189
+ let e = J ? Se(J) : h;
190
+ M.current = e, Ue(e), N(void 0), k(!0);
191
+ }, [J]), Ct = u((e) => {
192
+ let t = {
193
+ ...j.current,
193
194
  ...e
194
- })), N(void 0);
195
- }, []), bt = d(() => {
196
- $e ? S(F) : F();
195
+ };
196
+ j.current = t, Ue(t);
197
+ let ee = se(t, C);
198
+ N((e) => {
199
+ if (!e) return e;
200
+ let t = { ...e };
201
+ for (let e of Object.keys(t)) ee[e] || delete t[e];
202
+ return Object.keys(t).length ? t : void 0;
203
+ });
204
+ }, [C]), wt = u(() => {
205
+ nt ? x(I) : I();
197
206
  }, [
198
- F,
199
- S,
200
- $e
201
- ]), Z = d(() => {
202
- Y(), F();
203
- }, [F, Y]), Q = ze || $e, $ = d((e) => {
207
+ I,
208
+ x,
209
+ nt
210
+ ]), Z = u(() => {
211
+ Y(), I();
212
+ }, [I, Y]), Q = He || nt, $ = u((e) => {
204
213
  let t = () => {
205
214
  Z(), e();
206
215
  };
207
- Q ? S(t) : t();
216
+ Q ? x(t) : t();
208
217
  }, [
209
- S,
218
+ x,
210
219
  Z,
211
220
  Q
212
- ]), xt = d(() => {
213
- Q ? S(Z) : Z();
221
+ ]), Tt = u(() => {
222
+ Q ? x(Z) : Z();
214
223
  }, [
215
- S,
224
+ x,
216
225
  Z,
217
226
  Q
218
- ]), St = d(async ({ closeOnSuccess: t = !0, allowIncompleteVendor: ee = !1 } = {}) => {
219
- if (ee && E === "create" && !ze && _(Be.current, z ?? g) && !B) return { ok: !0 };
220
- let n = u, r = !1, i = Be.current;
221
- if (!_(i, M.current)) {
222
- let e = ae(i, Oe);
227
+ ]), Et = u(async ({ closeOnSuccess: t = !0, allowIncompleteVendor: ee = !1 } = {}) => {
228
+ if (ee && E === "create" && !P.current) {
229
+ let e = j.current, t = ce({
230
+ ...dt,
231
+ bankAccount: e
232
+ }, "create", C, "vendor");
233
+ if (ae(t)) return He || !g(e, B ?? h) ? {
234
+ ok: !0,
235
+ counterpartRawData: ge(dt, e, v)
236
+ } : { ok: !0 };
237
+ }
238
+ let n = l, r = !1, i = j.current;
239
+ if (!g(i, M.current)) {
240
+ let e = se(i, C);
223
241
  if (Object.keys(e).length > 0) return N(e), E !== "create" && k(!0), { ok: !1 };
224
242
  }
225
- if (E === "edit" && dt) return { ok: !1 };
243
+ if (E === "edit" && ht) return { ok: !1 };
226
244
  if (E) {
227
245
  if (E === "create" && P.current) n = P.current;
228
246
  else {
229
- let e = await st();
247
+ let e = await ut();
230
248
  if (!e.ok) return { ok: !1 };
231
249
  E === "create" ? (n = e.counterpartId, P.current = n) : n = e.counterpartId ?? n;
232
250
  }
@@ -234,94 +252,95 @@ function v({ payableId: s, counterpartId: u, payableCounterpartId: v, payableCou
234
252
  }
235
253
  if (!n) return { ok: !0 };
236
254
  let a = H.isBankAccountsLoading || H.isBankAccountsFetching || H.isBankAccountsError;
237
- if (_(i, M.current)) {
238
- let e = We ?? q;
239
- return e ? (t && (k(!1), E && Y()), r && I(n), {
255
+ if (g(i, M.current)) {
256
+ let e = qe ?? q;
257
+ return e ? (t && (k(!1), E && Y()), r && L(n), {
240
258
  ok: !0,
241
259
  counterpartId: n,
242
260
  counterpartBankAccountId: e
243
- }) : r ? (t && Y(), I(n), {
261
+ }) : r ? (t && Y(), L(n), {
244
262
  ok: !0,
245
263
  counterpartId: n
246
264
  }) : a ? { ok: !1 } : (t && (k(!1), E && Y()), {
247
265
  ok: !0,
248
266
  counterpartId: n,
249
- counterpartBankAccountId: lt
267
+ counterpartBankAccountId: pt
250
268
  });
251
269
  }
252
270
  if (a) return { ok: !1 };
253
271
  N(void 0);
254
- let o = ie(H.bankAccounts, We ?? J?.id), s;
272
+ let o = oe(H.bankAccounts, qe ?? J?.id), s;
255
273
  try {
256
- o.kind === "update" ? (await rt.mutateAsync({
274
+ o.kind === "update" ? (await ot.mutateAsync({
257
275
  path: {
258
276
  counterpart_id: n,
259
277
  bank_account_id: o.bankAccountId
260
278
  },
261
279
  body: ne(i, { includeAchDefaults: o.includeAchDefaults })
262
- }), s = o.bankAccountId) : s = (await nt.mutateAsync({
280
+ }), s = o.bankAccountId) : s = (await at.mutateAsync({
263
281
  path: { counterpart_id: n },
264
282
  body: te(i, { isDefaultForCurrency: o.isDefaultForCurrency })
265
283
  }))?.id;
266
284
  } catch {
267
- return e.error(C.bankAccountSaveFailed), {
285
+ return e.error(S.bankAccountSaveFailed), {
268
286
  ok: !1,
269
287
  counterpartId: n
270
288
  };
271
289
  }
272
- return M.current = i, Ue(s ? {
290
+ return M.current = i, Ke(s ? {
273
291
  counterpartId: n,
274
292
  bankAccountId: s
275
- } : void 0), t && (k(!1), E && Y()), r && I(n), {
293
+ } : void 0), t && (k(!1), E && Y()), r && L(n), {
276
294
  ok: !0,
277
295
  counterpartId: n,
278
296
  counterpartBankAccountId: s
279
297
  };
280
298
  }, [
281
299
  Y,
282
- u,
283
- nt,
300
+ l,
301
+ at,
284
302
  H.bankAccounts,
285
303
  H.isBankAccountsError,
286
304
  H.isBankAccountsFetching,
287
305
  H.isBankAccountsLoading,
288
- z,
289
- E,
290
306
  B,
291
- ze,
307
+ v,
308
+ E,
292
309
  dt,
310
+ He,
311
+ ht,
293
312
  q,
294
- Oe,
295
- lt,
296
- I,
313
+ C,
314
+ pt,
315
+ L,
297
316
  J,
298
- st,
299
- rt,
300
- We
301
- ]), Ct = d((e) => {
302
- if (Xe.current) return Xe.current;
317
+ ut,
318
+ ot,
319
+ qe
320
+ ]), Dt = u((e) => {
321
+ if (F.current) return F.current;
303
322
  let t = (async () => {
304
- Ye(!0);
323
+ Qe(!0);
305
324
  try {
306
- return await St(e);
325
+ return await Et(e);
307
326
  } finally {
308
- Xe.current = void 0, Ye(!1);
327
+ F.current = void 0, Qe(!1);
309
328
  }
310
329
  })();
311
- return Xe.current = t, t;
312
- }, [St]), wt = d(() => {
330
+ return F.current = t, t;
331
+ }, [Et]), Ot = u(() => {
313
332
  k(!1), E && Y();
314
- }, [E, Y]), Tt = p(() => (V.data?.data ?? []).map((e) => ({
315
- name: l(e),
333
+ }, [E, Y]), kt = f(() => (V.data?.data ?? []).map((e) => ({
334
+ name: re(e),
316
335
  email: c(e),
317
336
  onSelect: () => {
318
- $(() => I(e.id));
337
+ $(() => L(e.id));
319
338
  }
320
339
  })), [
321
340
  V.data,
322
341
  $,
323
- I
324
- ]), Et = d((e) => {
342
+ L
343
+ ]), At = u((e) => {
325
344
  D(!0), W((t) => e.entityType === "individual" && t.entityType !== "individual" ? {
326
345
  ...t,
327
346
  ...e,
@@ -335,7 +354,7 @@ function v({ payableId: s, counterpartId: u, payableCounterpartId: v, payableCou
335
354
  ...t,
336
355
  ...e
337
356
  });
338
- }, [W]), Dt = d((e) => {
357
+ }, [W]), jt = u((e) => {
339
358
  D(!0), W((t) => ({
340
359
  ...t,
341
360
  address: {
@@ -343,89 +362,101 @@ function v({ payableId: s, counterpartId: u, payableCounterpartId: v, payableCou
343
362
  ...e
344
363
  }
345
364
  }));
346
- }, [W]), Ot = {
365
+ }, [W]), Mt = {
347
366
  query: w,
348
- onQueryChange: je,
349
- isLoading: gt || !xe || !ke || !!u && H.isLoading || V.isLoading || V.isFetching && tt,
367
+ onQueryChange: Pe,
368
+ isLoading: bt || !Te || !Me || !!l && H.isLoading || V.isLoading || V.isFetching && it,
350
369
  onAddVendor: () => {
370
+ if (E === "create") {
371
+ let e = w.trim(), [t, ...ee] = e.split(/\s+/);
372
+ W((n) => n.entityType === "individual" ? {
373
+ ...n,
374
+ firstName: t,
375
+ lastName: ee.join(" ")
376
+ } : {
377
+ ...n,
378
+ legalName: e
379
+ }), D(!0);
380
+ return;
381
+ }
351
382
  $(() => X("create"));
352
383
  },
353
- results: Tt
354
- }, kt = Te && (E === "create" || !ut) ? {
384
+ results: kt
385
+ }, Nt = ke && (E === "create" || !mt) ? {
355
386
  isOpen: O,
356
387
  values: A,
357
- errors: Ve,
358
- onOpen: vt,
359
- onCancel: bt,
360
- onChange: yt
361
- } : void 0, At = E !== "create" && kt ? {
362
- ...kt,
363
- onOpen: E === "edit" ? () => $(vt) : kt.onOpen,
364
- canEditExisting: we
365
- } : void 0, jt = U.isSubmitting || nt.isPending || rt.isPending, Mt = {
366
- prepareVendorForSave: Ct,
367
- isVendorSavePending: Je || jt,
388
+ errors: We,
389
+ onOpen: St,
390
+ onCancel: wt,
391
+ onChange: Ct
392
+ } : void 0, Pt = E !== "create" && Nt ? {
393
+ ...Nt,
394
+ onOpen: E === "edit" ? () => $(St) : Nt.onOpen,
395
+ canEditExisting: Oe
396
+ } : void 0, Ft = U.isSubmitting || at.isPending || ot.isPending, It = {
397
+ prepareVendorForSave: Dt,
398
+ isVendorSavePending: Ze || Ft,
368
399
  hasUnsavedVendorChanges: Q,
369
- isPendingVendor: !!K && !ct,
370
- revealIncompleteVendor: ct ? mt : void 0,
400
+ isPendingVendor: !!K && !ft,
401
+ revealIncompleteVendor: ft ? vt : void 0,
371
402
  isEditingPayTo: !!E || O,
372
403
  activePayToOperation: E ? "vendor" : O ? G?.hasPaymentInstructions ? "existingInstructions" : "missingInstructions" : void 0,
373
404
  discardPayToEdits: Z,
374
- finalizePayToSave: wt,
375
- openPaymentInstructions: vt,
376
- paymentInstructions: a(At, !!G?.hasPaymentInstructions),
377
- paymentInstructionsEditor: At,
378
- detailsWarning: ft
379
- }, Nt = E === "create" && Te ? {
405
+ finalizePayToSave: Ot,
406
+ openPaymentInstructions: St,
407
+ paymentInstructions: a(Pt, !!G?.hasPaymentInstructions),
408
+ paymentInstructionsEditor: Pt,
409
+ detailsWarning: gt
410
+ }, Lt = E === "create" && ke ? {
380
411
  values: A,
381
- errors: Ve,
382
- onChange: yt,
383
- isExtracted: !!(z && _(A, z))
412
+ errors: We,
413
+ onChange: Ct,
414
+ isExtracted: !!(B && g(A, B))
384
415
  } : void 0;
385
416
  if (E) return {
386
417
  mode: "creating",
387
418
  summary: G,
388
- newVendorForm: /* @__PURE__ */ he(pe, {
419
+ newVendorForm: /* @__PURE__ */ ye(_e, {
389
420
  mode: E,
390
421
  values: U.values,
391
422
  errors: U.errors,
392
- onChange: Et,
393
- onAddressChange: Dt,
423
+ onChange: At,
424
+ onAddressChange: jt,
394
425
  sectionsToExpand: U.sectionsToExpand,
395
426
  onAddressExpand: U.expandAddress,
396
- onCancel: xt,
397
- onSave: Ct,
398
- isSaving: jt,
399
- search: et ? Ot : void 0,
400
- paymentInstructions: Nt,
401
- labels: Ee?.inlineForm
427
+ onCancel: Tt,
428
+ onSave: Dt,
429
+ isSaving: Ft,
430
+ search: rt ? Mt : void 0,
431
+ paymentInstructions: Lt,
432
+ labels: Ae?.inlineForm
402
433
  }),
403
- ...Mt
434
+ ...It
404
435
  };
405
436
  if (G) return {
406
437
  mode: "resolved",
407
438
  summary: G,
408
- onEdit: x && !dt ? () => $(() => X("edit")) : void 0,
409
- ...Mt
439
+ onEdit: b && !ht ? () => $(() => X("edit")) : void 0,
440
+ ...It
410
441
  };
411
- if (K && !gt) {
442
+ if (K && !bt) {
412
443
  let e = () => $(() => {
413
- qe(!0), X("create");
414
- }), t = x && Te ? {
444
+ Xe(!0), X("create");
445
+ }), t = b && ke ? {
415
446
  isOpen: !1,
416
447
  values: A,
417
- errors: Ve,
448
+ errors: We,
418
449
  onOpen: e,
419
- onChange: yt,
420
- onCancel: bt,
450
+ onChange: Ct,
451
+ onCancel: wt,
421
452
  canEditExisting: !0
422
453
  } : void 0;
423
454
  return {
424
455
  mode: "resolved",
425
456
  summary: K,
426
- onEdit: x ? e : void 0,
427
- error: Ce,
428
- ...Mt,
457
+ onEdit: b ? e : void 0,
458
+ error: De,
459
+ ...It,
429
460
  showPaymentInstructions: !0,
430
461
  paymentInstructions: a(t, K.hasPaymentInstructions),
431
462
  paymentInstructionsEditor: t
@@ -433,10 +464,10 @@ function v({ payableId: s, counterpartId: u, payableCounterpartId: v, payableCou
433
464
  }
434
465
  return {
435
466
  mode: "selecting",
436
- error: V.isError ? C.searchFailed : H.isError ? C.vendorDetailsFailed : Ce,
437
- search: Ot,
438
- ...Mt
467
+ error: V.isError ? S.searchFailed : H.isError ? S.vendorDetailsFailed : De,
468
+ search: Mt,
469
+ ...It
439
470
  };
440
471
  }
441
472
  //#endregion
442
- export { v as useVendorSectionProps };
473
+ export { _ as useVendorSectionProps };