@credithub/harlan-components 1.59.1 → 1.59.2

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 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';
@@ -21,18 +21,16 @@ var Liminar = function () {
21
21
  var ctx = useContext(Queries.LiminarCenprot);
22
22
  var _d = useGlobalData(), globalData = _d.data, setData = _d.setData;
23
23
  var _e = useState(undefined), liminarResult = _e[0], setLiminarResult = _e[1];
24
+ var _f = useState(true), isProcessing = _f[0], setIsProcessing = _f[1];
24
25
  var didRunRef = useRef(false);
25
26
  var carousel = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel;
26
27
  var isPJDataLoaded = (_b = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _b === void 0 ? void 0 : _b.isLoaded;
27
28
  var empresas = (_c = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _c === void 0 ? void 0 : _c.empresa;
28
29
  useEffect(function () {
29
30
  var _a;
30
- if (didRunRef.current)
31
+ if (didRunRef.current || !carousel || !isPJDataLoaded)
31
32
  return;
32
- if (!carousel || !isPJDataLoaded)
33
- return;
34
- var empresaNome = carousel.name || '';
35
- var empresaNomeNormalizado = normalizeName(empresaNome);
33
+ var empresaNomeNormalizado = normalizeName((carousel === null || carousel === void 0 ? void 0 : carousel.name) || '');
36
34
  var validAssuntos = [
37
35
  'protesto indevido de títulos',
38
36
  'inclusão indevida em cadastro de inadimplentes',
@@ -45,60 +43,56 @@ var Liminar = function () {
45
43
  var processosAtivo = empresas === null || empresas === void 0 ? void 0 : empresas.filter(function (processo) {
46
44
  var _a;
47
45
  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));
46
+ return envolvido.envolvido_tipo === 'Ativo' &&
47
+ similarNames(normalizeName(envolvido.nome_sem_filtro), empresaNomeNormalizado);
51
48
  });
52
49
  var assuntos = Array.isArray(processo.assuntos)
53
50
  ? processo.assuntos
54
51
  : [processo.assuntos];
55
52
  var hasValidAssunto = assuntos.some(function (assunto) {
56
- var assuntoNormalizado = normalizeName(assunto);
57
53
  return validAssuntos.some(function (valid) {
58
- return similarNames(assuntoNormalizado, valid);
54
+ return similarNames(normalizeName(assunto), valid);
59
55
  });
60
56
  });
61
57
  return hasAtivoEnvolvido && hasValidAssunto;
62
58
  });
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;
59
+ var isProcessoNaoEncontrado = ctx.type === RequestStatus.Error &&
60
+ String(ctx.error).includes('Processo(s) não encontrado(s).');
61
+ if (ctx.type === RequestStatus.Error && !isProcessoNaoEncontrado) {
62
+ console.error('Erro na requisição de liminares:', ctx.error || 'Erro desconhecido');
75
63
  }
64
+ var isSuccess = ctx.type === RequestStatus.Success || isProcessoNaoEncontrado;
65
+ var indiciosDeLiminar = isSuccess
66
+ ? ((_a = ctx.document) === null || _a === void 0 ? void 0 : _a.indiciosDeLiminar) === true
67
+ : false;
76
68
  var finalStatus = indiciosDeLiminar || (processosAtivo && processosAtivo.length > 0)
77
69
  ? 'Encontrado'
78
70
  : 'Não encontrado';
79
71
  setData(function (prev) { return (__assign(__assign({}, prev), { liminar: { indiciosDeLiminar: indiciosDeLiminar, message: finalStatus } })); });
80
72
  setLiminarResult(finalStatus);
73
+ setIsProcessing(false);
81
74
  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') {
75
+ }, [carousel, isPJDataLoaded, empresas, ctx, setData]);
76
+ var isProcessoNaoEncontrado = ctx.type === RequestStatus.Error &&
77
+ String(ctx.error).includes('Processo(s) não encontrado(s).');
78
+ var derivedCtx = useMemo(function () { return (__assign(__assign({}, ctx), { type: isProcessoNaoEncontrado ? RequestStatus.Success : ctx.type, document: isProcessoNaoEncontrado
79
+ ? { indiciosDeLiminar: false }
80
+ : ctx.document })); }, [ctx, isProcessoNaoEncontrado]);
81
+ if (!isProcessing && liminarResult === 'Não encontrado')
92
82
  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
- } }));
83
+ return (React.createElement(Section, { title: "Liminares para Remo\u00E7\u00E3o de Protesto", subtitle: isProcessing
84
+ ? 'Carregando liminar...'
85
+ : 'Indícios de liminares para ocultação de registros.', icon: ProtestosIcon, ctx: isProcessing ? __assign(__assign({}, ctx), { type: RequestStatus.Loading }) : derivedCtx, onSuccess: isProcessing
86
+ ? undefined
87
+ : function (data, context) {
88
+ var _a;
89
+ var globalMessage = ((_a = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _a === void 0 ? void 0 : _a.message) || 'Não encontrado';
90
+ var variant = globalMessage === 'Encontrado' ? 'error' : 'default';
91
+ return {
92
+ children: React.createElement(React.Fragment, null),
93
+ variant: variant,
94
+ description: (React.createElement(StatusMessage, { type: variant }, globalMessage))
95
+ };
96
+ } }));
103
97
  };
104
98
  export default Liminar;