@credithub/harlan-components 1.62.2 → 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.
- package/dist/components/processos-juridicos/processosJuridicos.d.ts +2 -2
- package/dist/components/processos-juridicos/processosJuridicos.js +27 -27
- package/dist/components/protestos/protestos.d.ts +2 -2
- package/dist/components/protestos/protestos.js +71 -62
- package/lib/cjs/index.js +101 -90
- package/lib/esm/index.js +100 -89
- package/package.json +1 -1
|
@@ -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,28 +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
|
-
//
|
|
23
|
+
// Refs para evitar processamento desnecessário
|
|
24
24
|
var processedRef = useRef(false);
|
|
25
25
|
var ctxHashRef = useRef('');
|
|
26
26
|
useEffect(function () {
|
|
27
27
|
var _a;
|
|
28
|
-
//
|
|
28
|
+
// Gera um hash para detectar mudanças relevantes no contexto
|
|
29
29
|
var currentCtxHash = JSON.stringify({
|
|
30
30
|
type: ctx.type,
|
|
31
|
-
documentId: ctx.document
|
|
31
|
+
documentId: !!ctx.document
|
|
32
32
|
});
|
|
33
|
-
//
|
|
33
|
+
// Se o estado não mudou e já foi processado, sai
|
|
34
34
|
if (currentCtxHash === ctxHashRef.current && processedRef.current) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
//
|
|
37
|
+
// Atualiza o hash atual
|
|
38
38
|
ctxHashRef.current = currentCtxHash;
|
|
39
|
-
//
|
|
39
|
+
// Caso de erro ou resposta vazia
|
|
40
40
|
if ((ctx.type === RequestStatus.Error || ctx.type === RequestStatus.Empty) &&
|
|
41
41
|
!processedRef.current) {
|
|
42
42
|
setData(function (prevState) {
|
|
43
43
|
var _a;
|
|
44
|
-
// Avoid unnecessary state updates if data hasn't changed
|
|
45
44
|
if (((_a = prevState.processosJuridicosData) === null || _a === void 0 ? void 0 : _a.isLoaded) &&
|
|
46
45
|
Array.isArray(prevState.processosJuridicosData.empresa) &&
|
|
47
46
|
prevState.processosJuridicosData.empresa.length === 0) {
|
|
@@ -55,7 +54,7 @@ var ProcessosJuridicos = function (_a) {
|
|
|
55
54
|
processedRef.current = true;
|
|
56
55
|
return;
|
|
57
56
|
}
|
|
58
|
-
//
|
|
57
|
+
// Caso de resposta bem-sucedida
|
|
59
58
|
if (ctx.type === RequestStatus.Success &&
|
|
60
59
|
!processedRef.current &&
|
|
61
60
|
ctx.document) {
|
|
@@ -67,7 +66,6 @@ var ProcessosJuridicos = function (_a) {
|
|
|
67
66
|
};
|
|
68
67
|
setData(function (prevState) {
|
|
69
68
|
var _a;
|
|
70
|
-
// Avoid unnecessary state updates
|
|
71
69
|
if (((_a = prevState.processosJuridicosData) === null || _a === void 0 ? void 0 : _a.isLoaded) &&
|
|
72
70
|
JSON.stringify(prevState.processosJuridicosData.empresa) ===
|
|
73
71
|
JSON.stringify(processosJuridicosData_1.empresa)) {
|
|
@@ -79,27 +77,29 @@ var ProcessosJuridicos = function (_a) {
|
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
79
|
}, [ctx.type, ctx.document, setData]);
|
|
82
|
-
//
|
|
80
|
+
// Reseta o estado processado ao iniciar novo carregamento
|
|
83
81
|
useEffect(function () {
|
|
84
82
|
if (ctx.type === RequestStatus.Loading) {
|
|
85
83
|
processedRef.current = false;
|
|
86
84
|
setData(function (prevState) { return (__assign(__assign({}, prevState), { processosJuridicosData: __assign(__assign({}, prevState.processosJuridicosData), { isLoaded: false }) })); });
|
|
87
85
|
}
|
|
88
86
|
}, [ctx.type, setData]);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
: '
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
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 }));
|
|
104
104
|
};
|
|
105
|
-
export default ProcessosJuridicos;
|
|
105
|
+
export default React.memo(ProcessosJuridicos);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
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,26 +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
|
|
46
|
-
if ((ctxLiminar === null || ctxLiminar === void 0 ? void 0 : ctxLiminar.type) === RequestStatus.Success
|
|
47
|
-
|
|
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 || ctx.type === RequestStatus.Empty) {
|
|
55
|
-
setData(function (prevState) { return (__assign(__assign({}, prevState), { protestosData: { isLoaded: true } })); });
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
59
|
var data = ctx.document;
|
|
59
60
|
var registrosText = XPathUtils.select('string(//registros)', data);
|
|
60
61
|
var haveException = /Falha na integra/gi.test(XPathUtils.select('string(//raw)', data));
|
|
61
62
|
var registros = haveException
|
|
62
63
|
? extractIntegerFromText(registrosText) + total
|
|
63
64
|
: extractIntegerFromText(registrosText);
|
|
65
|
+
if (haveException) {
|
|
66
|
+
setData(function (prevState) { return (__assign(__assign({}, prevState), { protestosData: { isLoaded: true } })); });
|
|
67
|
+
setDataUpdated(true);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
64
70
|
var filterProtestos = function (regex, data) {
|
|
65
71
|
return XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
|
|
66
72
|
return regex.test(XPathUtils.select('string(./nomeCedente)', protesto));
|
|
@@ -84,58 +90,61 @@ var Protestos = function () {
|
|
|
84
90
|
};
|
|
85
91
|
setData(function (prevState) { return (__assign(__assign({}, prevState), { protestos: registros, protestosData: protestosState })); });
|
|
86
92
|
setDataUpdated(true);
|
|
87
|
-
}, [ctx,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}))
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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 }));
|
|
139
148
|
};
|
|
140
|
-
export default Protestos;
|
|
149
|
+
export default React.memo(Protestos);
|
|
141
150
|
var templateObject_1;
|