@credithub/harlan-components 1.116.1 → 1.116.2

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.
@@ -83,7 +83,7 @@ export var useInstrumento = function (_a) {
83
83
  res = _a.sent();
84
84
  setEmailTitle('Instrumento solicitado por e-mail');
85
85
  setEmailMessage((res === null || res === void 0 ? void 0 : res.message) ||
86
- 'Solicitação registrada. Vamos processar o instrumento e também agregar as informações do credor quando possível. Em alguns minutos, refaça a consulta de hoje para atualizar os dados.');
86
+ 'Pedido registrado.\n\nAgora é aguardar: vamos tentar obter o instrumento e enviar por e-mail. Isso pode levar alguns minutos.\n\nApós identificar o instrumento, também vamos identificar o credor (quem protestou).');
87
87
  setIsSuccess(true);
88
88
  setIsEmailModalOpen(true);
89
89
  setIsModalSPOpen(false);
@@ -119,7 +119,7 @@ export var useInstrumento = function (_a) {
119
119
  res = _a.sent();
120
120
  setEmailTitle('Solicitação enviada');
121
121
  setEmailMessage((res === null || res === void 0 ? void 0 : res.message) ||
122
- 'Solicitação registrada. Vamos processar o instrumento e também agregar as informações do credor quando possível. Em alguns minutos, refaça a consulta de hoje para atualizar os dados.');
122
+ 'Pedido registrado.\n\nAgora é aguardar: vamos tentar obter o instrumento e enviar por e-mail. Isso pode levar alguns minutos.\n\nQuando possível, também vamos identificar o credor (quem protestou).');
123
123
  setIsSuccess(true);
124
124
  setIsEmailModalOpen(true);
125
125
  return [3 /*break*/, 5];
@@ -7,4 +7,4 @@ export declare const ProtestoItem: React.MemoExoticComponent<({ protesto, showIn
7
7
  export declare const Instrumento: ({ nm_chave, cpfCnpj }: {
8
8
  nm_chave?: string;
9
9
  cpfCnpj?: string;
10
- }) => React.JSX.Element | null;
10
+ }) => React.JSX.Element;
@@ -1,14 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -45,17 +34,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
35
  }
47
36
  };
48
- var __rest = (this && this.__rest) || function (s, e) {
49
- var t = {};
50
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
- t[p] = s[p];
52
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
- t[p[i]] = s[p[i]];
56
- }
57
- return t;
58
- };
59
37
  import { useGlobalData } from '../../contexts/globalDataContext';
60
38
  import { formatMoney } from '../../utils/number';
61
39
  import { isProtestoSPByNmChave } from '../../utils/protestoUf';
@@ -65,7 +43,7 @@ import AddItemField from '../common/addItem';
65
43
  import Button from '../common/button';
66
44
  import ModalInstrumentoProtestoSP from '../common/modalInstrumentoProtestoSP';
67
45
  import { ResultContent } from '../interface/result';
68
- import { Queries, WebService } from '../webservice';
46
+ import { WebService } from '../webservice';
69
47
  import InstrumentoDiscoveryConfirmModal from './instrumento/InstrumentoDiscoveryConfirmModal';
70
48
  import InstrumentoEmailStatusModal from './instrumento/InstrumentoEmailStatusModal';
71
49
  import { useInstrumento } from './instrumento/useInstrumento';
@@ -244,9 +222,6 @@ export var ProtestoItem = memo(function (_a) {
244
222
  export var Instrumento = function (_a) {
245
223
  var nm_chave = _a.nm_chave, cpfCnpj = _a.cpfCnpj;
246
224
  var client = useContext(WebService);
247
- var ctxProtestos = useContext(Queries.Protestos);
248
- var _b = useGlobalData(), setData = _b.setData, globalData = _b.data;
249
- var protestosData = (globalData === null || globalData === void 0 ? void 0 : globalData.protestosData) || {};
250
225
  var normalizedKey = useMemo(function () { return normalizeInstrumentKey(nm_chave); }, [nm_chave]);
251
226
  // Hook para gerenciar fluxo de instrumento (fase mockada)
252
227
  var instrumentoHook = useInstrumento({
@@ -254,10 +229,9 @@ export var Instrumento = function (_a) {
254
229
  cpfCnpj: cpfCnpj || '',
255
230
  client: client
256
231
  });
257
- if (!nm_chave)
258
- return null;
259
232
  var hasCpfCnpj = Boolean(cpfCnpj && cpfCnpj.trim() !== '');
260
233
  var isValidKey = useMemo(function () { return isInstrumentKeyValid(nm_chave); }, [nm_chave]);
234
+ var hasKey = Boolean(normalizedKey);
261
235
  var classifyInstrumentError = function (err) {
262
236
  var rawMessage = err instanceof Error ? err.message : String(err !== null && err !== void 0 ? err : '').toString();
263
237
  if (/chave.+inv[aá]lid/i.test(rawMessage) ||
@@ -267,30 +241,51 @@ export var Instrumento = function (_a) {
267
241
  return 'missing-doc';
268
242
  };
269
243
  var deriveErrorKind = useCallback(function () {
244
+ if (!hasKey)
245
+ return 'missing-key';
270
246
  if (!hasCpfCnpj)
271
247
  return 'missing-doc';
272
248
  if (!isValidKey)
273
249
  return 'invalid-key';
274
250
  return null;
275
- }, [hasCpfCnpj, isValidKey]);
276
- var _c = useState(deriveErrorKind), errorKind = _c[0], setErrorKind = _c[1];
277
- var _d = useState(false), isLoading = _d[0], setIsLoading = _d[1];
278
- var _e = useState(false), isDiscoveryConfirmOpen = _e[0], setIsDiscoveryConfirmOpen = _e[1];
251
+ }, [hasKey, hasCpfCnpj, isValidKey]);
252
+ var _b = useState(deriveErrorKind), errorKind = _b[0], setErrorKind = _b[1];
253
+ var _c = useState(false), isLoading = _c[0], setIsLoading = _c[1];
254
+ var _d = useState(false), isDiscoveryConfirmOpen = _d[0], setIsDiscoveryConfirmOpen = _d[1];
255
+ var _e = useState(false), isMissingKeyLoading = _e[0], setIsMissingKeyLoading = _e[1];
279
256
  useEffect(function () {
280
257
  setErrorKind(deriveErrorKind());
281
258
  }, [deriveErrorKind]);
259
+ useEffect(function () {
260
+ if (errorKind !== 'missing-key') {
261
+ setIsMissingKeyLoading(false);
262
+ return;
263
+ }
264
+ setIsMissingKeyLoading(true);
265
+ var timeout = setTimeout(function () {
266
+ setIsMissingKeyLoading(false);
267
+ }, 800);
268
+ return function () { return clearTimeout(timeout); };
269
+ }, [errorKind]);
282
270
  // Mantém o botão clicável para "Solicitar instrumento" mesmo durante prefetch
283
271
  var isDisabled = isLoading ||
272
+ isMissingKeyLoading ||
284
273
  errorKind === 'invalid-key' ||
285
- errorKind === 'missing-doc';
274
+ errorKind === 'missing-doc' ||
275
+ errorKind === 'missing-key';
286
276
  var getTooltipMessage = function () {
287
277
  if (errorKind === 'missing-doc')
288
278
  return 'Documento não disponível para consulta';
289
279
  if (errorKind === 'invalid-key')
290
280
  return 'Chave de instrumento inválida';
281
+ if (errorKind === 'missing-key') {
282
+ return isMissingKeyLoading ? '' : 'Instrumento não localizado';
283
+ }
291
284
  return '';
292
285
  };
293
286
  var getButtonLabel = function () {
287
+ if (errorKind === 'missing-key')
288
+ return isMissingKeyLoading ? 'Solicitar instrumento' : 'Instrumento não localizado';
294
289
  if (errorKind === 'invalid-key' || errorKind === 'missing-doc')
295
290
  return 'Instrumento Indisponível';
296
291
  if (!isProtestoSPByNmChave(normalizedKey))
@@ -299,23 +294,11 @@ export var Instrumento = function (_a) {
299
294
  };
300
295
  var tooltipMessage = getTooltipMessage();
301
296
  var isSP = isProtestoSPByNmChave(normalizedKey);
302
- var resetInstrumentStateForKey = useCallback(function () {
303
- if (!nm_chave)
304
- return;
305
- setData(function (prev) {
306
- var base = prev || {};
307
- var prevProtestosData = base.protestosData || {};
308
- var _a = prevProtestosData.failedInstruments || {}, _b = nm_chave, _f1 = _a[_b], restFailed = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
309
- var _c = prevProtestosData.failedInstrumentReasons || {}, _d = nm_chave, _r1 = _c[_d], restReasons = __rest(_c, [typeof _d === "symbol" ? _d : _d + ""]);
310
- var _e = prevProtestosData.checkedInstruments || {}, _f = nm_chave, _c1 = _e[_f], restChecked = __rest(_e, [typeof _f === "symbol" ? _f : _f + ""]);
311
- var _g = prevProtestosData.instrumentCache || {}, _h = nm_chave, _i1 = _g[_h], restCache = __rest(_g, [typeof _h === "symbol" ? _h : _h + ""]);
312
- return __assign(__assign({}, base), { protestosData: __assign(__assign({}, prevProtestosData), { failedInstruments: restFailed, failedInstrumentReasons: restReasons, checkedInstruments: restChecked, instrumentCache: restCache, refreshToken: (prevProtestosData.refreshToken || 0) + 1 }) });
313
- });
314
- setErrorKind(null);
315
- }, [nm_chave, setData]);
316
297
  return (React.createElement(React.Fragment, null,
317
298
  React.createElement("span", { title: tooltipMessage, style: { display: 'inline-block' } },
318
- React.createElement(Button, { isLoading: isLoading || instrumentoHook.isProcessandoDescoberta, onClick: function () { return __awaiter(void 0, void 0, void 0, function () {
299
+ React.createElement(Button, { isLoading: isLoading ||
300
+ instrumentoHook.isProcessandoDescoberta ||
301
+ isMissingKeyLoading, onClick: function () { return __awaiter(void 0, void 0, void 0, function () {
319
302
  return __generator(this, function (_a) {
320
303
  if (isDisabled)
321
304
  return [2 /*return*/];
@@ -330,15 +313,7 @@ export var Instrumento = function (_a) {
330
313
  });
331
314
  }); }, disabled: isDisabled }, getButtonLabel())),
332
315
  React.createElement(ModalInstrumentoProtestoSP, { isOpen: instrumentoHook.isModalSPOpen, onClose: instrumentoHook.closeModalSP, onEnviarEmail: instrumentoHook.handleEnviarEmail, isEnviandoEmail: instrumentoHook.isEnviandoEmail }),
333
- React.createElement(InstrumentoEmailStatusModal, { isOpen: instrumentoHook.isEmailModalOpen, onClose: instrumentoHook.closeEmailModal, message: instrumentoHook.emailMessage, title: instrumentoHook.emailTitle, secondaryActionLabel: instrumentoHook.isSuccess ? 'Atualizar consulta (hoje)' : undefined, secondaryActionDisabled: false, onSecondaryAction: instrumentoHook.isSuccess
334
- ? function () {
335
- var _a;
336
- // Permite reconsultar no mesmo dia para tentar “desocultar” instrumento/nome
337
- resetInstrumentStateForKey();
338
- (_a = ctxProtestos === null || ctxProtestos === void 0 ? void 0 : ctxProtestos.refetch) === null || _a === void 0 ? void 0 : _a.call(ctxProtestos);
339
- instrumentoHook.closeEmailModal();
340
- }
341
- : undefined }),
316
+ React.createElement(InstrumentoEmailStatusModal, { isOpen: instrumentoHook.isEmailModalOpen, onClose: instrumentoHook.closeEmailModal, message: instrumentoHook.emailMessage, title: instrumentoHook.emailTitle }),
342
317
  React.createElement(InstrumentoDiscoveryConfirmModal, { isOpen: isDiscoveryConfirmOpen, onClose: function () { return setIsDiscoveryConfirmOpen(false); }, isLoading: instrumentoHook.isProcessandoDescoberta, onConfirm: function () { return __awaiter(void 0, void 0, void 0, function () {
343
318
  return __generator(this, function (_a) {
344
319
  switch (_a.label) {