@credithub/harlan-components 1.62.2 → 1.62.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.
- package/dist/components/dividasPublicas/dividasPublicas.d.ts +2 -2
- package/dist/components/dividasPublicas/dividasPublicas.js +43 -31
- package/dist/components/processos-juridicos/processosJuridicos.js +22 -25
- package/dist/components/protestos/protestos.d.ts +2 -2
- package/dist/components/protestos/protestos.js +71 -62
- package/lib/cjs/index.js +139 -119
- package/lib/esm/index.js +138 -118
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -13,7 +13,7 @@ import DividasVencidasSerasaIcon from '../../assets/icones/dividasVencidasSerasa
|
|
|
13
13
|
import { useGlobalData } from '../../contexts/globalDataContext';
|
|
14
14
|
import { formatMoney } from '../../utils/number';
|
|
15
15
|
import XPathUtils from '../../utils/xpath';
|
|
16
|
-
import React, { useContext, useEffect, useState } from 'react';
|
|
16
|
+
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
17
17
|
import { Result } from '../interface/result';
|
|
18
18
|
import StatusMessage from '../interface/statusMessage';
|
|
19
19
|
import Section from '../section';
|
|
@@ -48,39 +48,51 @@ var DividasPublicas = function () {
|
|
|
48
48
|
var ctx = useContext(Queries.Finder);
|
|
49
49
|
var setData = useGlobalData().setData;
|
|
50
50
|
var _a = useState(false), dataUpdated = _a[0], setDataUpdated = _a[1];
|
|
51
|
+
var dividas = useMemo(function () {
|
|
52
|
+
if (ctx.document) {
|
|
53
|
+
return parseDividas(ctx.document);
|
|
54
|
+
}
|
|
55
|
+
return [];
|
|
56
|
+
}, [ctx.document]);
|
|
57
|
+
var dividasPublicas = useMemo(function () {
|
|
58
|
+
if (ctx.document) {
|
|
59
|
+
return (XPathUtils.select('number(//dividas/resumo/valor_total_dividas)', ctx.document) || 0);
|
|
60
|
+
}
|
|
61
|
+
return 0;
|
|
62
|
+
}, [ctx.document]);
|
|
51
63
|
useEffect(function () {
|
|
52
|
-
if (dataUpdated || !ctx.document)
|
|
64
|
+
if (dataUpdated || !ctx.document)
|
|
53
65
|
return;
|
|
54
|
-
}
|
|
55
|
-
var dividas = parseDividas(ctx.document);
|
|
56
66
|
if (ctx.type === RequestStatus.Error || ctx.type === RequestStatus.Empty) {
|
|
57
|
-
setData(function (prevState) { return (__assign(__assign({}, prevState), { divida: {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
setData(function (prevState) { return (__assign(__assign({}, prevState), { divida: {
|
|
68
|
+
protestosDeCredito: [],
|
|
69
|
+
protestosDeImposto: [],
|
|
70
|
+
protestosGerais: [],
|
|
71
|
+
totalProtestos: 0,
|
|
72
|
+
isLoaded: true
|
|
73
|
+
} })); });
|
|
63
74
|
setDataUpdated(true);
|
|
75
|
+
return;
|
|
64
76
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
?
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
setData(function (prevState) { return (__assign(__assign({}, prevState), { divida: { dividas: dividas, isLoaded: true }, dividasPublicas: dividasPublicas })); });
|
|
78
|
+
setDataUpdated(true);
|
|
79
|
+
}, [ctx.document, ctx.type, dataUpdated, dividas, dividasPublicas, setData]);
|
|
80
|
+
var handleSuccess = useCallback(function (document, _ctx) {
|
|
81
|
+
var parsedDividas = parseDividas(document);
|
|
82
|
+
var totalOcorrencias = parsedDividas.length;
|
|
83
|
+
var children = totalOcorrencias ? (React.createElement(Result, null,
|
|
84
|
+
React.createElement(DividasPublicasList, { dividas: parsedDividas }))) : null;
|
|
85
|
+
var variant = totalOcorrencias ? 'error' : 'default';
|
|
86
|
+
return {
|
|
87
|
+
children: children,
|
|
88
|
+
variant: variant,
|
|
89
|
+
description: (React.createElement(StatusMessage, { type: totalOcorrencias ? 'error' : 'default' }, totalOcorrencias
|
|
90
|
+
? totalOcorrencias === 1
|
|
91
|
+
? 'Encontrada uma dívida pública'
|
|
92
|
+
: "".concat(totalOcorrencias, " d\u00EDvidas encontradas")
|
|
93
|
+
: 'Não há ocorrência de dívida pública'))
|
|
94
|
+
};
|
|
95
|
+
}, []);
|
|
96
|
+
return (React.createElement(Section, { ctx: ctx, title: "D\u00EDvidas P\u00FAblicas", icon: DividasVencidasSerasaIcon, subtitle: "Veja as d\u00EDvidas p\u00FAblicas com a Uni\u00E3o (ativa, FGTS e previdenci\u00E1ria).", onSuccess: handleSuccess }));
|
|
85
97
|
};
|
|
86
|
-
export default DividasPublicas;
|
|
98
|
+
export default React.memo(DividasPublicas);
|
|
@@ -20,42 +20,41 @@ 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
|
|
24
23
|
var processedRef = useRef(false);
|
|
25
24
|
var ctxHashRef = useRef('');
|
|
26
25
|
useEffect(function () {
|
|
27
26
|
var _a;
|
|
28
|
-
// Create a hash of the current context state to detect changes
|
|
29
27
|
var currentCtxHash = JSON.stringify({
|
|
30
28
|
type: ctx.type,
|
|
31
29
|
documentId: ctx.document ? true : false
|
|
32
30
|
});
|
|
33
|
-
|
|
31
|
+
var cleanup = undefined;
|
|
34
32
|
if (currentCtxHash === ctxHashRef.current && processedRef.current) {
|
|
35
|
-
return;
|
|
33
|
+
return undefined;
|
|
36
34
|
}
|
|
37
|
-
// Update our reference to the current context
|
|
38
35
|
ctxHashRef.current = currentCtxHash;
|
|
39
|
-
// Handle error or empty response
|
|
40
36
|
if ((ctx.type === RequestStatus.Error || ctx.type === RequestStatus.Empty) &&
|
|
41
37
|
!processedRef.current) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
var timer_1 = setTimeout(function () {
|
|
39
|
+
if (ctx.type === RequestStatus.Error ||
|
|
40
|
+
ctx.type === RequestStatus.Empty) {
|
|
41
|
+
setData(function (prevState) {
|
|
42
|
+
var _a;
|
|
43
|
+
if (((_a = prevState.processosJuridicosData) === null || _a === void 0 ? void 0 : _a.isLoaded) &&
|
|
44
|
+
Array.isArray(prevState.processosJuridicosData.empresa) &&
|
|
45
|
+
prevState.processosJuridicosData.empresa.length === 0) {
|
|
46
|
+
return prevState;
|
|
47
|
+
}
|
|
48
|
+
return __assign(__assign({}, prevState), { processosJuridicosData: {
|
|
49
|
+
empresa: [],
|
|
50
|
+
isLoaded: true
|
|
51
|
+
} });
|
|
52
|
+
});
|
|
53
|
+
processedRef.current = true;
|
|
49
54
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
isLoaded: true
|
|
53
|
-
} });
|
|
54
|
-
});
|
|
55
|
-
processedRef.current = true;
|
|
56
|
-
return;
|
|
55
|
+
}, 300);
|
|
56
|
+
cleanup = function () { return clearTimeout(timer_1); };
|
|
57
57
|
}
|
|
58
|
-
// Handle successful response
|
|
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)) {
|
|
@@ -78,14 +76,13 @@ var ProcessosJuridicos = function (_a) {
|
|
|
78
76
|
processedRef.current = true;
|
|
79
77
|
}
|
|
80
78
|
}
|
|
79
|
+
return cleanup;
|
|
81
80
|
}, [ctx.type, ctx.document, setData]);
|
|
82
|
-
// Reset processed state when context changes to loading
|
|
83
81
|
useEffect(function () {
|
|
84
82
|
if (ctx.type === RequestStatus.Loading) {
|
|
85
83
|
processedRef.current = false;
|
|
86
|
-
setData(function (prevState) { return (__assign(__assign({}, prevState), { processosJuridicosData: __assign(__assign({}, prevState.processosJuridicosData), { isLoaded: false }) })); });
|
|
87
84
|
}
|
|
88
|
-
}, [ctx.type
|
|
85
|
+
}, [ctx.type]);
|
|
89
86
|
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) {
|
|
90
87
|
var _a;
|
|
91
88
|
var qtyProcessos = (_a = data.empresa) === null || _a === void 0 ? void 0 : _a.length;
|
|
@@ -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;
|