@credithub/harlan-components 1.62.3 → 1.62.5

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,3 +1,3 @@
1
1
  import React from 'react';
2
- declare const DividasPublicas: React.FC;
3
- export default DividasPublicas;
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: { isLoaded: true } })); });
58
- return;
59
- }
60
- if (!dataUpdated) {
61
- var dividasPublicas_1 = XPathUtils.select('number(//dividas/resumo/valor_total_dividas)', ctx.document) || 0;
62
- setData(function (prevState) { return (__assign(__assign({}, prevState), { divida: { dividas: dividas, isLoaded: true }, dividasPublicas: dividasPublicas_1 })); });
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
- console.log(dataUpdated);
66
- if (dividas.length === 0) {
67
- setData(function (prevState) { return (__assign(__assign({}, prevState), { divida: __assign(__assign({}, (prevState.divida || {})), { isLoaded: true }) })); });
68
- }
69
- }, [ctx, dataUpdated, setData]);
70
- 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: function (document) {
71
- var dividas = parseDividas(document);
72
- var totalOcorrencias = dividas.length;
73
- var children = totalOcorrencias ? (React.createElement(Result, null,
74
- React.createElement(DividasPublicasList, { dividas: dividas }))) : null;
75
- return {
76
- children: children,
77
- variant: totalOcorrencias ? 'error' : 'default',
78
- description: (React.createElement(StatusMessage, { type: totalOcorrencias ? 'error' : 'default' }, totalOcorrencias
79
- ? totalOcorrencias === 1
80
- ? 'Encontrada uma dívida pública'
81
- : "".concat(totalOcorrencias, " d\u00EDvidas encontradas")
82
- : 'Não há ocorrência de dívida pública'))
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 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);
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- declare const _default: React.NamedExoticComponent<{
2
+ declare const ProcessosJuridicos: React.FC<{
3
3
  onClickConsultarProcessoJuridico?: (processo: string) => void;
4
4
  }>;
5
- export default _default;
5
+ export default ProcessosJuridicos;
@@ -11,34 +11,29 @@ 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, { useCallback, useContext, useEffect, useRef } from 'react';
14
+ import React, { 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';
18
18
  import ProcessosJuridicosList from './processosJuridicosList';
19
19
  var ProcessosJuridicos = function (_a) {
20
20
  var onClickConsultarProcessoJuridico = _a.onClickConsultarProcessoJuridico;
21
+ console.log('Processos Juridicos Renderizou');
21
22
  var ctx = useContext(Queries.ProcessosJuridicos);
22
23
  var setData = useGlobalData().setData;
23
- // Refs para evitar processamento desnecessário
24
24
  var processedRef = useRef(false);
25
25
  var ctxHashRef = useRef('');
26
26
  useEffect(function () {
27
- var _a;
28
- // Gera um hash para detectar mudanças relevantes no contexto
27
+ var _a, _b;
29
28
  var currentCtxHash = JSON.stringify({
30
29
  type: ctx.type,
31
- documentId: !!ctx.document
30
+ documentId: Boolean(ctx.document)
32
31
  });
33
- // Se o estado não mudou e já foi processado, sai
34
32
  if (currentCtxHash === ctxHashRef.current && processedRef.current) {
35
33
  return;
36
34
  }
37
- // Atualiza o hash atual
38
35
  ctxHashRef.current = currentCtxHash;
39
- // Caso de erro ou resposta vazia
40
- if ((ctx.type === RequestStatus.Error || ctx.type === RequestStatus.Empty) &&
41
- !processedRef.current) {
36
+ if (ctx.type === RequestStatus.Error && !processedRef.current) {
42
37
  setData(function (prevState) {
43
38
  var _a;
44
39
  if (((_a = prevState.processosJuridicosData) === null || _a === void 0 ? void 0 : _a.isLoaded) &&
@@ -54,52 +49,62 @@ var ProcessosJuridicos = function (_a) {
54
49
  processedRef.current = true;
55
50
  return;
56
51
  }
57
- // Caso de resposta bem-sucedida
58
52
  if (ctx.type === RequestStatus.Success &&
59
- !processedRef.current &&
60
- ctx.document) {
61
- var qtyProcessos_1 = (_a = ctx.document.empresa) === null || _a === void 0 ? void 0 : _a.length;
62
- if (qtyProcessos_1) {
53
+ ctx.document &&
54
+ !processedRef.current) {
55
+ var documentData_1 = ctx.document;
56
+ var qtyProcessos_1 = (_b = (_a = documentData_1.empresa) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
57
+ if (qtyProcessos_1 > 0) {
63
58
  var processosJuridicosData_1 = {
64
- empresa: ctx.document.empresa,
59
+ empresa: documentData_1.empresa,
65
60
  isLoaded: true
66
61
  };
67
62
  setData(function (prevState) {
68
63
  var _a;
69
64
  if (((_a = prevState.processosJuridicosData) === null || _a === void 0 ? void 0 : _a.isLoaded) &&
70
65
  JSON.stringify(prevState.processosJuridicosData.empresa) ===
71
- JSON.stringify(processosJuridicosData_1.empresa)) {
66
+ JSON.stringify(documentData_1.empresa)) {
67
+ return prevState;
68
+ }
69
+ return __assign(__assign({}, prevState), { processosJuridicos: qtyProcessos_1, processosJuridicosData: processosJuridicosData_1 });
70
+ });
71
+ }
72
+ else {
73
+ setData(function (prevState) {
74
+ var _a;
75
+ if (((_a = prevState.processosJuridicosData) === null || _a === void 0 ? void 0 : _a.isLoaded) &&
76
+ Array.isArray(prevState.processosJuridicosData.empresa) &&
77
+ prevState.processosJuridicosData.empresa.length === 0) {
72
78
  return prevState;
73
79
  }
74
- return __assign(__assign({}, prevState), { processosJuridicos: qtyProcessos_1 || 0, processosJuridicosData: processosJuridicosData_1 });
80
+ return __assign(__assign({}, prevState), { processosJuridicosData: {
81
+ empresa: [],
82
+ isLoaded: true
83
+ } });
75
84
  });
76
- processedRef.current = true;
77
85
  }
86
+ processedRef.current = true;
78
87
  }
79
88
  }, [ctx.type, ctx.document, setData]);
80
- // Reseta o estado processado ao iniciar novo carregamento
81
89
  useEffect(function () {
82
90
  if (ctx.type === RequestStatus.Loading) {
83
91
  processedRef.current = false;
84
- setData(function (prevState) { return (__assign(__assign({}, prevState), { processosJuridicosData: __assign(__assign({}, prevState.processosJuridicosData), { isLoaded: false }) })); });
85
92
  }
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 }));
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
+ } }));
104
109
  };
105
- export default React.memo(ProcessosJuridicos);
110
+ export default ProcessosJuridicos;