@credithub/harlan-components 1.83.0 → 1.83.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.
|
@@ -57,7 +57,7 @@ import { areModulesLoaded } from '../../utils/isGlobalReady';
|
|
|
57
57
|
import { formatMoney } from '../../utils/number';
|
|
58
58
|
import { isCpf } from '../../utils/string';
|
|
59
59
|
import { Spinner } from 'phosphor-react';
|
|
60
|
-
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
|
60
|
+
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
61
61
|
import styled from 'styled-components';
|
|
62
62
|
import useToggle from '../../hooks/useToggle';
|
|
63
63
|
import { ConsultasComplementaresContext } from '../consultasComplementares';
|
|
@@ -87,16 +87,17 @@ function calcularProtestoLiminar(history) {
|
|
|
87
87
|
return reducao >= 0.8;
|
|
88
88
|
}
|
|
89
89
|
var ChartSystem = function (_a) {
|
|
90
|
-
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
90
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
91
91
|
var documento = _a.documento;
|
|
92
92
|
var ctxConsultasComplementares = useContext(ConsultasComplementaresContext);
|
|
93
|
-
var
|
|
94
|
-
var
|
|
95
|
-
var
|
|
93
|
+
var _m = useConsultasComplementares(), consultasComplementares = _m.consultasComplementares, setConsultasComplementares = _m.setConsultasComplementares, hasCredits = _m.hasCredits;
|
|
94
|
+
var _o = useGlobalData(), globalData = _o.data, setGlobalState = _o.setData;
|
|
95
|
+
var _p = useState(false), dataUpdated = _p[0], setDataUpdated = _p[1];
|
|
96
96
|
var ultimaOcorrenciaCCF = useUltimaOcorrenciaCCF();
|
|
97
97
|
var consultaSerasa = (_c = (_b = ctxConsultasComplementares === null || ctxConsultasComplementares === void 0 ? void 0 : ctxConsultasComplementares.consultasComplementares) === null || _b === void 0 ? void 0 : _b.refinSerasa) === null || _c === void 0 ? void 0 : _c.data;
|
|
98
98
|
var consultaBoaVista = (_e = (_d = ctxConsultasComplementares === null || ctxConsultasComplementares === void 0 ? void 0 : ctxConsultasComplementares.consultasComplementares) === null || _d === void 0 ? void 0 : _d.refinBoaVista) === null || _e === void 0 ? void 0 : _e.data;
|
|
99
|
-
var
|
|
99
|
+
var _q = useState({}), loadingButtons = _q[0], setLoadingButtons = _q[1];
|
|
100
|
+
var refetchTimer = useRef(null);
|
|
100
101
|
var productsPrices = getProductsPrices(isCpf(documento));
|
|
101
102
|
var handleOnClick = function (key) {
|
|
102
103
|
return function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -140,19 +141,44 @@ var ChartSystem = function (_a) {
|
|
|
140
141
|
});
|
|
141
142
|
}); };
|
|
142
143
|
};
|
|
143
|
-
var
|
|
144
|
-
var
|
|
144
|
+
var _r = useChartData(consultaSerasa, consultaBoaVista), chartData = _r.data, isLoadingChart = _r.isLoading, errorChart = _r.error, refetchChart = _r.refetch, chartDataProgress = _r.loadingProgress;
|
|
145
|
+
var _s = useDividasPublicas(), quantidadeDividas = _s.quantidade, valorTotalDividas = _s.valorTotal, ultimaOcorrenciaDividas = _s.ultimaOcorrencia, dividasProgress = _s.loadingProgress;
|
|
146
|
+
var protestosLoaded = ((_f = globalData.protestosData) === null || _f === void 0 ? void 0 : _f.isLoaded) === true;
|
|
147
|
+
var ccfLoaded = ((_g = globalData.ccfData) === null || _g === void 0 ? void 0 : _g.isLoaded) === true;
|
|
148
|
+
var _t = useState(false), chartFetched = _t[0], setChartFetched = _t[1];
|
|
145
149
|
useEffect(function () {
|
|
146
|
-
if (
|
|
147
|
-
|
|
150
|
+
if (protestosLoaded &&
|
|
151
|
+
ccfLoaded &&
|
|
152
|
+
!chartFetched &&
|
|
153
|
+
(consultaSerasa || consultaBoaVista)) {
|
|
154
|
+
if (!refetchTimer.current) {
|
|
155
|
+
refetchTimer.current = setTimeout(function () {
|
|
156
|
+
refetchChart();
|
|
157
|
+
setChartFetched(true);
|
|
158
|
+
refetchTimer.current = null;
|
|
159
|
+
}, 1000);
|
|
160
|
+
}
|
|
148
161
|
}
|
|
149
|
-
|
|
162
|
+
return function () {
|
|
163
|
+
if (refetchTimer.current) {
|
|
164
|
+
clearTimeout(refetchTimer.current);
|
|
165
|
+
refetchTimer.current = null;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}, [
|
|
169
|
+
protestosLoaded,
|
|
170
|
+
ccfLoaded,
|
|
171
|
+
chartFetched,
|
|
172
|
+
consultaSerasa,
|
|
173
|
+
consultaBoaVista,
|
|
174
|
+
refetchChart
|
|
175
|
+
]);
|
|
150
176
|
var errorMessage = typeof errorChart === 'string' ? new Error(errorChart) : errorChart;
|
|
151
177
|
var isOpen = useToggle(true)[0];
|
|
152
|
-
var quantidadeProtestos = ((
|
|
153
|
-
var valorTotalProtestos = ((
|
|
154
|
-
var
|
|
155
|
-
var
|
|
178
|
+
var quantidadeProtestos = ((_j = (_h = chartData === null || chartData === void 0 ? void 0 : chartData.protestos) === null || _h === void 0 ? void 0 : _h[(chartData === null || chartData === void 0 ? void 0 : chartData.protestos.length) - 1]) === null || _j === void 0 ? void 0 : _j.quantidade) || 0;
|
|
179
|
+
var valorTotalProtestos = ((_l = (_k = chartData === null || chartData === void 0 ? void 0 : chartData.protestos) === null || _k === void 0 ? void 0 : _k[(chartData === null || chartData === void 0 ? void 0 : chartData.protestos.length) - 1]) === null || _l === void 0 ? void 0 : _l.valorTotal) || 0;
|
|
180
|
+
var _u = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.serasa) || []), quantidadeSerasa = _u.quantidade, valorTotalSerasa = _u.valorTotal, ultimaOcorrenciaSerasa = _u.dataMaisRecente;
|
|
181
|
+
var _v = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.boaVista) || []), quantidadeBoaVista = _v.quantidade, valorTotalBoaVista = _v.valorTotal, ultimaOcorrenciaBoaVista = _v.dataMaisRecente;
|
|
156
182
|
var quantidadeCCFs = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.ccfs) || []).quantidade;
|
|
157
183
|
var ultimaOcorrenciaProtestos = '';
|
|
158
184
|
if ((chartData === null || chartData === void 0 ? void 0 : chartData.protestosCategory) && chartData.protestosCategory.length > 0) {
|
|
@@ -226,9 +252,10 @@ var ChartSystem = function (_a) {
|
|
|
226
252
|
setGlobalState,
|
|
227
253
|
ultimaOcorrenciaCCF
|
|
228
254
|
]);
|
|
255
|
+
var effectiveLoading = isLoadingChart || !protestosLoaded || !ccfLoaded;
|
|
229
256
|
return (React.createElement(Section, { ctx: {
|
|
230
257
|
response: undefined,
|
|
231
|
-
type:
|
|
258
|
+
type: effectiveLoading
|
|
232
259
|
? RequestStatus.Loading
|
|
233
260
|
: errorChart
|
|
234
261
|
? RequestStatus.Error
|
|
@@ -241,8 +268,8 @@ var ChartSystem = function (_a) {
|
|
|
241
268
|
}, title: "Resumo de Negativa\u00E7\u00F5es", subtitle: "Veja a quantidade de ocorr\u00EAncias conforme o documento foi consultado ao longo do tempo", icon: ResumoDeNegativacoesIcon, onSuccess: function () {
|
|
242
269
|
var _a, _b, _c;
|
|
243
270
|
return (React.createElement(Content, { isOpen: isOpen },
|
|
244
|
-
chartData && React.createElement(ChartContent, { dataInput: chartData }),
|
|
245
|
-
React.createElement(QuantidadeResultados, { data: chartData, consultarSerasa: React.createElement(ButtonsSummary, { style: {
|
|
271
|
+
chartData && protestosLoaded && ccfLoaded ? (React.createElement(ChartContent, { dataInput: chartData })) : (React.createElement(Spinner, null)),
|
|
272
|
+
chartData && protestosLoaded && ccfLoaded && (React.createElement(QuantidadeResultados, { data: chartData, consultarSerasa: React.createElement(ButtonsSummary, { style: {
|
|
246
273
|
display: loadingButtons['refinSerasa'] ||
|
|
247
274
|
((_a = consultasComplementares === null || consultasComplementares === void 0 ? void 0 : consultasComplementares.refinSerasa) === null || _a === void 0 ? void 0 : _a.consultaRealizada)
|
|
248
275
|
? 'none'
|
|
@@ -265,7 +292,7 @@ var ChartSystem = function (_a) {
|
|
|
265
292
|
? (ultimaOcorrenciaBoaVista !== null && ultimaOcorrenciaBoaVista !== void 0 ? ultimaOcorrenciaBoaVista : undefined)
|
|
266
293
|
: undefined, ultimaOcorrenciaPefinSerasa: Array.isArray(chartData === null || chartData === void 0 ? void 0 : chartData.serasa) && chartData.serasa.length > 0
|
|
267
294
|
? (ultimaOcorrenciaSerasa !== null && ultimaOcorrenciaSerasa !== void 0 ? ultimaOcorrenciaSerasa : undefined)
|
|
268
|
-
: undefined })));
|
|
295
|
+
: undefined }))));
|
|
269
296
|
}, isError: function (err) { return ({
|
|
270
297
|
children: React.createElement(React.Fragment, null),
|
|
271
298
|
description: (React.createElement(StatusMessage, { type: "error" },
|
|
@@ -184,8 +184,9 @@ var Liminar = function (_a) {
|
|
|
184
184
|
(_f = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _f === void 0 ? void 0 : _f.indiciosDeLiminarProtestosDoPassado
|
|
185
185
|
]), origensDetectadas = _w.origensDetectadas, foundBusinessEntity = _w.foundBusinessEntity;
|
|
186
186
|
var documentHistoryReady = useMemo(function () { return isDocumentHistoryReady(globalData); }, [globalData]);
|
|
187
|
+
var protestosIsReady = useMemo(function () { var _a; return (_a = globalData === null || globalData === void 0 ? void 0 : globalData.protestosData) === null || _a === void 0 ? void 0 : _a.isLoaded; }, [globalData]);
|
|
187
188
|
useEffect(function () {
|
|
188
|
-
if (!documentHistoryReady)
|
|
189
|
+
if (!documentHistoryReady || !protestosIsReady)
|
|
189
190
|
return;
|
|
190
191
|
var fetch = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
191
192
|
var dossie, processosJuridicos, depsLoaded, newIds, hash, indiciosApi, indiciosDeLiminarProtestosDoPassado, protestosDoPassadoIds, _a, possuiIndiciosDeLiminarProtestosDoPassado, protestosIds, finalStatus, descricaoLiminar;
|
|
@@ -38,6 +38,7 @@ import XPathUtils from '../../utils/xpath';
|
|
|
38
38
|
import { Client } from '@credithub/webservice';
|
|
39
39
|
import { useCallback, useContext } from 'react';
|
|
40
40
|
import { WebService } from '../webservice';
|
|
41
|
+
import { useGlobalData } from '../../contexts/globalDataContext';
|
|
41
42
|
/**
|
|
42
43
|
* Hook que identifica indícios de liminar de sustação de protesto.
|
|
43
44
|
*
|
|
@@ -51,6 +52,7 @@ import { WebService } from '../webservice';
|
|
|
51
52
|
var useLiminarProtestosDoPassado = function (_a) {
|
|
52
53
|
var documento = _a.documento;
|
|
53
54
|
var client = useContext(WebService);
|
|
55
|
+
var globalData = useGlobalData().data;
|
|
54
56
|
/** Máximo de requisições simultâneas ao endpoint de PDF. */
|
|
55
57
|
var MAX_CONCURRENT = 10;
|
|
56
58
|
/** Timeout (ms) por requisição individual ao PDF. */
|
|
@@ -97,7 +99,7 @@ var useLiminarProtestosDoPassado = function (_a) {
|
|
|
97
99
|
case 2:
|
|
98
100
|
parsed = (_a.sent());
|
|
99
101
|
nodes = XPathUtils.selectArray('//protesto/nm_chave', parsed);
|
|
100
|
-
numerosChave = Array.from(new Set(nodes.map(function (n) { return n.textContent || ''; })));
|
|
102
|
+
numerosChave = Array.from(new Set(nodes.map(function (n) { return n.textContent || ''; }))).filter(function (e) { var _a; return !(((_a = globalData === null || globalData === void 0 ? void 0 : globalData.protestosData) === null || _a === void 0 ? void 0 : _a.nmChaves) || []).includes(e); });
|
|
101
103
|
ocultos = [];
|
|
102
104
|
idx = 0;
|
|
103
105
|
running = [];
|