@credithub/harlan-components 1.74.0 → 1.75.0

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.
@@ -52,9 +52,11 @@ import theme from '../../styles/theme';
52
52
  import { normalizeName, similarNames } from '../../utils/similarNames';
53
53
  import { WarningCircle } from 'phosphor-react';
54
54
  import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
55
+ import Button from '../common/button';
56
+ import Modal from '../common/modal';
55
57
  import StatusMessage from '../interface/statusMessage';
56
58
  import Section from '../section';
57
- import { Queries, RequestStatus } from '../webservice';
59
+ import { Queries, RequestStatus, useFetch } from '../webservice';
58
60
  import { TitleWithTooltip, TooltipContainer, TooltipText } from './liminarStyles';
59
61
  import useLiminarProtestosDoPassado from './useLiminarProtestosDoPassado';
60
62
  /* ----------------------------------
@@ -89,6 +91,9 @@ var Liminar = function () {
89
91
  var dataHashRef = useRef('');
90
92
  var invertedIdsRef = useRef([]);
91
93
  var _p = useState(false), isTooltipVisible = _p[0], setTooltipVisible = _p[1];
94
+ var _q = useState(false), isEmailModalOpen = _q[0], setIsEmailModalOpen = _q[1];
95
+ var _r = useState(''), emailModalMessage = _r[0], setEmailModalMessage = _r[1];
96
+ var _s = useFetch("SELECT FROM 'LIMINAR'.'SENDMAIL'"), sendIndiciosEmail = _s.fetch, isEmailSending = _s.isLoading, emailError = _s.error;
92
97
  var hideTt = useRef();
93
98
  /*
94
99
  * Extrai e normaliza os tipos de documento presentes em ctx.document, retornando sempre um array de strings em minúsculo.
@@ -132,7 +137,7 @@ var Liminar = function () {
132
137
  /*
133
138
  * Identifica as origens de liminares detectadas e verifica se existe liminar de protesto invertida
134
139
  */
135
- var _q = useMemo(function () {
140
+ var _t = useMemo(function () {
136
141
  var _a, _b;
137
142
  var labels = new Set();
138
143
  var indiciosApi = ((_a = ctx.document) === null || _a === void 0 ? void 0 : _a.indiciosDeLiminar) === true;
@@ -168,13 +173,13 @@ var Liminar = function () {
168
173
  tiposDocumento,
169
174
  processosComAssuntoValido,
170
175
  (_e = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _e === void 0 ? void 0 : _e.indiciosDeLiminarProtestosDoPassado
171
- ]), origensDetectadas = _q.origensDetectadas, foundBusinessEntity = _q.foundBusinessEntity;
176
+ ]), origensDetectadas = _t.origensDetectadas, foundBusinessEntity = _t.foundBusinessEntity;
172
177
  useEffect(function () {
173
178
  var fetch = function () { return __awaiter(void 0, void 0, void 0, function () {
174
- var dossie, processosJuridicos, depsLoaded, newIds, hash, indiciosApi, indiciosDeLiminarProtestosDoPassado, finalStatus;
175
- var _a, _b, _c;
176
- return __generator(this, function (_d) {
177
- switch (_d.label) {
179
+ var dossie, processosJuridicos, depsLoaded, newIds, hash, indiciosApi, indiciosDeLiminarProtestosDoPassado, protestosDoPassadoIds, _a, possuiIndiciosDeLiminarProtestosDoPassado, protestosIds, finalStatus;
180
+ var _b, _c, _d;
181
+ return __generator(this, function (_e) {
182
+ switch (_e.label) {
178
183
  case 0:
179
184
  dossie = globalData === null || globalData === void 0 ? void 0 : globalData.dossie;
180
185
  processosJuridicos = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData;
@@ -186,27 +191,31 @@ var Liminar = function () {
186
191
  : [];
187
192
  hash = JSON.stringify({
188
193
  t: ctx.type,
189
- indicios: (_a = ctx.document) === null || _a === void 0 ? void 0 : _a.indiciosDeLiminar,
194
+ indicios: (_b = ctx.document) === null || _b === void 0 ? void 0 : _b.indiciosDeLiminar,
190
195
  carousel: dossie.carousel,
191
196
  empresas: processosJuridicos.empresa
192
197
  });
193
198
  if (hash === dataHashRef.current)
194
199
  return [2 /*return*/];
195
200
  dataHashRef.current = hash;
196
- indiciosApi = ((_b = ctx.document) === null || _b === void 0 ? void 0 : _b.indiciosDeLiminar) === true;
201
+ indiciosApi = ((_c = ctx.document) === null || _c === void 0 ? void 0 : _c.indiciosDeLiminar) === true;
197
202
  indiciosDeLiminarProtestosDoPassado = false;
203
+ protestosDoPassadoIds = '';
198
204
  if (!(!indiciosApi &&
199
205
  !processosComAssuntoValido.length &&
200
- ((_c = globalData === null || globalData === void 0 ? void 0 : globalData.documentHistory) === null || _c === void 0 ? void 0 : _c.protestoLiminar))) return [3 /*break*/, 2];
206
+ ((_d = globalData === null || globalData === void 0 ? void 0 : globalData.documentHistory) === null || _d === void 0 ? void 0 : _d.protestoLiminar))) return [3 /*break*/, 2];
201
207
  setIsLoadingLiminarProtestosDoPassado(true);
202
208
  return [4 /*yield*/, fetchLiminarProtestosDoPassado()];
203
209
  case 1:
204
- indiciosDeLiminarProtestosDoPassado =
205
- _d.sent();
206
- if (indiciosDeLiminarProtestosDoPassado)
210
+ _a = _e.sent(), possuiIndiciosDeLiminarProtestosDoPassado = _a.possuiIndiciosDeLiminarProtestosDoPassado, protestosIds = _a.protestosDoPassadoIds;
211
+ console.log("possuiIndiciosDeLiminarProtestosDoPassado", possuiIndiciosDeLiminarProtestosDoPassado);
212
+ if (possuiIndiciosDeLiminarProtestosDoPassado) {
207
213
  origensDetectadas.push('Liminar no Cenprot');
214
+ indiciosDeLiminarProtestosDoPassado = possuiIndiciosDeLiminarProtestosDoPassado;
215
+ protestosDoPassadoIds = protestosIds.join(',');
216
+ }
208
217
  setIsLoadingLiminarProtestosDoPassado(false);
209
- _d.label = 2;
218
+ _e.label = 2;
210
219
  case 2:
211
220
  finalStatus = indiciosApi ||
212
221
  processosComAssuntoValido.length ||
@@ -220,6 +229,7 @@ var Liminar = function () {
220
229
  isLoaded: true,
221
230
  processosComLiminarIds: processosComAssuntoValido.map(function (p) { return p.id; }),
222
231
  indiciosDeLiminarProtestosDoPassado: indiciosDeLiminarProtestosDoPassado,
232
+ protestosDoPassadoIds: protestosDoPassadoIds,
223
233
  invertedProcessos: newIds
224
234
  } })); });
225
235
  processedRef.current = true;
@@ -261,38 +271,75 @@ var Liminar = function () {
261
271
  (ready &&
262
272
  (((_h = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _h === void 0 ? void 0 : _h.indiciosDeLiminar) ||
263
273
  ((_l = (_k = (_j = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _j === void 0 ? void 0 : _j.processosComLiminarIds) === null || _k === void 0 ? void 0 : _k.length) !== null && _l !== void 0 ? _l : 0) > 0));
274
+ // Função para disparar o envio do e-mail e configurar a mensagem do modal
275
+ var handleSendEmailIndicios = function (e) { return __awaiter(void 0, void 0, void 0, function () {
276
+ var documento, ids;
277
+ var _a, _b, _c;
278
+ return __generator(this, function (_d) {
279
+ switch (_d.label) {
280
+ case 0:
281
+ e.preventDefault();
282
+ e.stopPropagation();
283
+ documento = ((_b = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel) === null || _b === void 0 ? void 0 : _b.document) || '';
284
+ ids = ((_c = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _c === void 0 ? void 0 : _c.protestosDoPassadoIds) || '';
285
+ return [4 /*yield*/, sendIndiciosEmail({ documento: documento, nm_chave: ids })];
286
+ case 1:
287
+ _d.sent();
288
+ if (emailError) {
289
+ setEmailModalMessage("Falha ao enviar e-mail: ".concat(emailError.message));
290
+ }
291
+ else {
292
+ setEmailModalMessage('O e-mail com os indícios da liminar foi enviado com sucesso.');
293
+ }
294
+ setIsEmailModalOpen(true);
295
+ return [2 /*return*/];
296
+ }
297
+ });
298
+ }); };
264
299
  if (!shouldRender)
265
300
  return null;
266
- return (React.createElement(Section, { title: React.createElement(TitleWithTooltip, null,
267
- "Liminares para Remo\u00E7\u00E3o de Protesto",
268
- !!processosComAssuntoValido.length && ready && (React.createElement(TooltipContainer, { onMouseEnter: function () {
269
- clearTimeout(hideTt.current);
270
- setTooltipVisible(true);
271
- }, onMouseLeave: function () {
272
- hideTt.current = setTimeout(function () { return setTooltipVisible(false); }, 300);
273
- } },
274
- renderTooltipIcon(),
275
- React.createElement(TooltipText, { visible: isTooltipVisible },
276
- React.createElement(React.Fragment, null,
277
- tooltipMessage,
278
- React.createElement("ul", { style: { marginTop: 6, paddingLeft: 18 } }, processosComAssuntoValido.map(function (p) { return (React.createElement("li", { key: p.id, onClick: function () { return scrollToProcesso(p.id); }, style: {
279
- fontSize: 13,
280
- cursor: 'pointer',
281
- textDecoration: 'underline',
282
- color: '#007aff'
283
- } }, p.id)); }))))))), subtitle: "Ind\u00EDcios de liminares para oculta\u00E7\u00E3o de registros.", icon: ProtestosIcon, ctx: ready ? ctx : ctxLoading, onSuccess: ready
284
- ? function () {
285
- var _a, _b;
286
- var msg = (_b = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Não encontrado';
287
- var variant = msg === 'Encontrado' ? 'error' : 'default';
288
- return {
289
- children: React.createElement(React.Fragment, null),
290
- variant: variant,
291
- description: (React.createElement(React.Fragment, null,
292
- React.createElement(StatusMessage, { type: variant }, msg),
293
- origensDetectadas.map(function (o) { return (React.createElement(StatusMessage, { key: o, type: variant }, o)); })))
294
- };
295
- }
296
- : undefined }));
301
+ return (React.createElement(React.Fragment, null,
302
+ React.createElement(Section, { title: React.createElement(TitleWithTooltip, null,
303
+ "Liminares para Remo\u00E7\u00E3o de Protesto",
304
+ !!processosComAssuntoValido.length && ready && (React.createElement(TooltipContainer, { onMouseEnter: function () {
305
+ clearTimeout(hideTt.current);
306
+ setTooltipVisible(true);
307
+ }, onMouseLeave: function () {
308
+ hideTt.current = setTimeout(function () { return setTooltipVisible(false); }, 300);
309
+ } },
310
+ renderTooltipIcon(),
311
+ React.createElement(TooltipText, { visible: isTooltipVisible },
312
+ React.createElement(React.Fragment, null,
313
+ tooltipMessage,
314
+ React.createElement("ul", { style: { marginTop: 6, paddingLeft: 18 } }, processosComAssuntoValido.map(function (p) { return (React.createElement("li", { key: p.id, onClick: function () { return scrollToProcesso(p.id); }, style: {
315
+ fontSize: 13,
316
+ cursor: 'pointer',
317
+ textDecoration: 'underline',
318
+ color: '#007aff'
319
+ } }, p.id)); }))))))), subtitle: "Ind\u00EDcios de liminares para oculta\u00E7\u00E3o de registros.", icon: ProtestosIcon, ctx: ready ? ctx : ctxLoading, onSuccess: ready
320
+ ? function (_data, _context) {
321
+ var _a, _b, _c, _d;
322
+ var msg = (_b = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Não encontrado';
323
+ var variant = msg === 'Encontrado' ? 'error' : 'default';
324
+ return {
325
+ children: React.createElement(React.Fragment, null),
326
+ variant: variant,
327
+ description: (React.createElement(React.Fragment, null,
328
+ React.createElement(StatusMessage, { type: variant }, msg),
329
+ origensDetectadas.map(function (o) { return (React.createElement(StatusMessage, { key: o, type: variant }, o)); }))),
330
+ actions: (React.createElement("div", { style: { textAlign: 'center' }, onClick: function (e) { return e.stopPropagation(); } }, ((_c = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _c === void 0 ? void 0 : _c.indiciosDeLiminarProtestosDoPassado) && ((_d = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _d === void 0 ? void 0 : _d.protestosDoPassadoIds) && (React.createElement(Button, { onClick: handleSendEmailIndicios }, "Enviar Ind\u00EDcios por Email"))))
331
+ };
332
+ }
333
+ : undefined }),
334
+ React.createElement(Modal, { isOpen: isEmailModalOpen, onClose: function () {
335
+ setIsEmailModalOpen(false);
336
+ setEmailModalMessage('');
337
+ }, title: "Resultado do Envio de E-mail" },
338
+ React.createElement("p", null, emailModalMessage),
339
+ React.createElement("div", { style: { textAlign: 'center', marginTop: '16px' } },
340
+ React.createElement(Button, { onClick: function () {
341
+ setIsEmailModalOpen(false);
342
+ setEmailModalMessage('');
343
+ } }, "Fechar")))));
297
344
  };
298
345
  export default Liminar;
@@ -2,6 +2,9 @@ interface LiminarProtestosDoPassadoProps {
2
2
  documento: string;
3
3
  }
4
4
  declare const useLiminarProtestosDoPassado: ({ documento }: LiminarProtestosDoPassadoProps) => {
5
- fetchLiminarProtestosDoPassado: () => Promise<boolean>;
5
+ fetchLiminarProtestosDoPassado: () => Promise<{
6
+ possuiIndiciosDeLiminarProtestosDoPassado: boolean;
7
+ protestosDoPassadoIds: string[];
8
+ }>;
6
9
  };
7
10
  export default useLiminarProtestosDoPassado;
@@ -83,7 +83,7 @@ var useLiminarProtestosDoPassado = function (_a) {
83
83
  });
84
84
  }); };
85
85
  var fetch = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
86
- var data, parsed, nodes, numerosChave;
86
+ var data, parsed, nodes, numerosChave, possuiIndiciosDeLiminarProtestosDoPassado;
87
87
  return __generator(this, function (_a) {
88
88
  switch (_a.label) {
89
89
  case 0: return [4 /*yield*/, client.request("SELECT FROM 'IEPTB'.'PASTQUERIES'", {
@@ -96,7 +96,13 @@ var useLiminarProtestosDoPassado = function (_a) {
96
96
  parsed = _a.sent();
97
97
  nodes = XPathUtils.selectArray('//protesto/nm_chave', parsed);
98
98
  numerosChave = Array.from(new Set(nodes.map(function (node) { return node.textContent || ''; })));
99
- return [2 /*return*/, getAlgumInstrumentoPossuiPDF(numerosChave)];
99
+ return [4 /*yield*/, getAlgumInstrumentoPossuiPDF(numerosChave)];
100
+ case 3:
101
+ possuiIndiciosDeLiminarProtestosDoPassado = _a.sent();
102
+ return [2 /*return*/, {
103
+ possuiIndiciosDeLiminarProtestosDoPassado: possuiIndiciosDeLiminarProtestosDoPassado,
104
+ protestosDoPassadoIds: numerosChave
105
+ }];
100
106
  }
101
107
  });
102
108
  }); }, [documento]);