@credithub/harlan-components 1.120.2 → 1.120.4

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.
@@ -1,8 +1,34 @@
1
1
  import { Queries, RequestStatus } from '../../../components/webservice';
2
2
  import { useGlobalData } from '../../../contexts/globalDataContext';
3
- import { converterParaFormatoValido } from '../../../utils/date';
3
+ import { converterParaFormatoValido, formatDatePtBrToDate } from '../../../utils/date';
4
4
  import { useContext, useEffect, useMemo, useRef, useState } from 'react';
5
5
  import { processData, processProtestData } from '../utils/dataProcessing';
6
+ function getLastQuantidadeProcessosFromHistory(parsed) {
7
+ var _a;
8
+ var arr = parsed === null || parsed === void 0 ? void 0 : parsed.processosJuridicos;
9
+ if (!Array.isArray(arr) || arr.length === 0)
10
+ return 0;
11
+ var withTime = arr
12
+ .map(function (e) {
13
+ var _a;
14
+ try {
15
+ var t = typeof e.data === 'string'
16
+ ? new Date(formatDatePtBrToDate(e.data)).getTime()
17
+ : e.data instanceof Date
18
+ ? e.data.getTime()
19
+ : NaN;
20
+ return { quantidade: (_a = e.quantidade) !== null && _a !== void 0 ? _a : 0, t: t };
21
+ }
22
+ catch (_b) {
23
+ return { quantidade: 0, t: NaN };
24
+ }
25
+ })
26
+ .filter(function (e) { return !isNaN(e.t); });
27
+ if (withTime.length === 0)
28
+ return 0;
29
+ var last = withTime.sort(function (a, b) { return b.t - a.t; })[0];
30
+ return (_a = last === null || last === void 0 ? void 0 : last.quantidade) !== null && _a !== void 0 ? _a : 0;
31
+ }
6
32
  var useChartData = function (consultaSerasa, consultaBoaVista) {
7
33
  var _a, _b, _c;
8
34
  var _d = useState(null), data = _d[0], setData = _d[1];
@@ -19,12 +45,12 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
19
45
  var ctxProcessos = useContext(Queries.ProcessosJuridicos);
20
46
  var globalData = useGlobalData().data;
21
47
  var iaOverrides = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.protestosData) === null || _a === void 0 ? void 0 : _a.iaOverrides;
22
- var quantidadeProcessos = useMemo(function () {
48
+ var quantidadeProcessosFromPJ = useMemo(function () {
23
49
  var _a, _b, _c;
24
50
  if (ctxProcessos.type === RequestStatus.Success) {
25
51
  return (_c = (_b = (_a = ctxProcessos.document) === null || _a === void 0 ? void 0 : _a.empresa) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
26
52
  }
27
- return 0;
53
+ return null;
28
54
  }, [ctxProcessos.type, ctxProcessos.document]);
29
55
  // Calcula dados de categorias a partir dos dados já processados em globalData
30
56
  // ou fallback para processamento do documento se globalData ainda não estiver disponível
@@ -149,17 +175,12 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
149
175
  }
150
176
  // eslint-disable-next-line react-hooks/exhaustive-deps
151
177
  }, [consultaSerasa, consultaBoaVista]);
152
- // Verifica se todos os contextos necessários terminaram de carregar
178
+ // History, Protestos e CCF são obrigatórios; Processos Jurídicos não bloqueia (usa fallback do history)
153
179
  var allContextsReady = useMemo(function () {
154
- return (ctxHistory.type !== RequestStatus.Loading &&
155
- ctxProtestos.type !== RequestStatus.Loading &&
156
- ctxCCF.type !== RequestStatus.Loading &&
157
- ctxProcessos.type !== RequestStatus.Loading &&
158
- ctxHistory.type === RequestStatus.Success &&
180
+ return ctxHistory.type === RequestStatus.Success &&
159
181
  ctxProtestos.type === RequestStatus.Success &&
160
- ctxCCF.type === RequestStatus.Success &&
161
- (ctxProcessos.type === RequestStatus.Success || ctxProcessos.type === RequestStatus.Error));
162
- }, [ctxHistory.type, ctxProtestos.type, ctxCCF.type, ctxProcessos.type]);
182
+ ctxCCF.type === RequestStatus.Success;
183
+ }, [ctxHistory.type, ctxProtestos.type, ctxCCF.type]);
163
184
  useEffect(function () {
164
185
  var _a;
165
186
  // Limpa timeout anterior se existir
@@ -167,11 +188,10 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
167
188
  clearTimeout(processingTimeout.current);
168
189
  processingTimeout.current = null;
169
190
  }
170
- // Reset quando qualquer contexto volta para Loading
191
+ // Reset quando algum dos contextos obrigatórios volta para Loading (PJ não bloqueia)
171
192
  if (ctxHistory.type === RequestStatus.Loading ||
172
193
  ctxProtestos.type === RequestStatus.Loading ||
173
- ctxCCF.type === RequestStatus.Loading ||
174
- ctxProcessos.type === RequestStatus.Loading) {
194
+ ctxCCF.type === RequestStatus.Loading) {
175
195
  setDataReady(false);
176
196
  setErrorState(null);
177
197
  setIsProcessing(false);
@@ -203,6 +223,7 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
203
223
  }
204
224
  var parsed = JSON.parse(documentSnapshot_1);
205
225
  parsed.protestosCategory = dadosProtestos;
226
+ var quantidadeProcessos = quantidadeProcessosFromPJ !== null && quantidadeProcessosFromPJ !== void 0 ? quantidadeProcessosFromPJ : getLastQuantidadeProcessosFromHistory(parsed);
206
227
  var processed = processData(structuredClone(parsed), quantidadeProcessos, totalProtestos, valorTotalProtestos, ultimaOcorrenciaProtestos);
207
228
  setData(processed);
208
229
  setIsProcessing(false);
@@ -223,10 +244,9 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
223
244
  ctxHistory.type,
224
245
  ctxProtestos.type,
225
246
  ctxCCF.type,
226
- ctxProcessos.type,
227
247
  ctxHistory.document,
228
248
  dadosProtestos,
229
- quantidadeProcessos,
249
+ quantidadeProcessosFromPJ,
230
250
  totalProtestos,
231
251
  valorTotalProtestos,
232
252
  ultimaOcorrenciaProtestos,
@@ -232,14 +232,13 @@ export var ProtestoItem = memo(function (_a) {
232
232
  return React.createElement(ThreeDotsLoader, null);
233
233
  return quemApresentou || '';
234
234
  };
235
- return (React.createElement(ResultContent, { print: "repeat(7, 1fr)", desktop: "repeat(8, 1fr)", tablet: "repeat(4, 1fr)", mobile: "repeat(2, 1fr)" },
235
+ return (React.createElement(ResultContent, { print: "repeat(6, 1fr)", desktop: "repeat(7, 1fr)", tablet: "repeat(4, 1fr)", mobile: "repeat(2, 1fr)" },
236
236
  React.createElement(AddItemField, { name: "Quem Protestou", value: getQuemProtestouDisplay() }),
237
237
  React.createElement(AddItemField, { name: "Atrav\u00E9s De", value: protesto.nomeApresentante }),
238
238
  React.createElement(AddItemField, { name: "Data Do Protesto", value: protesto.dataProtesto }),
239
239
  React.createElement(AddItemField, { name: "Possui Anu\u00EAncia / Protesto Pago", value: formatBooleanField(String(protesto.temAnuencia)) }),
240
240
  React.createElement(AddItemField, { name: "Valor Do Protesto", value: formatMoney(protesto.valor) }),
241
241
  React.createElement(AddItemField, { name: "Custas de Cart\u00F3rio para Baixa", value: protesto.vl_custas ? formatMoney(protesto.vl_custas) : '—' }),
242
- React.createElement(AddItemField, { name: "UF", value: React.createElement(UfCell, { uf: cartorio === null || cartorio === void 0 ? void 0 : cartorio.uf, hasCartorio: Boolean(cartorio), onOpenCartorio: onOpenCartorioModal }) }),
243
242
  showInstrumento && React.createElement(Instrumento, { nm_chave: nm_chave, cpfCnpj: documento })));
244
243
  });
245
244
  export var Instrumento = function (_a) {
@@ -48,8 +48,7 @@ var GraficosAnaliticosDependency = function (_a) {
48
48
  var children = _a.children, documento = _a.documento;
49
49
  var ctxCCF = useContext(Queries.CCF);
50
50
  var ctxProtestos = useContext(Queries.Protestos);
51
- var ctxProcessosJuridicos = useContext(Queries.ProcessosJuridicos);
52
- return (React.createElement(Queries.GraficosAnaliticos.Request, { data: { documento: documento }, depends: [ctxCCF, ctxProtestos, ctxProcessosJuridicos] }, children));
51
+ return (React.createElement(Queries.GraficosAnaliticos.Request, { data: { documento: documento }, depends: [ctxCCF, ctxProtestos] }, children));
53
52
  };
54
53
  var HasCreditsVerification = function (_a) {
55
54
  var children = _a.children, documento = _a.documento, apiKey = _a.apiKey;