@credithub/harlan-components 1.59.1 → 1.59.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.
@@ -12,27 +12,55 @@ 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, useRef } from 'react';
15
+ import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
16
16
  import StatusMessage from '../interface/statusMessage';
17
17
  import Section from '../section';
18
18
  import { Queries, RequestStatus } from '../webservice';
19
+ function useStableValue(value) {
20
+ var _a = useState(value), stableValue = _a[0], setStableValue = _a[1];
21
+ var lastValueRef = useRef(value);
22
+ var consecutiveFramesRef = useRef(0);
23
+ useEffect(function () {
24
+ lastValueRef.current = value;
25
+ consecutiveFramesRef.current = 0;
26
+ var frame;
27
+ function check() {
28
+ if (lastValueRef.current === value) {
29
+ consecutiveFramesRef.current++;
30
+ if (consecutiveFramesRef.current >= 2) {
31
+ setStableValue(value);
32
+ return;
33
+ }
34
+ }
35
+ else {
36
+ consecutiveFramesRef.current = 0;
37
+ lastValueRef.current = value;
38
+ }
39
+ frame = requestAnimationFrame(check);
40
+ }
41
+ frame = requestAnimationFrame(check);
42
+ return function () { return cancelAnimationFrame(frame); };
43
+ }, [value]);
44
+ return stableValue;
45
+ }
19
46
  var Liminar = function () {
20
47
  var _a, _b, _c;
21
48
  var ctx = useContext(Queries.LiminarCenprot);
22
49
  var _d = useGlobalData(), globalData = _d.data, setData = _d.setData;
23
50
  var _e = useState(undefined), liminarResult = _e[0], setLiminarResult = _e[1];
24
- var didRunRef = useRef(false);
51
+ var _f = useState(true), isProcessing = _f[0], setIsProcessing = _f[1];
25
52
  var carousel = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel;
26
53
  var isPJDataLoaded = (_b = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _b === void 0 ? void 0 : _b.isLoaded;
27
54
  var empresas = (_c = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _c === void 0 ? void 0 : _c.empresa;
55
+ var dataHash = useMemo(function () { return JSON.stringify({ carousel: carousel, isPJDataLoaded: isPJDataLoaded, empresas: empresas }); }, [carousel, isPJDataLoaded, empresas]);
56
+ var stableDataHash = useStableValue(dataHash);
28
57
  useEffect(function () {
29
58
  var _a;
30
- if (didRunRef.current)
59
+ if (stableDataHash !== dataHash)
31
60
  return;
32
61
  if (!carousel || !isPJDataLoaded)
33
62
  return;
34
- var empresaNome = carousel.name || '';
35
- var empresaNomeNormalizado = normalizeName(empresaNome);
63
+ var empresaNomeNormalizado = normalizeName((carousel === null || carousel === void 0 ? void 0 : carousel.name) || '');
36
64
  var validAssuntos = [
37
65
  'protesto indevido de títulos',
38
66
  'inclusão indevida em cadastro de inadimplentes',
@@ -45,60 +73,63 @@ var Liminar = function () {
45
73
  var processosAtivo = empresas === null || empresas === void 0 ? void 0 : empresas.filter(function (processo) {
46
74
  var _a;
47
75
  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));
76
+ return envolvido.envolvido_tipo === 'Ativo' &&
77
+ similarNames(normalizeName(envolvido.nome_sem_filtro), empresaNomeNormalizado);
51
78
  });
52
79
  var assuntos = Array.isArray(processo.assuntos)
53
80
  ? processo.assuntos
54
81
  : [processo.assuntos];
55
82
  var hasValidAssunto = assuntos.some(function (assunto) {
56
- var assuntoNormalizado = normalizeName(assunto);
57
83
  return validAssuntos.some(function (valid) {
58
- return similarNames(assuntoNormalizado, valid);
84
+ return similarNames(normalizeName(assunto), valid);
59
85
  });
60
86
  });
61
87
  return hasAtivoEnvolvido && hasValidAssunto;
62
88
  });
63
- var indiciosDeLiminar = false;
64
- if (ctx.type === RequestStatus.Error) {
65
- if (ctx.error &&
66
- String(ctx.error).includes('Processo(s) não encontrado(s).')) {
67
- indiciosDeLiminar = false;
68
- }
69
- else {
70
- console.error('Erro na requisição de liminares:', ctx.error || 'Erro desconhecido');
71
- }
72
- }
73
- else if (ctx.type === RequestStatus.Success) {
74
- indiciosDeLiminar = ((_a = ctx.document) === null || _a === void 0 ? void 0 : _a.indiciosDeLiminar) === true;
89
+ var isProcessoNaoEncontrado = ctx.type === RequestStatus.Error &&
90
+ String(ctx.error).includes('Processo(s) não encontrado(s).');
91
+ if (ctx.type === RequestStatus.Error && !isProcessoNaoEncontrado) {
92
+ console.error('Erro na requisição de liminares:', ctx.error || 'Erro desconhecido');
75
93
  }
94
+ var isSuccess = ctx.type === RequestStatus.Success || isProcessoNaoEncontrado;
95
+ var indiciosDeLiminar = isSuccess
96
+ ? ((_a = ctx.document) === null || _a === void 0 ? void 0 : _a.indiciosDeLiminar) === true
97
+ : false;
76
98
  var finalStatus = indiciosDeLiminar || (processosAtivo && processosAtivo.length > 0)
77
99
  ? 'Encontrado'
78
100
  : 'Não encontrado';
79
101
  setData(function (prev) { return (__assign(__assign({}, prev), { liminar: { indiciosDeLiminar: indiciosDeLiminar, message: finalStatus } })); });
80
102
  setLiminarResult(finalStatus);
81
- didRunRef.current = true;
82
- }, [carousel, isPJDataLoaded, empresas, ctx.type, setData]);
83
- var derivedCtx = useMemo(function () {
84
- if (liminarResult === undefined) {
85
- return __assign(__assign({}, ctx), { type: RequestStatus.Loading });
86
- }
87
- return __assign(__assign({}, ctx), { type: ctx.type === RequestStatus.Error ? RequestStatus.Success : ctx.type, document: ctx.type === RequestStatus.Error
88
- ? { indiciosDeLiminar: false }
89
- : ctx.document });
90
- }, [liminarResult, ctx]);
91
- if (liminarResult === 'Não encontrado') {
103
+ setIsProcessing(false);
104
+ }, [
105
+ stableDataHash,
106
+ dataHash,
107
+ carousel,
108
+ isPJDataLoaded,
109
+ empresas,
110
+ ctx,
111
+ setData
112
+ ]);
113
+ var isProcessoNaoEncontrado = ctx.type === RequestStatus.Error &&
114
+ String(ctx.error).includes('Processo(s) não encontrado(s).');
115
+ var derivedCtx = useMemo(function () { return (__assign(__assign({}, ctx), { type: isProcessoNaoEncontrado ? RequestStatus.Success : ctx.type, document: isProcessoNaoEncontrado
116
+ ? { indiciosDeLiminar: false }
117
+ : ctx.document })); }, [ctx, isProcessoNaoEncontrado]);
118
+ if (!isProcessing && liminarResult === 'Não encontrado')
92
119
  return null;
93
- }
94
- 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) {
95
- var _a;
96
- var globalMessage = ((_a = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _a === void 0 ? void 0 : _a.message) || 'Não encontrado';
97
- return {
98
- children: React.createElement(React.Fragment, null),
99
- variant: globalMessage === 'Encontrado' ? 'error' : 'default',
100
- description: (React.createElement(StatusMessage, { type: globalMessage === 'Encontrado' ? 'error' : 'default' }, globalMessage))
101
- };
102
- } }));
120
+ return (React.createElement(Section, { title: "Liminares para Remo\u00E7\u00E3o de Protesto", subtitle: isProcessing
121
+ ? 'Carregando liminar...'
122
+ : 'Indícios de liminares para ocultação de registros.', icon: ProtestosIcon, ctx: isProcessing ? __assign(__assign({}, ctx), { type: RequestStatus.Loading }) : derivedCtx, onSuccess: isProcessing
123
+ ? undefined
124
+ : function (data, context) {
125
+ var _a;
126
+ var globalMessage = ((_a = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _a === void 0 ? void 0 : _a.message) || 'Não encontrado';
127
+ var variant = globalMessage === 'Encontrado' ? 'error' : 'default';
128
+ return {
129
+ children: React.createElement(React.Fragment, null),
130
+ variant: variant,
131
+ description: (React.createElement(StatusMessage, { type: variant }, globalMessage))
132
+ };
133
+ } }));
103
134
  };
104
135
  export default Liminar;