@credithub/harlan-components 1.62.1 → 1.62.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.
@@ -48,6 +48,7 @@ var CCF = function () {
48
48
  }
49
49
  if (ctx.type === RequestStatus.Error || ctx.type === RequestStatus.Empty) {
50
50
  setData(function (prevState) { return (__assign(__assign({}, prevState), { ccfData: { isLoaded: true } })); });
51
+ return;
51
52
  }
52
53
  var data = ctx.document;
53
54
  var _a = processData(data), ccfData = _a.ccfData, totalOcorrencias = _a.totalOcorrencias, ultimoRegistro = _a.ultimoRegistro;
@@ -55,6 +55,7 @@ var DividasPublicas = function () {
55
55
  var dividas = parseDividas(ctx.document);
56
56
  if (ctx.type === RequestStatus.Error || ctx.type === RequestStatus.Empty) {
57
57
  setData(function (prevState) { return (__assign(__assign({}, prevState), { divida: { isLoaded: true } })); });
58
+ return;
58
59
  }
59
60
  if (!dataUpdated) {
60
61
  var dividasPublicas_1 = XPathUtils.select('number(//dividas/resumo/valor_total_dividas)', ctx.document) || 0;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- declare const ProcessosJuridicos: React.FC<{
2
+ declare const _default: React.NamedExoticComponent<{
3
3
  onClickConsultarProcessoJuridico?: (processo: string) => void;
4
4
  }>;
5
- export default ProcessosJuridicos;
5
+ export default _default;
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import ProcessosJuridicosIcon from '../../assets/icones/processosJuridicos';
13
13
  import { useGlobalData } from '../../contexts/globalDataContext';
14
- import React, { useContext, useEffect, useRef } from 'react';
14
+ import React, { useCallback, useContext, useEffect, useRef } from 'react';
15
15
  import StatusMessage from '../interface/statusMessage';
16
16
  import Section from '../section';
17
17
  import { Queries, RequestStatus } from '../webservice';
@@ -20,34 +20,27 @@ var ProcessosJuridicos = function (_a) {
20
20
  var onClickConsultarProcessoJuridico = _a.onClickConsultarProcessoJuridico;
21
21
  var ctx = useContext(Queries.ProcessosJuridicos);
22
22
  var setData = useGlobalData().setData;
23
- // Use a ref instead of state to track whether data has been processed
23
+ // Refs para evitar processamento desnecessário
24
24
  var processedRef = useRef(false);
25
25
  var ctxHashRef = useRef('');
26
- useEffect(function () {
27
- if (ctx.type === RequestStatus.Loading) {
28
- processedRef.current = false;
29
- setData(function (prevState) { return (__assign(__assign({}, prevState), { processosJuridicosData: __assign(__assign({}, prevState.processosJuridicosData), { isLoaded: false }) })); });
30
- }
31
- }, [ctx.type, setData]);
32
26
  useEffect(function () {
33
27
  var _a;
34
- // Create a hash of the current context state to detect changes
28
+ // Gera um hash para detectar mudanças relevantes no contexto
35
29
  var currentCtxHash = JSON.stringify({
36
30
  type: ctx.type,
37
- documentId: ctx.document ? true : false
31
+ documentId: !!ctx.document
38
32
  });
39
- // Skip if we've already processed this data state
33
+ // Se o estado não mudou e foi processado, sai
40
34
  if (currentCtxHash === ctxHashRef.current && processedRef.current) {
41
35
  return;
42
36
  }
43
- // Update our reference to the current context
37
+ // Atualiza o hash atual
44
38
  ctxHashRef.current = currentCtxHash;
45
- // Handle error or empty response
39
+ // Caso de erro ou resposta vazia
46
40
  if ((ctx.type === RequestStatus.Error || ctx.type === RequestStatus.Empty) &&
47
41
  !processedRef.current) {
48
42
  setData(function (prevState) {
49
43
  var _a;
50
- // Avoid unnecessary state updates if data hasn't changed
51
44
  if (((_a = prevState.processosJuridicosData) === null || _a === void 0 ? void 0 : _a.isLoaded) &&
52
45
  Array.isArray(prevState.processosJuridicosData.empresa) &&
53
46
  prevState.processosJuridicosData.empresa.length === 0) {
@@ -61,7 +54,7 @@ var ProcessosJuridicos = function (_a) {
61
54
  processedRef.current = true;
62
55
  return;
63
56
  }
64
- // Handle successful response
57
+ // Caso de resposta bem-sucedida
65
58
  if (ctx.type === RequestStatus.Success &&
66
59
  !processedRef.current &&
67
60
  ctx.document) {
@@ -73,7 +66,6 @@ var ProcessosJuridicos = function (_a) {
73
66
  };
74
67
  setData(function (prevState) {
75
68
  var _a;
76
- // Avoid unnecessary state updates
77
69
  if (((_a = prevState.processosJuridicosData) === null || _a === void 0 ? void 0 : _a.isLoaded) &&
78
70
  JSON.stringify(prevState.processosJuridicosData.empresa) ===
79
71
  JSON.stringify(processosJuridicosData_1.empresa)) {
@@ -85,26 +77,29 @@ var ProcessosJuridicos = function (_a) {
85
77
  }
86
78
  }
87
79
  }, [ctx.type, ctx.document, setData]);
88
- // Reset processed state when context changes to loading
80
+ // Reseta o estado processado ao iniciar novo carregamento
89
81
  useEffect(function () {
90
82
  if (ctx.type === RequestStatus.Loading) {
91
83
  processedRef.current = false;
84
+ setData(function (prevState) { return (__assign(__assign({}, prevState), { processosJuridicosData: __assign(__assign({}, prevState.processosJuridicosData), { isLoaded: false }) })); });
92
85
  }
93
- }, [ctx.type]);
94
- return (React.createElement(Section, { ctx: ctx, title: "Processos Jur\u00EDdicos", subtitle: "Veja os processos jur\u00EDdicos para este documento.", icon: ProcessosJuridicosIcon, minimized: false, onSuccess: function (data) {
95
- var _a;
96
- var qtyProcessos = (_a = data.empresa) === null || _a === void 0 ? void 0 : _a.length;
97
- var children = qtyProcessos ? (React.createElement(ProcessosJuridicosList, { processos: data.empresa || [], onClickConsultarProcessoJuridico: onClickConsultarProcessoJuridico })) : null;
98
- return {
99
- children: children,
100
- description: (React.createElement(StatusMessage, { type: qtyProcessos ? 'error' : 'default' }, qtyProcessos
101
- ? 'Pesquisa concluída, ' +
102
- (qtyProcessos > 1
103
- ? "foram encontrados ".concat(qtyProcessos, " processos")
104
- : 'foi encontrado 1 processo')
105
- : 'Não foram encontrados processos jurídicos para o documento pesquisado')),
106
- variant: qtyProcessos ? 'error' : 'default'
107
- };
108
- } }));
86
+ }, [ctx.type, setData]);
87
+ // Ajustamos a função para receber dois parâmetros e garantir que 'variant' seja do tipo literal esperado
88
+ var handleSuccess = useCallback(function (data, _ctx) {
89
+ var _a;
90
+ var qtyProcessos = (_a = data.empresa) === null || _a === void 0 ? void 0 : _a.length;
91
+ var children = qtyProcessos ? (React.createElement(ProcessosJuridicosList, { processos: data.empresa || [], onClickConsultarProcessoJuridico: onClickConsultarProcessoJuridico })) : null;
92
+ var variant = qtyProcessos ? 'error' : 'default';
93
+ return {
94
+ children: children,
95
+ description: (React.createElement(StatusMessage, { type: qtyProcessos ? 'error' : 'default' }, qtyProcessos
96
+ ? "Pesquisa conclu\u00EDda, ".concat(qtyProcessos > 1
97
+ ? "foram encontrados ".concat(qtyProcessos, " processos")
98
+ : 'foi encontrado 1 processo')
99
+ : 'Não foram encontrados processos jurídicos para o documento pesquisado')),
100
+ variant: variant
101
+ };
102
+ }, [onClickConsultarProcessoJuridico]);
103
+ return (React.createElement(Section, { ctx: ctx, title: "Processos Jur\u00EDdicos", subtitle: "Veja os processos jur\u00EDdicos para este documento.", icon: ProcessosJuridicosIcon, minimized: false, onSuccess: handleSuccess }));
109
104
  };
110
- export default ProcessosJuridicos;
105
+ export default React.memo(ProcessosJuridicos);
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
- declare const Protestos: React.FC;
3
- export default Protestos;
2
+ declare const _default: React.NamedExoticComponent<{}>;
3
+ export default _default;
@@ -22,7 +22,7 @@ import { useGlobalData } from '../../contexts/globalDataContext';
22
22
  import { formatDatePtBrToDate } from '../../utils/date';
23
23
  import { extractIntegerFromText } from '../../utils/number';
24
24
  import XPathUtils from '../../utils/xpath';
25
- import React, { useContext, useEffect, useMemo, useState } from 'react';
25
+ import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
26
26
  import styled from 'styled-components';
27
27
  import StatusMessage from '../interface/statusMessage';
28
28
  import Section from '../section';
@@ -30,6 +30,7 @@ import { Queries, RequestStatus } from '../webservice';
30
30
  import ProtestosCategory from './protestosCategory';
31
31
  import { ProtestoItem } from './protestosList';
32
32
  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"])));
33
+ // Função de ordenação por data
33
34
  var byDate = function (protesto, protesto2) {
34
35
  var _a, _b;
35
36
  var v0 = ((_a = formatDatePtBrToDate(XPathUtils.select('string(./dataProtesto)', protesto2))) === null || _a === void 0 ? void 0 : _a.getTime()) || 0;
@@ -41,25 +42,31 @@ var Protestos = function () {
41
42
  var ctxLiminar = useContext(Queries.Liminar);
42
43
  var setData = useGlobalData().setData;
43
44
  var _a = useState(false), dataUpdated = _a[0], setDataUpdated = _a[1];
45
+ // Calcula o total e memorizamos esse valor para evitar recalcular a cada render
44
46
  var total = useMemo(function () {
45
- var _a, _b;
46
- if ((ctxLiminar === null || ctxLiminar === void 0 ? void 0 : ctxLiminar.type) === RequestStatus.Success)
47
- return (((_b = (_a = ctxLiminar === null || ctxLiminar === void 0 ? void 0 : ctxLiminar.document) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.reduce(function (carry, e) { return carry + Number(e === null || e === void 0 ? void 0 : e[9]); }, 0)) || 0);
47
+ var _a;
48
+ if ((ctxLiminar === null || ctxLiminar === void 0 ? void 0 : ctxLiminar.type) === RequestStatus.Success &&
49
+ ((_a = ctxLiminar.document) === null || _a === void 0 ? void 0 : _a.data)) {
50
+ return (ctxLiminar.document.data.reduce(function (carry, e) { return carry + Number(e === null || e === void 0 ? void 0 : e[9]); }, 0) || 0);
51
+ }
48
52
  return 0;
49
- }, [ctxLiminar === null || ctxLiminar === void 0 ? void 0 : ctxLiminar.type]);
53
+ }, [ctxLiminar === null || ctxLiminar === void 0 ? void 0 : ctxLiminar.type, ctxLiminar === null || ctxLiminar === void 0 ? void 0 : ctxLiminar.document]);
54
+ // Processa os protestos e atualiza o contexto global (apenas quando ctx.document é válido e o processamento ainda não ocorreu)
50
55
  useEffect(function () {
51
56
  if (dataUpdated || !ctx.document) {
52
57
  return;
53
58
  }
54
- if (ctx.type === RequestStatus.Error) {
55
- setData(function (prevState) { return (__assign(__assign({}, prevState), { protestosData: { isLoaded: true } })); });
56
- }
57
59
  var data = ctx.document;
58
60
  var registrosText = XPathUtils.select('string(//registros)', data);
59
61
  var haveException = /Falha na integra/gi.test(XPathUtils.select('string(//raw)', data));
60
62
  var registros = haveException
61
63
  ? extractIntegerFromText(registrosText) + total
62
64
  : extractIntegerFromText(registrosText);
65
+ if (haveException) {
66
+ setData(function (prevState) { return (__assign(__assign({}, prevState), { protestosData: { isLoaded: true } })); });
67
+ setDataUpdated(true);
68
+ return;
69
+ }
63
70
  var filterProtestos = function (regex, data) {
64
71
  return XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
65
72
  return regex.test(XPathUtils.select('string(./nomeCedente)', protesto));
@@ -83,58 +90,61 @@ var Protestos = function () {
83
90
  };
84
91
  setData(function (prevState) { return (__assign(__assign({}, prevState), { protestos: registros, protestosData: protestosState })); });
85
92
  setDataUpdated(true);
86
- }, [ctx, setData, dataUpdated]);
87
- 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: function (data) {
88
- var registrosText = XPathUtils.select('string(//registros)', data);
89
- var haveException = /Falha na integra/gi.test(XPathUtils.select('string(//raw)', data));
90
- var registros = haveException
91
- ? extractIntegerFromText(registrosText) + total
92
- : extractIntegerFromText(registrosText);
93
- var protestosDeCredito = XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
94
- return REGEX_PROTESTOS_DE_CREDITO.test(XPathUtils.select('string(./nomeCedente)', protesto));
95
- });
96
- var protestosDeImposto = XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
97
- return REGEX_PROTESTOS_DE_IMPOSTO.test(XPathUtils.select('string(./nomeCedente)', protesto));
98
- });
99
- var protestosGerais = XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
100
- var nomeCedente = XPathUtils.select('string(./nomeCedente)', protesto);
101
- return (!REGEX_PROTESTOS_DE_IMPOSTO.test(nomeCedente) &&
102
- !REGEX_PROTESTOS_DE_CREDITO.test(nomeCedente));
103
- });
104
- var elements = [
105
- {
106
- total: protestosDeCredito.length,
107
- element: (React.createElement(ProtestosCategory, { title: "Protestos de Cr\u00E9dito", subtitle: "Protestos de cr\u00E9dito em geral.", registros: protestosDeCredito.length, icon: ProtestosCreditoIcon }, protestosDeCredito
108
- .sort(byDate)
109
- .map(function (protesto, i) { return (React.createElement(ProtestoItem, { protesto: protesto, key: i })); })))
110
- },
111
- {
112
- total: protestosDeImposto.length,
113
- element: (React.createElement(ProtestosCategory, { title: "Protestos de Imposto", subtitle: "Protestos de impostos federais, estaduais e municipais.", registros: protestosDeImposto.length, icon: ProtestosImpostosIcon }, protestosDeImposto
114
- .sort(byDate)
115
- .map(function (protestoElement, index) { return (React.createElement(ProtestoItem, { protesto: protestoElement, key: index })); })))
116
- },
117
- {
118
- total: protestosGerais.length,
119
- element: (React.createElement(ProtestosCategory, { title: "Protestos Gerais", subtitle: "Protestos de outros tipos.", registros: protestosGerais.length, icon: ProtestosGeraisIcon }, protestosGerais
120
- .sort(byDate)
121
- .map(function (protestoElement, index) { return (React.createElement(ProtestoItem, { protesto: protestoElement, key: index })); })))
122
- }
123
- ].sort(function (a, b) { return b.total - a.total; });
124
- var children = registros ? (React.createElement(ResultProtestos, null, elements.map(function (_a, i) {
125
- var element = _a.element;
126
- return (React.createElement(React.Fragment, { key: i }, element));
127
- }))) : null;
128
- return {
129
- children: children,
130
- variant: registros ? 'error' : 'default',
131
- description: (React.createElement(StatusMessage, { type: registros ? 'error' : 'default' }, registros
132
- ? registros === 1
133
- ? 'Encontrado um protesto'
134
- : "Encontrados ".concat(registros, " protestos")
135
- : 'Não ocorrência de protesto'))
136
- };
137
- } }));
93
+ }, [ctx.type, ctx.document, dataUpdated, total, setData]);
94
+ // Callback memorizado para a renderização do conteúdo em caso de sucesso
95
+ var handleSuccess = useCallback(function (data, _ctx) {
96
+ var registrosText = XPathUtils.select('string(//registros)', data);
97
+ var haveException = /Falha na integra/gi.test(XPathUtils.select('string(//raw)', data));
98
+ var registros = haveException
99
+ ? extractIntegerFromText(registrosText) + total
100
+ : extractIntegerFromText(registrosText);
101
+ var protestosDeCredito = XPathUtils.selectArray('//body//protesto', data)
102
+ .filter(function (protesto) {
103
+ return REGEX_PROTESTOS_DE_CREDITO.test(XPathUtils.select('string(./nomeCedente)', protesto));
104
+ })
105
+ .sort(byDate);
106
+ var protestosDeImposto = XPathUtils.selectArray('//body//protesto', data)
107
+ .filter(function (protesto) {
108
+ return REGEX_PROTESTOS_DE_IMPOSTO.test(XPathUtils.select('string(./nomeCedente)', protesto));
109
+ })
110
+ .sort(byDate);
111
+ var protestosGerais = XPathUtils.selectArray('//body//protesto', data)
112
+ .filter(function (protesto) {
113
+ var nomeCedente = XPathUtils.select('string(./nomeCedente)', protesto);
114
+ return (!REGEX_PROTESTOS_DE_IMPOSTO.test(nomeCedente) &&
115
+ !REGEX_PROTESTOS_DE_CREDITO.test(nomeCedente));
116
+ })
117
+ .sort(byDate);
118
+ var elements = [
119
+ {
120
+ total: protestosDeCredito.length,
121
+ element: (React.createElement(ProtestosCategory, { title: "Protestos de Cr\u00E9dito", subtitle: "Protestos de cr\u00E9dito em geral.", registros: protestosDeCredito.length, icon: ProtestosCreditoIcon }, protestosDeCredito.map(function (protesto, i) { return (React.createElement(ProtestoItem, { protesto: protesto, key: i })); })))
122
+ },
123
+ {
124
+ total: protestosDeImposto.length,
125
+ element: (React.createElement(ProtestosCategory, { title: "Protestos de Imposto", subtitle: "Protestos de impostos federais, estaduais e municipais.", registros: protestosDeImposto.length, icon: ProtestosImpostosIcon }, protestosDeImposto.map(function (protesto, i) { return (React.createElement(ProtestoItem, { protesto: protesto, key: i })); })))
126
+ },
127
+ {
128
+ total: protestosGerais.length,
129
+ element: (React.createElement(ProtestosCategory, { title: "Protestos Gerais", subtitle: "Protestos de outros tipos.", registros: protestosGerais.length, icon: ProtestosGeraisIcon }, protestosGerais.map(function (protesto, i) { return (React.createElement(ProtestoItem, { protesto: protesto, key: i })); })))
130
+ }
131
+ ].sort(function (a, b) { return b.total - a.total; });
132
+ var children = registros ? (React.createElement(ResultProtestos, null, elements.map(function (_a, i) {
133
+ var element = _a.element;
134
+ return (React.createElement(React.Fragment, { key: i }, element));
135
+ }))) : null;
136
+ var variant = registros ? 'error' : 'default';
137
+ return {
138
+ children: children,
139
+ variant: variant,
140
+ description: (React.createElement(StatusMessage, { type: registros ? 'error' : 'default' }, registros
141
+ ? registros === 1
142
+ ? 'Encontrado um protesto'
143
+ : "Encontrados ".concat(registros, " protestos")
144
+ : 'Não há ocorrência de protesto'))
145
+ };
146
+ }, [total]);
147
+ 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 }));
138
148
  };
139
- export default Protestos;
149
+ export default React.memo(Protestos);
140
150
  var templateObject_1;