@credithub/harlan-components 1.83.1 → 1.83.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.
@@ -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';
@@ -97,6 +97,7 @@ var ChartSystem = function (_a) {
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
99
  var _o = useState({}), loadingButtons = _o[0], setLoadingButtons = _o[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 () {
@@ -142,17 +143,37 @@ var ChartSystem = function (_a) {
142
143
  };
143
144
  var _p = useChartData(consultaSerasa, consultaBoaVista), chartData = _p.data, isLoadingChart = _p.isLoading, errorChart = _p.error, refetchChart = _p.refetch, chartDataProgress = _p.loadingProgress;
144
145
  var _q = useDividasPublicas(), quantidadeDividas = _q.quantidade, valorTotalDividas = _q.valorTotal, ultimaOcorrenciaDividas = _q.ultimaOcorrencia, dividasProgress = _q.loadingProgress;
146
+ var modulesReady = useMemo(function () { return areModulesLoaded(globalData); }, [globalData]);
147
+ var _r = useState(false), chartFetched = _r[0], setChartFetched = _r[1];
145
148
  useEffect(function () {
146
- if (consultaSerasa || consultaBoaVista) {
147
- refetchChart();
149
+ if (modulesReady && !chartFetched && (consultaSerasa || consultaBoaVista)) {
150
+ if (!refetchTimer.current) {
151
+ refetchTimer.current = setTimeout(function () {
152
+ refetchChart();
153
+ setChartFetched(true);
154
+ refetchTimer.current = null;
155
+ }, 1000);
156
+ }
148
157
  }
149
- }, [consultaSerasa, consultaBoaVista, refetchChart]);
158
+ return function () {
159
+ if (refetchTimer.current) {
160
+ clearTimeout(refetchTimer.current);
161
+ refetchTimer.current = null;
162
+ }
163
+ };
164
+ }, [
165
+ modulesReady,
166
+ chartFetched,
167
+ consultaSerasa,
168
+ consultaBoaVista,
169
+ refetchChart
170
+ ]);
150
171
  var errorMessage = typeof errorChart === 'string' ? new Error(errorChart) : errorChart;
151
172
  var isOpen = useToggle(true)[0];
152
173
  var quantidadeProtestos = ((_g = (_f = chartData === null || chartData === void 0 ? void 0 : chartData.protestos) === null || _f === void 0 ? void 0 : _f[(chartData === null || chartData === void 0 ? void 0 : chartData.protestos.length) - 1]) === null || _g === void 0 ? void 0 : _g.quantidade) || 0;
153
174
  var valorTotalProtestos = ((_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.valorTotal) || 0;
154
- var _r = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.serasa) || []), quantidadeSerasa = _r.quantidade, valorTotalSerasa = _r.valorTotal, ultimaOcorrenciaSerasa = _r.dataMaisRecente;
155
- var _s = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.boaVista) || []), quantidadeBoaVista = _s.quantidade, valorTotalBoaVista = _s.valorTotal, ultimaOcorrenciaBoaVista = _s.dataMaisRecente;
175
+ var _s = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.serasa) || []), quantidadeSerasa = _s.quantidade, valorTotalSerasa = _s.valorTotal, ultimaOcorrenciaSerasa = _s.dataMaisRecente;
176
+ var _t = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.boaVista) || []), quantidadeBoaVista = _t.quantidade, valorTotalBoaVista = _t.valorTotal, ultimaOcorrenciaBoaVista = _t.dataMaisRecente;
156
177
  var quantidadeCCFs = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.ccfs) || []).quantidade;
157
178
  var ultimaOcorrenciaProtestos = '';
158
179
  if ((chartData === null || chartData === void 0 ? void 0 : chartData.protestosCategory) && chartData.protestosCategory.length > 0) {
@@ -174,7 +195,6 @@ var ChartSystem = function (_a) {
174
195
  }
175
196
  }
176
197
  var loadingProgress = (chartDataProgress + dividasProgress) / 2;
177
- var modulesReady = useMemo(function () { return areModulesLoaded(globalData); }, [globalData]);
178
198
  useEffect(function () {
179
199
  var _a, _b;
180
200
  if (!dataUpdated && chartData && modulesReady) {
@@ -226,9 +246,10 @@ var ChartSystem = function (_a) {
226
246
  setGlobalState,
227
247
  ultimaOcorrenciaCCF
228
248
  ]);
249
+ var effectiveLoading = isLoadingChart || !modulesReady;
229
250
  return (React.createElement(Section, { ctx: {
230
251
  response: undefined,
231
- type: isLoadingChart
252
+ type: effectiveLoading
232
253
  ? RequestStatus.Loading
233
254
  : errorChart
234
255
  ? RequestStatus.Error
@@ -241,8 +262,8 @@ var ChartSystem = function (_a) {
241
262
  }, 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
263
  var _a, _b, _c;
243
264
  return (React.createElement(Content, { isOpen: isOpen },
244
- chartData && React.createElement(ChartContent, { dataInput: chartData }),
245
- React.createElement(QuantidadeResultados, { data: chartData, consultarSerasa: React.createElement(ButtonsSummary, { style: {
265
+ chartData && modulesReady ? (React.createElement(ChartContent, { dataInput: chartData })) : (React.createElement(Spinner, null)),
266
+ chartData && modulesReady && (React.createElement(QuantidadeResultados, { data: chartData, consultarSerasa: React.createElement(ButtonsSummary, { style: {
246
267
  display: loadingButtons['refinSerasa'] ||
247
268
  ((_a = consultasComplementares === null || consultasComplementares === void 0 ? void 0 : consultasComplementares.refinSerasa) === null || _a === void 0 ? void 0 : _a.consultaRealizada)
248
269
  ? 'none'
@@ -265,7 +286,7 @@ var ChartSystem = function (_a) {
265
286
  ? (ultimaOcorrenciaBoaVista !== null && ultimaOcorrenciaBoaVista !== void 0 ? ultimaOcorrenciaBoaVista : undefined)
266
287
  : undefined, ultimaOcorrenciaPefinSerasa: Array.isArray(chartData === null || chartData === void 0 ? void 0 : chartData.serasa) && chartData.serasa.length > 0
267
288
  ? (ultimaOcorrenciaSerasa !== null && ultimaOcorrenciaSerasa !== void 0 ? ultimaOcorrenciaSerasa : undefined)
268
- : undefined })));
289
+ : undefined }))));
269
290
  }, isError: function (err) { return ({
270
291
  children: React.createElement(React.Fragment, null),
271
292
  description: (React.createElement(StatusMessage, { type: "error" },