@credithub/harlan-components 1.60.4 → 1.61.0

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.
@@ -12,7 +12,7 @@ var __assign = (this && this.__assign) || function () {
12
12
  import ChequesSemFundoIcon from '../../assets/icones/chequesSemFundo';
13
13
  import { useGlobalData } from '../../contexts/globalDataContext';
14
14
  import XPathUtils from '../../utils/xpath';
15
- import React, { useCallback, useContext, useState, useEffect, useMemo } from 'react';
15
+ import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
16
16
  import { Result } from '../interface/result';
17
17
  import StatusMessage from '../interface/statusMessage';
18
18
  import Section from '../section';
@@ -49,11 +49,16 @@ var CCF = function () {
49
49
  }
50
50
  var data = ctx.document;
51
51
  var _a = processData(data), ccfData = _a.ccfData, totalOcorrencias = _a.totalOcorrencias, ultimoRegistro = _a.ultimoRegistro;
52
+ if (totalOcorrencias === 0) {
53
+ var ccfState_1 = { ccfData: ccfData, isLoaded: true };
54
+ setData(function (prevState) { return (__assign(__assign({}, prevState), { ccfData: ccfState_1 })); });
55
+ setDataUpdated(true);
56
+ }
52
57
  if (totalOcorrencias !== 0 ||
53
58
  ultimoRegistro.length > 0 ||
54
59
  ccfData.length > 0) {
55
- var ccfState_1 = { ccfData: ccfData };
56
- setData(function (prevState) { return (__assign(__assign({}, prevState), { ccfData: ccfState_1, ccf: totalOcorrencias, ultimoRegistroCCF: ultimoRegistro })); });
60
+ var ccfState_2 = { ccfData: ccfData, isLoaded: true };
61
+ setData(function (prevState) { return (__assign(__assign({}, prevState), { ccfData: ccfState_2, ccf: totalOcorrencias, ultimoRegistroCCF: ultimoRegistro })); });
57
62
  setDataUpdated(true);
58
63
  }
59
64
  }, [ctx, dataUpdated, processData, setData]);
@@ -1,3 +1,7 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
1
5
  var __assign = (this && this.__assign) || function () {
2
6
  __assign = Object.assign || function(t) {
3
7
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -26,67 +30,104 @@ import { formatMoney } from '../../utils/number';
26
30
  import { formatDocument } from '../../utils/string';
27
31
  import { format } from 'date-fns';
28
32
  import React, { useContext } from 'react';
33
+ import styled, { keyframes } from 'styled-components';
29
34
  import Section from '../interface/section';
30
35
  import StatusMessage from '../interface/statusMessage';
31
36
  import { Queries, RequestStatus } from '../webservice';
32
- var getPossuiPendenciaText = function (_a) {
33
- var ccf = _a.ccf, ultimoRegistroCCF = _a.ultimoRegistroCCF, dividasPublicas = _a.dividasPublicas, protestos = _a.protestos, processosJuridicos = _a.processosJuridicos, receitaStatus = _a.receitaStatus, liminar = _a.liminar;
34
- return [
35
- receitaStatus ? "".concat(receitaStatus) : '',
36
- dividasPublicas
37
- ? "".concat(formatMoney(dividasPublicas), " em D\u00EDvidas P\u00FAblicas")
38
- : '',
39
- ccf
40
- ? "".concat(ccf === 1 ? 'Cheque sem Fundo' : "".concat(ccf, " Cheques sem Fundo"), " com \u00DAltima Ocorr\u00EAncia em ").concat(ultimoRegistroCCF)
41
- : '',
42
- protestos
43
- ? protestos === 1
44
- ? 'Protesto Encontrado'
45
- : "".concat(protestos, " Protestos")
46
- : '',
47
- processosJuridicos
48
- ? processosJuridicos === 1
49
- ? 'Processo Jurídico'
50
- : "".concat(processosJuridicos, " Processos Jur\u00EDdicos")
51
- : '',
52
- (liminar === null || liminar === void 0 ? void 0 : liminar.totalProtestos) === 'NADA CONSTA' ||
53
- (liminar === null || liminar === void 0 ? void 0 : liminar.message) === 'Encontrado'
54
- ? 'Indício de Liminar'
55
- : ''
56
- ].filter(function (x) { return !!x; });
57
- };
37
+ // Animação do spinner
38
+ var spin = keyframes(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n"], ["\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n"])));
39
+ // Componente Spinner sutil
40
+ var Spinner = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n border: 2px solid rgba(0, 0, 0, 0.1);\n border-left-color: #222;\n border-radius: 50%;\n width: 16px;\n height: 16px;\n animation: ", " 1s linear infinite;\n margin-right: 8px;\n display: inline-block;\n vertical-align: middle;\n"], ["\n border: 2px solid rgba(0, 0, 0, 0.1);\n border-left-color: #222;\n border-radius: 50%;\n width: 16px;\n height: 16px;\n animation: ", " 1s linear infinite;\n margin-right: 8px;\n display: inline-block;\n vertical-align: middle;\n"])), spin);
58
41
  var ConsultaSimplesSection = function (_a) {
59
- var _b, _c, _d;
42
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
60
43
  var documento = _a.documento, children = _a.children, onClose = _a.onClose, rest = __rest(_a, ["documento", "children", "onClose"]);
61
44
  var ctx = useContext(Queries.Finder);
62
45
  var data = useGlobalData().data;
46
+ // Extraindo valores do globalData
63
47
  var receitaStatus = ((_c = (_b = data.dossie) === null || _b === void 0 ? void 0 : _b.summary) === null || _c === void 0 ? void 0 : _c.receitaStatus) &&
64
48
  ['ATIVA', 'REGULAR'].indexOf(data.dossie.summary.receitaStatus) === -1
65
49
  ? data.dossie.summary.receitaStatus
66
50
  : null;
67
- var possuiPendencias = data.ccf ||
68
- data.protestos ||
69
- data.dividasPublicas ||
70
- data.processosJuridicos ||
71
- receitaStatus ||
72
- ((_d = data.liminar) === null || _d === void 0 ? void 0 : _d.message) === 'Encontrado';
73
- var possuiPendenciaText = getPossuiPendenciaText(__assign(__assign({}, data), { receitaStatus: receitaStatus, liminar: data.liminar }));
51
+ // Cria um array com cada tag de pendência, seu texto e sua flag de carregamento
52
+ var pendencias = [
53
+ {
54
+ label: 'Situação Receita',
55
+ text: receitaStatus ? "".concat(receitaStatus) : '',
56
+ loaded: true // assume que essa informação está disponível
57
+ },
58
+ {
59
+ label: 'Dívidas Públicas',
60
+ text: data.dividasPublicas
61
+ ? "".concat(formatMoney(data.dividasPublicas), " em D\u00EDvidas P\u00FAblicas")
62
+ : '',
63
+ loaded: (_e = (_d = data.divida) === null || _d === void 0 ? void 0 : _d.isLoaded) !== null && _e !== void 0 ? _e : false
64
+ },
65
+ {
66
+ label: 'Cheques sem Fundo',
67
+ text: data.ccf
68
+ ? "".concat(data.ccf === 1 ? 'Cheque sem Fundo' : "".concat(data.ccf, " Cheques sem Fundo"), " com \u00DAltima Ocorr\u00EAncia em ").concat(data.ultimoRegistroCCF)
69
+ : '',
70
+ loaded: (_g = (_f = data.ccfData) === null || _f === void 0 ? void 0 : _f.isLoaded) !== null && _g !== void 0 ? _g : false
71
+ },
72
+ {
73
+ label: 'Protestos',
74
+ text: data.protestos
75
+ ? data.protestos === 1
76
+ ? 'Protesto Encontrado'
77
+ : "".concat(data.protestos, " Protestos")
78
+ : '',
79
+ loaded: (_j = (_h = data.protestosData) === null || _h === void 0 ? void 0 : _h.isLoaded) !== null && _j !== void 0 ? _j : false
80
+ },
81
+ {
82
+ label: 'Processos Jurídicos',
83
+ text: data.processosJuridicos
84
+ ? data.processosJuridicos === 1
85
+ ? 'Processo Jurídico'
86
+ : "".concat(data.processosJuridicos, " Processos Jur\u00EDdicos")
87
+ : '',
88
+ loaded: (_l = (_k = data.processosJuridicosData) === null || _k === void 0 ? void 0 : _k.isLoaded) !== null && _l !== void 0 ? _l : false
89
+ },
90
+ {
91
+ label: 'Liminar',
92
+ text: data.liminar &&
93
+ (data.liminar.totalProtestos === 'NADA CONSTA' ||
94
+ data.liminar.message === 'Encontrado')
95
+ ? 'Indício de Liminar'
96
+ : '',
97
+ loaded: (_o = (_m = data.liminar) === null || _m === void 0 ? void 0 : _m.isLoaded) !== null && _o !== void 0 ? _o : false
98
+ }
99
+ ];
74
100
  var isError = (ctx === null || ctx === void 0 ? void 0 : ctx.type) === RequestStatus.Error;
75
101
  var isLoading = (ctx === null || ctx === void 0 ? void 0 : ctx.type) === RequestStatus.Loading;
76
- var isDataReady = !isLoading &&
77
- (possuiPendenciaText.length > 0 || possuiPendencias || isError);
78
102
  var statusType = isError
79
103
  ? 'warning'
80
- : possuiPendencias
104
+ : data.ccf ||
105
+ data.protestos ||
106
+ data.dividasPublicas ||
107
+ data.processosJuridicos ||
108
+ receitaStatus ||
109
+ ((_p = data.liminar) === null || _p === void 0 ? void 0 : _p.message) === 'Encontrado'
81
110
  ? 'error'
82
111
  : 'success';
83
112
  return (React.createElement(Section, __assign({ title: "Consulta Simples", subtitle: "Consulta de informa\u00E7\u00F5es do documento.", description: React.createElement(React.Fragment, null,
84
113
  React.createElement(StatusMessage, null, format(new Date(), "dd/MM/yyyy 'às' HH:mm")),
85
114
  React.createElement(StatusMessage, { type: "found" }, formatDocument(documento)),
86
115
  isError && (ctx === null || ctx === void 0 ? void 0 : ctx.error) && (React.createElement(StatusMessage, { type: statusType }, ctx.error.message)),
87
- isDataReady ? (possuiPendenciaText.length === 0 && !possuiPendencias ? (React.createElement(StatusMessage, { type: statusType }, "Nenhum registro encontrado")) : (possuiPendenciaText.map(function (text) { return (React.createElement(StatusMessage, { key: text, type: "error" }, text)); }))) : null), onClose: onClose, icon: ConsultaSimplesIcon, variant: isLoading ? 'loading' : 'default', ctx: ctx, loadingProps: {
116
+ pendencias.map(function (item) {
117
+ // Se a tag não está carregada, mostra o spinner com a mensagem de carregamento
118
+ if (!item.loaded) {
119
+ return (React.createElement(StatusMessage, { key: item.label, type: "loading" },
120
+ React.createElement(Spinner, null),
121
+ " ",
122
+ item.label,
123
+ "..."));
124
+ }
125
+ // Se carregado e houver texto, exibe-o; caso contrário, não renderiza nada
126
+ return item.text ? (React.createElement(StatusMessage, { key: item.label, type: "error" }, item.text)) : null;
127
+ })), onClose: onClose, icon: ConsultaSimplesIcon, variant: isLoading ? 'loading' : 'default', ctx: ctx, loadingProps: {
88
128
  percentage: (ctx === null || ctx === void 0 ? void 0 : ctx.progress) || 0,
89
129
  hidden: !isLoading
90
130
  } }, rest), children));
91
131
  };
92
132
  export default ConsultaSimplesSection;
133
+ var templateObject_1, templateObject_2;
@@ -55,9 +55,12 @@ var DividasPublicas = function () {
55
55
  var dividas = parseDividas(ctx.document);
56
56
  if (!dataUpdated) {
57
57
  var dividasPublicas_1 = XPathUtils.select('number(//dividas/resumo/valor_total_dividas)', ctx.document) || 0;
58
- setData(function (prevState) { return (__assign(__assign({}, prevState), { dividas: dividas, dividasPublicas: dividasPublicas_1 })); });
58
+ setData(function (prevState) { return (__assign(__assign({}, prevState), { dividas: dividas, dividasPublicas: dividasPublicas_1, isLoaded: true })); });
59
59
  setDataUpdated(true);
60
60
  }
61
+ if (dividas.length === 0) {
62
+ setData(function (prevState) { return (__assign(__assign({}, prevState), { divida: __assign(__assign({}, (prevState.divida || {})), { isLoaded: true }) })); });
63
+ }
61
64
  }, [ctx, dataUpdated, setData]);
62
65
  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) {
63
66
  var dividas = parseDividas(document);
@@ -1,4 +1,4 @@
1
- type StatusColorTypes = 'default' | 'error' | 'success' | 'found' | 'warning';
1
+ type StatusColorTypes = 'default' | 'error' | 'success' | 'found' | 'warning' | 'loading';
2
2
  export type StatusProps = {
3
3
  type?: StatusColorTypes;
4
4
  capitalize?: boolean;
@@ -10,7 +10,8 @@ var StatusMessage = styled.span(templateObject_1 || (templateObject_1 = __makeTe
10
10
  error: theme.colors.erro,
11
11
  success: theme.colors.positivoClaro,
12
12
  found: theme.colors.azulClaro,
13
- warning: theme.colors.alerta
13
+ warning: theme.colors.alerta,
14
+ loading: theme.colors.cinzaClaro // Você pode ajustar essa cor conforme necessário
14
15
  };
15
16
  return statusColors[type];
16
17
  }, function (_a) {
@@ -120,7 +120,7 @@ var Liminar = function () {
120
120
  ((_b = prev.liminar) === null || _b === void 0 ? void 0 : _b.indiciosDeLiminar) === indiciosDeLiminar) {
121
121
  return prev;
122
122
  }
123
- return __assign(__assign({}, prev), { liminar: { indiciosDeLiminar: indiciosDeLiminar, message: finalStatus } });
123
+ return __assign(__assign({}, prev), { liminar: { indiciosDeLiminar: indiciosDeLiminar, message: finalStatus, isLoaded: true } });
124
124
  });
125
125
  // Store the result in our ref
126
126
  resultRef.current = finalStatus;
@@ -37,7 +37,8 @@ var ProcessosJuridicos = function (_a) {
37
37
  // Update our reference to the current context
38
38
  ctxHashRef.current = currentCtxHash;
39
39
  // Handle error or empty response
40
- if ((ctx.type === RequestStatus.Error || ctx.type === RequestStatus.Empty) && !processedRef.current) {
40
+ if ((ctx.type === RequestStatus.Error || ctx.type === RequestStatus.Empty) &&
41
+ !processedRef.current) {
41
42
  setData(function (prevState) {
42
43
  var _a;
43
44
  // Avoid unnecessary state updates if data hasn't changed
@@ -55,7 +56,9 @@ var ProcessosJuridicos = function (_a) {
55
56
  return;
56
57
  }
57
58
  // Handle successful response
58
- if (ctx.type === RequestStatus.Success && !processedRef.current && ctx.document) {
59
+ if (ctx.type === RequestStatus.Success &&
60
+ !processedRef.current &&
61
+ ctx.document) {
59
62
  var qtyProcessos_1 = (_a = ctx.document.empresa) === null || _a === void 0 ? void 0 : _a.length;
60
63
  if (qtyProcessos_1) {
61
64
  var processosJuridicosData_1 = {
@@ -85,7 +88,7 @@ var ProcessosJuridicos = function (_a) {
85
88
  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) {
86
89
  var _a;
87
90
  var qtyProcessos = (_a = data.empresa) === null || _a === void 0 ? void 0 : _a.length;
88
- var children = qtyProcessos ? (React.createElement(ProcessosJuridicosList, { processos: data.empresa, onClickConsultarProcessoJuridico: onClickConsultarProcessoJuridico })) : null;
91
+ var children = qtyProcessos ? (React.createElement(ProcessosJuridicosList, { processos: data.empresa || [], onClickConsultarProcessoJuridico: onClickConsultarProcessoJuridico })) : null;
89
92
  return {
90
93
  children: children,
91
94
  description: (React.createElement(StatusMessage, { type: qtyProcessos ? 'error' : 'default' }, qtyProcessos
@@ -75,7 +75,8 @@ var Protestos = function () {
75
75
  protestosDeCredito: protestosDeCredito,
76
76
  protestosDeImposto: protestosDeImposto,
77
77
  protestosGerais: protestosGerais,
78
- totalProtestos: registros
78
+ totalProtestos: registros,
79
+ isLoaded: true
79
80
  };
80
81
  setData(function (prevState) { return (__assign(__assign({}, prevState), { protestos: registros, protestosData: protestosState })); });
81
82
  setDataUpdated(true);
@@ -119,7 +120,7 @@ var Protestos = function () {
119
120
  ].sort(function (a, b) { return b.total - a.total; });
120
121
  var children = registros ? (React.createElement(ResultProtestos, null, elements.map(function (_a, i) {
121
122
  var element = _a.element;
122
- return React.createElement(React.Fragment, { key: i }, element);
123
+ return (React.createElement(React.Fragment, { key: i }, element));
123
124
  }))) : null;
124
125
  return {
125
126
  children: children,
@@ -1,3 +1,10 @@
1
1
  import createDataContext from './createDataContext';
2
- var _a = createDataContext({}), GlobalDataProvider = _a.DataProvider, useGlobalData = _a.useData;
2
+ var defaultGlobalState = {
3
+ ccfData: { isLoaded: false },
4
+ divida: { isLoaded: false },
5
+ liminar: { isLoaded: false },
6
+ protestosData: { isLoaded: false },
7
+ processosJuridicosData: { isLoaded: false }
8
+ };
9
+ var _a = createDataContext(defaultGlobalState), GlobalDataProvider = _a.DataProvider, useGlobalData = _a.useData;
3
10
  export { GlobalDataProvider, useGlobalData };