@credithub/harlan-components 1.55.3 → 1.57.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,76 +12,77 @@ var __assign = (this && this.__assign) || function () {
12
12
  import ProtestosIcon from '../../assets/icones/protestos';
13
13
  import { useGlobalData } from '../../contexts/globalDataContext';
14
14
  import { normalizeName, similarNames } from '../../utils/similarNames';
15
- import React, { useContext, useEffect, useMemo, useState } from 'react';
15
+ import React, { useContext, useEffect, useMemo, useState, useRef } from 'react';
16
16
  import StatusMessage from '../interface/statusMessage';
17
17
  import Section from '../section';
18
18
  import { Queries, RequestStatus } from '../webservice';
19
19
  var Liminar = function () {
20
- var _a;
20
+ var _a, _b, _c;
21
21
  var ctx = useContext(Queries.LiminarCenprot);
22
- var _b = useGlobalData(), globalData = _b.data, setData = _b.setData;
23
- var _c = useState(false), checkCompleted = _c[0], setCheckCompleted = _c[1];
22
+ var _d = useGlobalData(), globalData = _d.data, setData = _d.setData;
23
+ var _e = useState(undefined), liminarResult = _e[0], setLiminarResult = _e[1];
24
+ var didRunRef = useRef(false);
25
+ var carousel = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel;
26
+ var isPJDataLoaded = (_b = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _b === void 0 ? void 0 : _b.isLoaded;
27
+ var empresas = (_c = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _c === void 0 ? void 0 : _c.empresa;
24
28
  useEffect(function () {
25
- var _a, _b, _c, _d, _e;
26
- if (checkCompleted)
29
+ var _a;
30
+ if (didRunRef.current)
27
31
  return;
28
- var processosJuridicosData = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) !== null && _a !== void 0 ? _a : {
29
- isLoaded: true,
30
- empresa: []
31
- };
32
- if (((_b = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _b === void 0 ? void 0 : _b.carousel) && (processosJuridicosData === null || processosJuridicosData === void 0 ? void 0 : processosJuridicosData.isLoaded)) {
33
- var empresaNome = globalData.dossie.carousel.name || '';
34
- var empresaNomeNormalizado_1 = normalizeName(empresaNome);
35
- var validAssuntos_1 = [
36
- 'protesto indevido de títulos',
37
- 'inclusão indevida em cadastro de inadimplentes',
38
- 'liminar',
39
- 'sustação de Protesto',
40
- 'inexequibilidade do titulo / inexigibilidade da obrigação',
41
- 'Adimplemento e Extinção',
42
- 'Inexequibilidade do Título / Inexequibilidade da Obrigação | Tutela de Urgência | Protesto Indevido de Título'
43
- ].map(normalizeName);
44
- var processosAtivo = (_d = (_c = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _c === void 0 ? void 0 : _c.empresa) === null || _d === void 0 ? void 0 : _d.filter(function (processo) {
45
- var _a;
46
- var hasAtivoEnvolvido = (_a = processo.envolvidos_ultima_movimentacao) === null || _a === void 0 ? void 0 : _a.some(function (envolvido) {
47
- var nomeEnvolvidoNormalizado = normalizeName(envolvido.nome_sem_filtro);
48
- return (envolvido.envolvido_tipo === 'Ativo' &&
49
- similarNames(nomeEnvolvidoNormalizado, empresaNomeNormalizado_1));
50
- });
51
- var assuntos = Array.isArray(processo.assuntos)
52
- ? processo.assuntos
53
- : [processo.assuntos];
54
- var hasValidAssunto = assuntos.some(function (assunto) {
55
- var assuntoNormalizado = normalizeName(assunto);
56
- return validAssuntos_1.some(function (valid) {
57
- return similarNames(assuntoNormalizado, valid);
58
- });
32
+ if (!carousel || !isPJDataLoaded)
33
+ return;
34
+ var empresaNome = carousel.name || '';
35
+ var empresaNomeNormalizado = normalizeName(empresaNome);
36
+ var validAssuntos = [
37
+ 'protesto indevido de títulos',
38
+ 'inclusão indevida em cadastro de inadimplentes',
39
+ 'liminar',
40
+ 'sustação de Protesto',
41
+ 'inexequibilidade do titulo / inexequibilidade da obrigação',
42
+ 'Adimplemento e Extinção',
43
+ 'Inexequibilidade do Título / Inexequibilidade da Obrigação | Tutela de Urgência | Protesto Indevido de Título'
44
+ ].map(normalizeName);
45
+ var processosAtivo = empresas === null || empresas === void 0 ? void 0 : empresas.filter(function (processo) {
46
+ var _a;
47
+ var hasAtivoEnvolvido = (_a = processo.envolvidos_ultima_movimentacao) === null || _a === void 0 ? void 0 : _a.some(function (envolvido) {
48
+ var nomeEnvolvidoNormalizado = normalizeName(envolvido.nome_sem_filtro);
49
+ return (envolvido.envolvido_tipo === 'Ativo' &&
50
+ similarNames(nomeEnvolvidoNormalizado, empresaNomeNormalizado));
51
+ });
52
+ var assuntos = Array.isArray(processo.assuntos)
53
+ ? processo.assuntos
54
+ : [processo.assuntos];
55
+ var hasValidAssunto = assuntos.some(function (assunto) {
56
+ var assuntoNormalizado = normalizeName(assunto);
57
+ return validAssuntos.some(function (valid) {
58
+ return similarNames(assuntoNormalizado, valid);
59
59
  });
60
- return hasAtivoEnvolvido && hasValidAssunto;
61
60
  });
62
- var indiciosDeLiminar_1 = false;
63
- if (ctx.type === RequestStatus.Error) {
64
- console.error('Erro na requisição de liminares:', ctx.error || 'Erro desconhecido');
65
- }
66
- else if (ctx.type === RequestStatus.Success) {
67
- indiciosDeLiminar_1 = ((_e = ctx.document) === null || _e === void 0 ? void 0 : _e.indiciosDeLiminar) === true;
68
- }
69
- var finalStatus_1 = indiciosDeLiminar_1 || (processosAtivo && processosAtivo.length > 0)
70
- ? 'Encontrado'
71
- : 'Não encontrado';
72
- setData(function (prev) { return (__assign(__assign({}, prev), { liminar: { indiciosDeLiminar: indiciosDeLiminar_1, message: finalStatus_1 } })); });
73
- setCheckCompleted(true);
61
+ return hasAtivoEnvolvido && hasValidAssunto;
62
+ });
63
+ var indiciosDeLiminar = false;
64
+ if (ctx.type === RequestStatus.Error) {
65
+ console.error('Erro na requisição de liminares:', ctx.error || 'Erro desconhecido');
66
+ }
67
+ else if (ctx.type === RequestStatus.Success) {
68
+ indiciosDeLiminar = ((_a = ctx.document) === null || _a === void 0 ? void 0 : _a.indiciosDeLiminar) === true;
74
69
  }
75
- }, [checkCompleted, globalData, ctx, setData]);
70
+ var finalStatus = indiciosDeLiminar || (processosAtivo && processosAtivo.length > 0)
71
+ ? 'Encontrado'
72
+ : 'Não encontrado';
73
+ setData(function (prev) { return (__assign(__assign({}, prev), { liminar: { indiciosDeLiminar: indiciosDeLiminar, message: finalStatus } })); });
74
+ setLiminarResult(finalStatus);
75
+ didRunRef.current = true;
76
+ }, [carousel, isPJDataLoaded, empresas, ctx.type, setData]);
76
77
  var derivedCtx = useMemo(function () {
77
- if (!checkCompleted) {
78
+ if (liminarResult === undefined) {
78
79
  return __assign(__assign({}, ctx), { type: RequestStatus.Loading });
79
80
  }
80
81
  return __assign(__assign({}, ctx), { type: ctx.type === RequestStatus.Error ? RequestStatus.Success : ctx.type, document: ctx.type === RequestStatus.Error
81
82
  ? { indiciosDeLiminar: false }
82
83
  : ctx.document });
83
- }, [checkCompleted, ctx]);
84
- if (checkCompleted && ((_a = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _a === void 0 ? void 0 : _a.message) === 'Não encontrado') {
84
+ }, [liminarResult, ctx]);
85
+ if (liminarResult === 'Não encontrado') {
85
86
  return null;
86
87
  }
87
88
  return (React.createElement(Section, { title: "Liminares para Remo\u00E7\u00E3o de Protesto", subtitle: "Ind\u00EDcios de liminares para oculta\u00E7\u00E3o de registros.", icon: ProtestosIcon, ctx: derivedCtx, onSuccess: function (doc) {
@@ -37,14 +37,60 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  import { formatMoney } from '../../utils/number';
38
38
  import { formatDocument } from '../../utils/string';
39
39
  import XPathUtils from '../../utils/xpath';
40
- import React, { memo, useContext } from 'react';
40
+ import React, { memo, useContext, useState, useEffect } from 'react';
41
41
  import AddItemField from '../common/addItem';
42
42
  import Button from '../common/button';
43
43
  import { ResultContent } from '../interface/result';
44
44
  import { WebService } from '../webservice';
45
45
  import { openFormThenRedirect } from '../../utils/protestosp';
46
+ // Throttling mechanism for API requests
47
+ var activeRequests = 0;
48
+ var MAX_CONCURRENT_REQUESTS = 2;
49
+ var requestQueue = [];
50
+ var processQueue = function () {
51
+ if (requestQueue.length === 0 || activeRequests >= MAX_CONCURRENT_REQUESTS)
52
+ return;
53
+ // Process next request in queue
54
+ var nextRequest = requestQueue.shift();
55
+ if (nextRequest) {
56
+ activeRequests++;
57
+ nextRequest();
58
+ }
59
+ };
60
+ // Elegant three-dot loader component
61
+ var ThreeDotsLoader = function () {
62
+ // CSS for the loader container
63
+ var loaderStyle = {
64
+ display: 'inline-flex',
65
+ alignItems: 'center',
66
+ marginLeft: '5px',
67
+ height: '10px',
68
+ };
69
+ // CSS for each dot
70
+ var dotStyle = function (delay) { return ({
71
+ width: '4px',
72
+ height: '4px',
73
+ margin: '0 2px',
74
+ borderRadius: '50%',
75
+ background: '#aaa',
76
+ opacity: 0.7,
77
+ animation: 'blink 1.4s infinite',
78
+ animationDelay: "".concat(delay, "s"),
79
+ }); };
80
+ // CSS animation keyframes defined as a style block
81
+ var keyframes = "\n @keyframes blink {\n 0% { opacity: 0.2; }\n 20% { opacity: 0.8; }\n 100% { opacity: 0.2; }\n }\n ";
82
+ return (React.createElement("span", { style: loaderStyle },
83
+ React.createElement("style", null, keyframes),
84
+ React.createElement("span", { style: dotStyle(0) }),
85
+ React.createElement("span", { style: dotStyle(0.2) }),
86
+ React.createElement("span", { style: dotStyle(0.4) })));
87
+ };
46
88
  export var ProtestoItem = memo(function (_a) {
47
89
  var protesto = _a.protesto;
90
+ var client = useContext(WebService);
91
+ var _b = useState(null), quemApresentou = _b[0], setQuemApresentou = _b[1];
92
+ var _c = useState(false), loading = _c[0], setLoading = _c[1];
93
+ var _d = useState(false), queued = _d[0], setQueued = _d[1];
48
94
  var getField = function (path, formatter) {
49
95
  var value = XPathUtils.select("string(".concat(path, ")"), protesto);
50
96
  return formatter ? formatter(value) : value;
@@ -52,8 +98,92 @@ export var ProtestoItem = memo(function (_a) {
52
98
  var formatBooleanField = function (value) {
53
99
  return value === 'true' ? 'Sim' : 'Não';
54
100
  };
101
+ // Function to fetch Quem Apresentou data
102
+ var fetchQuemApresentou = function (nm_chave) { return __awaiter(void 0, void 0, void 0, function () {
103
+ var response, error_1;
104
+ return __generator(this, function (_a) {
105
+ switch (_a.label) {
106
+ case 0:
107
+ if (!nm_chave)
108
+ return [2 /*return*/];
109
+ setLoading(true);
110
+ _a.label = 1;
111
+ case 1:
112
+ _a.trys.push([1, 4, 5, 6]);
113
+ return [4 /*yield*/, client.request("SELECT FROM 'PDFPROTESTO'.'AI'", { nm_chave: nm_chave })];
114
+ case 2: return [4 /*yield*/, (_a.sent()).json()];
115
+ case 3:
116
+ response = _a.sent();
117
+ if (response && response['Quem Apresentou']) {
118
+ setQuemApresentou(response['Quem Apresentou']);
119
+ }
120
+ return [3 /*break*/, 6];
121
+ case 4:
122
+ error_1 = _a.sent();
123
+ console.error('Error fetching Quem Apresentou:', error_1);
124
+ return [3 /*break*/, 6];
125
+ case 5:
126
+ setLoading(false);
127
+ activeRequests--;
128
+ processQueue(); // Process next request in queue
129
+ return [7 /*endfinally*/];
130
+ case 6: return [2 /*return*/];
131
+ }
132
+ });
133
+ }); };
134
+ // Function to queue or execute the fetch request
135
+ var queueOrExecuteFetch = function (nm_chave) {
136
+ var executeRequest = function () {
137
+ fetchQuemApresentou(nm_chave);
138
+ };
139
+ if (activeRequests < MAX_CONCURRENT_REQUESTS) {
140
+ // Execute immediately if under threshold
141
+ activeRequests++;
142
+ executeRequest();
143
+ }
144
+ else {
145
+ // Queue the request
146
+ setQueued(true);
147
+ requestQueue.push(function () {
148
+ setQueued(false);
149
+ executeRequest();
150
+ });
151
+ }
152
+ };
153
+ useEffect(function () {
154
+ // Check if nomeCedente is empty
155
+ var nomeCedente = getField('./nomeCedente');
156
+ if (nomeCedente && nomeCedente.trim() !== '')
157
+ return;
158
+ // Get nm_chave and queue/execute the request
159
+ var nm_chave = getField('./nm_chave');
160
+ if (nm_chave) {
161
+ queueOrExecuteFetch(nm_chave);
162
+ }
163
+ // Cleanup function
164
+ return function () {
165
+ // If this component unmounts while in queue, try to remove it from queue
166
+ var queueIndex = requestQueue.findIndex(function (req) {
167
+ return req.toString().includes(nm_chave);
168
+ });
169
+ if (queueIndex !== -1) {
170
+ requestQueue.splice(queueIndex, 1);
171
+ }
172
+ };
173
+ }, []);
174
+ // Get the display value for Quem Protestou field
175
+ var getQuemProtestouDisplay = function () {
176
+ var baseValue = quemApresentou || getField('./nomeCedente');
177
+ if (loading || queued) {
178
+ return React.createElement(React.Fragment, null,
179
+ baseValue || '',
180
+ " ",
181
+ React.createElement(ThreeDotsLoader, null));
182
+ }
183
+ return baseValue;
184
+ };
55
185
  return (React.createElement(ResultContent, { print: "repeat(7, 1fr)", desktop: "repeat(8, 1fr)", tablet: "repeat(4, 1fr)", mobile: "repeat(2, 1fr)" },
56
- React.createElement(AddItemField, { name: "Quem Protestou", value: getField('./nomeCedente') }),
186
+ React.createElement(AddItemField, { name: "Quem Protestou", value: getQuemProtestouDisplay() }),
57
187
  React.createElement(AddItemField, { name: "Atrav\u00E9s De", value: getField('./nomeApresentante') }),
58
188
  React.createElement(AddItemField, { name: "CPF/CNPJ Protestado", value: formatDocument(getField('./cpfCnpj')) }),
59
189
  React.createElement(AddItemField, { name: "Data Do Protesto", value: getField('./dataProtesto') }),