@credithub/harlan-components 1.76.1 → 1.78.3

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.
@@ -72,12 +72,18 @@ import QuantidadeResultados from './quantityResult';
72
72
  import { useCalculation, useUltimaOcorrenciaCCF } from './utils/chartUtils';
73
73
  var Content = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: ", ";\n padding: 0px 30px;\n\n @media print {\n display: block;\n }\n"], ["\n display: ", ";\n padding: 0px 30px;\n\n @media print {\n display: block;\n }\n"])), function (props) { return (props.isOpen ? 'block' : 'none'); });
74
74
  function calcularProtestoLiminar(history) {
75
- var _a;
76
- if (!history.length)
75
+ var _a, _b;
76
+ if (history.length < 2)
77
77
  return false;
78
- var teveAnterior = history.slice(0, -1).some(function (h) { return h.quantidade > 0; });
79
- var ultimoZerado = ((_a = history.at(-1)) === null || _a === void 0 ? void 0 : _a.quantidade) === 0;
80
- return teveAnterior && ultimoZerado;
78
+ var anteriores = history.slice(0, -1).map(function (h) { return h.quantidade; });
79
+ var ultimo = (_b = (_a = history.at(-1)) === null || _a === void 0 ? void 0 : _a.quantidade) !== null && _b !== void 0 ? _b : 0;
80
+ var maiorAnterior = Math.max.apply(Math, anteriores);
81
+ if (maiorAnterior === 0)
82
+ return false;
83
+ if (ultimo === 0)
84
+ return true;
85
+ var reducao = 1 - ultimo / maiorAnterior;
86
+ return reducao >= 0.8;
81
87
  }
82
88
  var ChartSystem = function (_a) {
83
89
  var _b, _c, _d, _e, _f, _g, _h, _j;
@@ -1,10 +1,13 @@
1
1
  import React from 'react';
2
+ import { HasCreditsType } from '../consultasComplementares';
2
3
  interface LiminarProps {
3
4
  /**
4
5
  * Se verdadeiro, exibe ações exclusivas para instituições financeiras,
5
6
  * como o download de protestos ocultos.
6
7
  */
7
8
  isFinancial?: boolean;
9
+ hasCredits?: HasCreditsType;
10
+ tags?: (string | RegExp)[];
8
11
  }
9
12
  declare const Liminar: React.FC<LiminarProps>;
10
13
  export default Liminar;
@@ -59,6 +59,9 @@ import Section from '../section';
59
59
  import { Queries, RequestStatus, useFetch } from '../webservice';
60
60
  import { TitleWithTooltip, TooltipContainer, TooltipText } from './liminarStyles';
61
61
  import useLiminarProtestosDoPassado from './useLiminarProtestosDoPassado';
62
+ import { hasOneOfTags } from '../../utils/tags';
63
+ import { SummaryButton } from '../dossie/summary/styles';
64
+ import { formatMoney } from '../../utils/number';
62
65
  /* ----------------------------------
63
66
  * Constantes
64
67
  * ---------------------------------*/
@@ -81,20 +84,24 @@ var businessTypes = [
81
84
  ];
82
85
  var Liminar = function (_a) {
83
86
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
84
- var _o = _a.isFinancial, isFinancial = _o === void 0 ? false : _o;
87
+ var _o = _a.isFinancial, isFinancial = _o === void 0 ? false : _o, hasCredits = _a.hasCredits, _p = _a.tags, tags = _p === void 0 ? [] : _p;
85
88
  var ctx = useContext(Queries.LiminarCenprot);
86
- var _p = useGlobalData(), globalData = _p.data, setData = _p.setData;
89
+ var _q = useGlobalData(), globalData = _q.data, setData = _q.setData;
87
90
  var fetchLiminarProtestosDoPassado = useLiminarProtestosDoPassado({
88
91
  documento: ((_c = (_b = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _b === void 0 ? void 0 : _b.carousel) === null || _c === void 0 ? void 0 : _c.document) || ''
89
92
  }).fetchLiminarProtestosDoPassado;
90
- var _q = useState(false), isLoadingLiminarProtestosDoPassado = _q[0], setIsLoadingLiminarProtestosDoPassado = _q[1];
93
+ var _r = useState(false), isLoadingLiminarProtestosDoPassado = _r[0], setIsLoadingLiminarProtestosDoPassado = _r[1];
91
94
  var processedRef = useRef(false);
92
95
  var dataHashRef = useRef('');
93
96
  var invertedIdsRef = useRef([]);
94
- var _r = useState(false), isTooltipVisible = _r[0], setTooltipVisible = _r[1];
95
- var _s = useState(false), isEmailModalOpen = _s[0], setIsEmailModalOpen = _s[1];
96
- var _t = useState(''), emailModalMessage = _t[0], setEmailModalMessage = _t[1];
97
- var _u = useFetch("SELECT FROM 'LIMINAR'.'SENDMAIL'"), sendIndiciosEmail = _u.fetch, isEmailSending = _u.isLoading, emailError = _u.error;
97
+ var _s = useState(false), isTooltipVisible = _s[0], setTooltipVisible = _s[1];
98
+ var _t = useState(false), isEmailModalOpen = _t[0], setIsEmailModalOpen = _t[1];
99
+ var _u = useState(''), emailModalMessage = _u[0], setEmailModalMessage = _u[1];
100
+ var liminarMailPrice = useMemo(function () {
101
+ var isDiamanteNew = hasOneOfTags(tags, ['diamante-new']);
102
+ return isDiamanteNew ? 0 : 50000;
103
+ }, [tags]);
104
+ var _v = useFetch("SELECT FROM 'LIMINAR'.'SENDMAIL'"), sendIndiciosEmail = _v.fetch, isEmailSending = _v.isLoading, emailError = _v.error;
98
105
  var hideTt = useRef();
99
106
  /*
100
107
  * Extrai e normaliza os tipos de documento presentes em ctx.document, retornando sempre um array de strings em minúsculo.
@@ -138,7 +145,7 @@ var Liminar = function (_a) {
138
145
  /*
139
146
  * Identifica as origens de liminares detectadas e verifica se existe liminar de protesto invertida
140
147
  */
141
- var _v = useMemo(function () {
148
+ var _w = useMemo(function () {
142
149
  var _a, _b;
143
150
  var labels = new Set();
144
151
  var indiciosApi = ((_a = ctx.document) === null || _a === void 0 ? void 0 : _a.indiciosDeLiminar) === true;
@@ -174,7 +181,7 @@ var Liminar = function (_a) {
174
181
  tiposDocumento,
175
182
  processosComAssuntoValido,
176
183
  (_f = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _f === void 0 ? void 0 : _f.indiciosDeLiminarProtestosDoPassado
177
- ]), origensDetectadas = _v.origensDetectadas, foundBusinessEntity = _v.foundBusinessEntity;
184
+ ]), origensDetectadas = _w.origensDetectadas, foundBusinessEntity = _w.foundBusinessEntity;
178
185
  useEffect(function () {
179
186
  var fetch = function () { return __awaiter(void 0, void 0, void 0, function () {
180
187
  var dossie, processosJuridicos, depsLoaded, newIds, hash, indiciosApi, indiciosDeLiminarProtestosDoPassado, protestosDoPassadoIds, _a, possuiIndiciosDeLiminarProtestosDoPassado, protestosIds, finalStatus;
@@ -209,7 +216,6 @@ var Liminar = function (_a) {
209
216
  return [4 /*yield*/, fetchLiminarProtestosDoPassado()];
210
217
  case 1:
211
218
  _a = _e.sent(), possuiIndiciosDeLiminarProtestosDoPassado = _a.possuiIndiciosDeLiminarProtestosDoPassado, protestosIds = _a.protestosDoPassadoIds;
212
- console.log('possuiIndiciosDeLiminarProtestosDoPassado', possuiIndiciosDeLiminarProtestosDoPassado);
213
219
  if (possuiIndiciosDeLiminarProtestosDoPassado) {
214
220
  origensDetectadas.push('Liminar no Cenprot');
215
221
  indiciosDeLiminarProtestosDoPassado =
@@ -275,27 +281,42 @@ var Liminar = function (_a) {
275
281
  ((_m = (_l = (_k = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _k === void 0 ? void 0 : _k.processosComLiminarIds) === null || _l === void 0 ? void 0 : _l.length) !== null && _m !== void 0 ? _m : 0) > 0));
276
282
  // Função para disparar o envio do e-mail e configurar a mensagem do modal
277
283
  var handleSendEmailIndicios = function (e) { return __awaiter(void 0, void 0, void 0, function () {
278
- var documento, ids;
279
- var _a, _b, _c;
280
- return __generator(this, function (_d) {
281
- switch (_d.label) {
282
- case 0:
283
- e.preventDefault();
284
- e.stopPropagation();
285
- 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) || '';
286
- ids = ((_c = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _c === void 0 ? void 0 : _c.protestosDoPassadoIds) || '';
287
- return [4 /*yield*/, sendIndiciosEmail({ documento: documento, nm_chave: ids })];
288
- case 1:
289
- _d.sent();
290
- if (emailError) {
291
- setEmailModalMessage("Falha ao enviar e-mail: ".concat(emailError.message));
292
- }
293
- else {
294
- setEmailModalMessage('Você deve ter recebido um e-mail nosso com os detalhes que encontramos sobre esse indício.');
295
- }
296
- setIsEmailModalOpen(true);
297
- return [2 /*return*/];
284
+ var callback;
285
+ return __generator(this, function (_a) {
286
+ e.preventDefault();
287
+ e.stopPropagation();
288
+ if (!hasOneOfTags(tags, ['diamante', 'diamante-new'])) {
289
+ setEmailModalMessage('Disponível apenas no plano Diamante.');
290
+ setIsEmailModalOpen(true);
291
+ return [2 /*return*/];
298
292
  }
293
+ callback = function () { return __awaiter(void 0, void 0, void 0, function () {
294
+ var documento, ids;
295
+ var _a, _b, _c;
296
+ return __generator(this, function (_d) {
297
+ switch (_d.label) {
298
+ case 0:
299
+ 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) || '';
300
+ ids = ((_c = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _c === void 0 ? void 0 : _c.protestosDoPassadoIds) || '';
301
+ return [4 /*yield*/, sendIndiciosEmail({ documento: documento, nm_chave: ids })];
302
+ case 1:
303
+ _d.sent();
304
+ if (emailError) {
305
+ setEmailModalMessage("Falha ao enviar e-mail: ".concat(emailError.message));
306
+ }
307
+ else {
308
+ setEmailModalMessage('Você deve ter recebido um e-mail nosso com os detalhes que encontramos sobre esse indício.');
309
+ }
310
+ setIsEmailModalOpen(true);
311
+ return [2 /*return*/];
312
+ }
313
+ });
314
+ }); };
315
+ if (hasCredits)
316
+ hasCredits(liminarMailPrice, callback);
317
+ else
318
+ callback();
319
+ return [2 /*return*/];
299
320
  });
300
321
  }); };
301
322
  if (!shouldRender)
@@ -331,14 +352,14 @@ var Liminar = function (_a) {
331
352
  origensDetectadas.map(function (o) { return (React.createElement(StatusMessage, { key: o, type: variant }, o)); }))),
332
353
  actions: (React.createElement("div", { style: { textAlign: 'center' }, onClick: function (e) { return e.stopPropagation(); } }, isFinancial &&
333
354
  ((_c = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _c === void 0 ? void 0 : _c.indiciosDeLiminarProtestosDoPassado) &&
334
- ((_d = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _d === void 0 ? void 0 : _d.protestosDoPassadoIds) && (React.createElement(Button, { onClick: handleSendEmailIndicios, disabled: isEmailSending }, "Baixar Protestos Ocultos"))))
355
+ ((_d = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _d === void 0 ? void 0 : _d.protestosDoPassadoIds) && (React.createElement(SummaryButton, { onClick: handleSendEmailIndicios, disabled: isEmailSending, smallContent: liminarMailPrice && !isEmailSending ? formatMoney(liminarMailPrice / 1000) : '' }, "Baixar Protestos Ocultos"))))
335
356
  };
336
357
  }
337
358
  : undefined }),
338
359
  React.createElement(Modal, { isOpen: isEmailModalOpen, onClose: function () {
339
360
  setIsEmailModalOpen(false);
340
361
  setEmailModalMessage('');
341
- }, title: "Detalhes enviados por e-mail" },
362
+ }, title: "Envio de protestos ocultos por e-mail" },
342
363
  React.createElement("p", null, emailModalMessage),
343
364
  React.createElement("div", { style: { textAlign: 'center', marginTop: '16px' } },
344
365
  React.createElement(Button, { onClick: function () {
@@ -24,12 +24,14 @@ import { extractIntegerFromText } from '../../utils/number';
24
24
  import XPathUtils from '../../utils/xpath';
25
25
  import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
26
26
  import styled from 'styled-components';
27
+ import Button from '../common/button';
27
28
  import StatusMessage from '../interface/statusMessage';
28
29
  import Section from '../section';
29
30
  import { Queries, RequestStatus } from '../webservice';
30
31
  import ProtestosCategory from './protestosCategory';
31
32
  import { ProtestoItem } from './protestosList';
32
33
  var ResultProtestos = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n row-gap: 20px;\n margin-top: 20px;\n"], ["\n display: flex;\n flex-direction: column;\n row-gap: 20px;\n margin-top: 20px;\n"])));
34
+ var BtnWrapper = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n text-align: center;\n @media print {\n display: none;\n }\n"], ["\n text-align: center;\n @media print {\n display: none;\n }\n"])));
33
35
  // Função de ordenação por data
34
36
  var byDate = function (protesto, protesto2) {
35
37
  var _a, _b;
@@ -137,7 +139,7 @@ var Protestos = function () {
137
139
  }))) : null;
138
140
  var variant = registros ? 'error' : 'default';
139
141
  return {
140
- children: children,
142
+ children: React.createElement(React.Fragment, null, children),
141
143
  variant: variant,
142
144
  description: (React.createElement(StatusMessage, { type: registros ? 'error' : 'default' }, registros
143
145
  ? registros === 1
@@ -146,7 +148,10 @@ var Protestos = function () {
146
148
  : 'Não há ocorrência de protesto'))
147
149
  };
148
150
  }, [total, iaOverrides]);
149
- return (React.createElement(Section, { ctx: ctx, title: "Apontamentos na Central de Protestos (CENPROT)", subtitle: "Consulta de protestos de cr\u00E9dito, imposto e gerais.", icon: ProtestosIcon, onSuccess: handleSuccess }));
151
+ return (React.createElement(Section, { ctx: ctx, title: "Apontamentos na Central de Protestos (CENPROT)", subtitle: "Consulta de protestos de cr\u00E9dito, imposto e gerais.", icon: ProtestosIcon, onSuccess: handleSuccess, actions: typeof harlan !== 'undefined' ? (React.createElement(BtnWrapper, null,
152
+ React.createElement(Button, { onClick: function () {
153
+ harlan === null || harlan === void 0 ? void 0 : harlan.call('creditHub::addLiminar');
154
+ } }, "Apontar Protesto"))) : null }));
150
155
  };
151
156
  export default React.memo(Protestos);
152
- var templateObject_1;
157
+ var templateObject_1, templateObject_2;
@@ -312,10 +312,11 @@ export function useFetch(query) {
312
312
  var abortController = useMemo(function () { return new AbortController(); }, []);
313
313
  var _a = useState(null), response = _a[0], setResponse = _a[1];
314
314
  var _b = useState(null), error = _b[0], setError = _b[1];
315
- var _c = useState(true), isLoading = _c[0], setIsLoading = _c[1];
315
+ var _c = useState(false), isLoading = _c[0], setIsLoading = _c[1];
316
316
  var fetch = useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
317
317
  return __generator(this, function (_a) {
318
318
  setIsLoading(true);
319
+ setError(null);
319
320
  return [2 /*return*/, client
320
321
  .request(query, data, undefined, abortController.signal)
321
322
  .then(function (document) {
@@ -17,6 +17,7 @@ type ConsultaSimplesProps = {
17
17
  initVeiculos?: boolean;
18
18
  printMode?: boolean;
19
19
  isFinancial?: boolean;
20
+ tags?: (string | RegExp)[];
20
21
  };
21
22
  declare const ConsultaSimples: React.FC<ConsultaSimplesProps>;
22
23
  export default ConsultaSimples;
@@ -27,7 +27,7 @@ var FinderDependency = function (_a) {
27
27
  React.createElement(Queries.Protestos.Request, { data: { documento: documento }, depends: [ctxFinder] }, children)));
28
28
  };
29
29
  var ConsultaSimples = function (_a) {
30
- var _documento = _a.documento, onClickConsultarProcessoJuridico = _a.onClickConsultarProcessoJuridico, onClickQSA = _a.onClickQSA, onClickPrint = _a.onClickPrint, apiKey = _a.apiKey, onClose = _a.onClose, hasCredits = _a.hasCredits, _b = _a.initRefinBoaVista, initRefinBoaVista = _b === void 0 ? false : _b, _c = _a.initRefinSerasa, initRefinSerasa = _c === void 0 ? false : _c, _d = _a.initVeiculos, initVeiculos = _d === void 0 ? false : _d, _e = _a.printMode, printMode = _e === void 0 ? false : _e, _f = _a.isFinancial, isFinancial = _f === void 0 ? false : _f;
30
+ var _documento = _a.documento, onClickConsultarProcessoJuridico = _a.onClickConsultarProcessoJuridico, onClickQSA = _a.onClickQSA, onClickPrint = _a.onClickPrint, apiKey = _a.apiKey, onClose = _a.onClose, hasCredits = _a.hasCredits, _b = _a.initRefinBoaVista, initRefinBoaVista = _b === void 0 ? false : _b, _c = _a.initRefinSerasa, initRefinSerasa = _c === void 0 ? false : _c, _d = _a.initVeiculos, initVeiculos = _d === void 0 ? false : _d, _e = _a.printMode, printMode = _e === void 0 ? false : _e, _f = _a.isFinancial, isFinancial = _f === void 0 ? false : _f, _g = _a.tags, tags = _g === void 0 ? [] : _g;
31
31
  var documento = _documento.replace(/\D+/g, '');
32
32
  return (React.createElement(ThemeProvider, { theme: theme },
33
33
  React.createElement(ConsultasComplementaresProvider, { hasCredits: hasCredits, initRefinBoaVista: initRefinBoaVista, initRefinSerasa: initRefinSerasa, initVeiculos: initVeiculos },
@@ -43,7 +43,7 @@ var ConsultaSimples = function (_a) {
43
43
  React.createElement(ConsultaSimplesSection, { documento: documento, onClose: onClose, onClickPrint: onClickPrint },
44
44
  React.createElement(ConsultaRfbProvider, { documento: documento },
45
45
  React.createElement(Dossie, { documento: documento, printMode: printMode }),
46
- React.createElement(Liminar, { isFinancial: isFinancial }),
46
+ React.createElement(Liminar, { isFinancial: isFinancial, hasCredits: hasCredits, tags: tags }),
47
47
  React.createElement(Addresses, { apiKey: apiKey }),
48
48
  React.createElement(Contacts, null),
49
49
  React.createElement(Partners, { onClickQSA: onClickQSA })),
@@ -0,0 +1,2 @@
1
+ export declare function hasOneOfTags(userTags: (string | RegExp)[], tagsToVerify: (string | RegExp)[]): boolean;
2
+ export declare function hasAllTags(userTags: (string | RegExp)[], tagsToCompare: (string | RegExp)[]): boolean;
@@ -0,0 +1,37 @@
1
+ function parseValuesArrayToLowerCase() {
2
+ var array = [];
3
+ for (var _i = 0; _i < arguments.length; _i++) {
4
+ array[_i] = arguments[_i];
5
+ }
6
+ return array.map(function (item) {
7
+ return typeof item === 'string' ? item.toLowerCase() : item;
8
+ });
9
+ }
10
+ // Função pura: verifica se um array contém um valor (igualdade simples)
11
+ function contains(array, value) {
12
+ return array.includes(value);
13
+ }
14
+ // Função pura: verifica se pelo menos uma tag está presente
15
+ export function hasOneOfTags(userTags, tagsToVerify) {
16
+ if (!userTags.length || !tagsToVerify.length)
17
+ return false;
18
+ var userTagsLower = parseValuesArrayToLowerCase.apply(void 0, userTags);
19
+ var tagsToVerifyLower = parseValuesArrayToLowerCase.apply(void 0, tagsToVerify);
20
+ return tagsToVerifyLower.some(function (tag) {
21
+ return tag instanceof RegExp
22
+ ? tag.test(userTags.join(','))
23
+ : contains(userTagsLower, tag);
24
+ });
25
+ }
26
+ // Função pura: verifica se todas as tags estão presentes
27
+ export function hasAllTags(userTags, tagsToCompare) {
28
+ if (!userTags.length || !tagsToCompare.length)
29
+ return false;
30
+ var userTagsLower = parseValuesArrayToLowerCase.apply(void 0, userTags);
31
+ var tagsToCompareLower = parseValuesArrayToLowerCase.apply(void 0, tagsToCompare);
32
+ return tagsToCompareLower.every(function (tag) {
33
+ return tag instanceof RegExp
34
+ ? tag.test(userTags.join(','))
35
+ : contains(userTagsLower, tag);
36
+ });
37
+ }