@credithub/harlan-components 1.69.2 → 1.69.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.
@@ -9,6 +9,7 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ /* eslint-disable react-hooks/exhaustive-deps */
12
13
  import ProtestosIcon from '../../assets/icones/protestos';
13
14
  import { useGlobalData } from '../../contexts/globalDataContext';
14
15
  import theme from '../../styles/theme';
@@ -20,7 +21,7 @@ import Section from '../section';
20
21
  import { Queries, RequestStatus } from '../webservice';
21
22
  import { TitleWithTooltip, TooltipContainer, TooltipText } from './liminarStyles';
22
23
  /* ----------------------------------
23
- * Constantes auxiliares
24
+ * Constantes
24
25
  * ---------------------------------*/
25
26
  var validAssuntos = [
26
27
  'protesto indevido de título',
@@ -43,40 +44,32 @@ var businessTypes = [
43
44
  * Componente
44
45
  * ---------------------------------*/
45
46
  var Liminar = function () {
46
- var _a, _b, _c, _d, _e;
47
+ var _a, _b, _c, _d;
47
48
  /* -------- Contextos -------- */
48
49
  var ctx = useContext(Queries.LiminarCenprot);
49
- var _f = useGlobalData(), globalData = _f.data, setData = _f.setData;
50
- /* -------- Refs de controle de efeitos -------- */
51
- var processedRef = useRef(false); // já finalizou pipeline principal
52
- var dataHashRef = useRef(''); // detecção de repetição
53
- var invertedIdsRef = useRef([]); // cache ids já gravados
50
+ var _e = useGlobalData(), globalData = _e.data, setData = _e.setData;
51
+ /* -------- Refs -------- */
52
+ var processedRef = useRef(false);
53
+ var dataHashRef = useRef('');
54
+ var invertedIdsRef = useRef([]);
54
55
  /* -------- Tooltip -------- */
55
- var _g = useState(false), isTooltipVisible = _g[0], setTooltipVisible = _g[1];
56
- var hideTooltipTimeout = useRef();
57
- var showTooltip = function () {
58
- if (hideTooltipTimeout.current)
59
- clearTimeout(hideTooltipTimeout.current);
60
- setTooltipVisible(true);
61
- };
62
- var hideTooltip = function () {
63
- hideTooltipTimeout.current = setTimeout(function () { return setTooltipVisible(false); }, 300);
64
- };
65
- /* -------- Tipos de documento vindos da API -------- */
56
+ var _f = useState(false), isTooltipVisible = _f[0], setTooltipVisible = _f[1];
57
+ var hideTt = useRef();
58
+ /* ----------------------------------
59
+ * Pré-processamentos
60
+ * ---------------------------------*/
66
61
  var tiposDocumento = useMemo(function () {
67
62
  var _a;
68
63
  var raw = (_a = ctx.document) === null || _a === void 0 ? void 0 : _a.type;
69
64
  if (Array.isArray(raw))
70
65
  return raw.map(function (t) { return t.toLowerCase(); });
71
- if (typeof raw === 'string')
72
- return [raw.toLowerCase()];
73
- return [];
66
+ return raw ? [String(raw).toLowerCase()] : [];
74
67
  }, [ctx.document]);
75
- /* -------- Processos com assunto relevante -------- */
68
+ /* -------- Processos relevantes -------- */
76
69
  var processosComAssuntoValido = useMemo(function () {
77
- var _a, _b, _c;
78
- var carouselName = ((_b = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel) === null || _b === void 0 ? void 0 : _b.name) || '';
79
- var empresas = (_c = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _c === void 0 ? void 0 : _c.empresa;
70
+ var _a, _b, _c, _d;
71
+ var carouselName = (_c = (_b = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : '';
72
+ var empresas = (_d = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _d === void 0 ? void 0 : _d.empresa;
80
73
  var nomeNorm = normalizeName(carouselName);
81
74
  if (!Array.isArray(empresas))
82
75
  return [];
@@ -99,43 +92,37 @@ var Liminar = function () {
99
92
  (_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel,
100
93
  (_b = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _b === void 0 ? void 0 : _b.empresa
101
94
  ]);
102
- /* -------- Labels de origem e detecção de entidade PJ -------- */
103
- var _h = useMemo(function () {
95
+ /* -------- Labels de origem + entidade PJ -------- */
96
+ var _g = useMemo(function () {
104
97
  var _a;
105
- /* Labels */
106
98
  var labels = new Set();
107
99
  var indiciosApi = ((_a = ctx.document) === null || _a === void 0 ? void 0 : _a.indiciosDeLiminar) === true;
108
- if (indiciosApi) {
109
- tiposDocumento.forEach(function (tipo) {
100
+ if (indiciosApi)
101
+ tiposDocumento.forEach(function (t) {
110
102
  var m = {
111
103
  cenprot: 'Liminar no Cenprot',
112
104
  serasa: 'Liminar na Serasa',
113
105
  judicial: 'Liminar no Judiciário'
114
106
  };
115
- if (m[tipo])
116
- labels.add(m[tipo]);
107
+ if (m[t])
108
+ labels.add(m[t]);
117
109
  });
118
- }
119
110
  if (processosComAssuntoValido.length)
120
111
  labels.add('Liminar no Judiciário');
121
- /* PJ “banco”, “fintech”... */
122
- var pjDetectada = processosComAssuntoValido.some(function (proc) {
112
+ var pj = processosComAssuntoValido.some(function (p) {
123
113
  var _a;
124
- return (_a = proc.envolvidos_ultima_movimentacao) === null || _a === void 0 ? void 0 : _a.some(function (e) {
114
+ return (_a = p.envolvidos_ultima_movimentacao) === null || _a === void 0 ? void 0 : _a.some(function (e) {
125
115
  if (e.envolvido_tipo !== 'Ativo')
126
116
  return false;
127
- var nomeNorm = normalizeName(e.nome_sem_filtro);
128
- return businessTypes.some(function (t) { return nomeNorm.includes(t); });
117
+ var n = normalizeName(e.nome_sem_filtro);
118
+ return businessTypes.some(function (t) { return n.includes(t); });
129
119
  });
130
120
  });
131
- return {
132
- origensDetectadas: Array.from(labels),
133
- foundBusinessEntity: pjDetectada
134
- };
135
- }, [ctx.document, tiposDocumento, processosComAssuntoValido]), origensDetectadas = _h.origensDetectadas, foundBusinessEntity = _h.foundBusinessEntity;
136
- /* =========================================================================
137
- * Efeito 1 – gravar IDs invertidos (invertedProcessos) apenas se mudarem
138
- * ========================================================================= */
121
+ return { origensDetectadas: Array.from(labels), foundBusinessEntity: pj };
122
+ }, [ctx.document, tiposDocumento, processosComAssuntoValido]), origensDetectadas = _g.origensDetectadas, foundBusinessEntity = _g.foundBusinessEntity;
123
+ /* ----------------------------------
124
+ * Efeito 1 – invertedProcessos
125
+ * ---------------------------------*/
139
126
  useEffect(function () {
140
127
  if (!foundBusinessEntity)
141
128
  return;
@@ -143,32 +130,30 @@ var Liminar = function () {
143
130
  var same = newIds.length === invertedIdsRef.current.length &&
144
131
  newIds.every(function (id, i) { return id === invertedIdsRef.current[i]; });
145
132
  if (same)
146
- return; // nada mudou → não dispara setState
133
+ return;
147
134
  invertedIdsRef.current = newIds;
148
135
  setData(function (prev) { return (__assign(__assign({}, prev), { liminar: __assign(__assign({}, prev.liminar), { invertedProcessos: newIds }) })); });
149
136
  }, [foundBusinessEntity, processosComAssuntoValido, setData]);
150
- /* =========================================================================
151
- * Efeito 2 – pipeline principal: status “Encontrado / Não encontrado”
152
- * ========================================================================= */
137
+ /* ----------------------------------
138
+ * Efeito 2 – cálculo final
139
+ * ---------------------------------*/
153
140
  useEffect(function () {
154
- var _a, _b, _c, _d;
155
- if (!((_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel) ||
156
- !((_b = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _b === void 0 ? void 0 : _b.isLoaded))
141
+ var _a, _b;
142
+ var dossie = globalData === null || globalData === void 0 ? void 0 : globalData.dossie;
143
+ var processosJuridicos = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData;
144
+ var depsLoaded = !!(processosJuridicos === null || processosJuridicos === void 0 ? void 0 : processosJuridicos.isLoaded) && !!(dossie === null || dossie === void 0 ? void 0 : dossie.carousel);
145
+ if (!depsLoaded || ctx.type === RequestStatus.Loading)
157
146
  return;
158
- if (ctx.type === RequestStatus.Loading)
159
- return; // aguarda terminar
160
- /* hash que depende apenas de campos realmente relevantes */
161
147
  var hash = JSON.stringify({
162
148
  t: ctx.type,
163
- indicios: (_c = ctx.document) === null || _c === void 0 ? void 0 : _c.indiciosDeLiminar,
164
- carousel: globalData.dossie.carousel,
165
- empresas: globalData.processosJuridicosData.empresa
149
+ indicios: (_a = ctx.document) === null || _a === void 0 ? void 0 : _a.indiciosDeLiminar,
150
+ carousel: dossie.carousel, // non-null após depsLoaded
151
+ empresas: processosJuridicos.empresa // idem
166
152
  });
167
153
  if (hash === dataHashRef.current)
168
- return; // já processado
154
+ return;
169
155
  dataHashRef.current = hash;
170
- /* status final */
171
- var indiciosApi = ((_d = ctx.document) === null || _d === void 0 ? void 0 : _d.indiciosDeLiminar) === true;
156
+ var indiciosApi = ((_b = ctx.document) === null || _b === void 0 ? void 0 : _b.indiciosDeLiminar) === true;
172
157
  var finalStatus = indiciosApi || processosComAssuntoValido.length
173
158
  ? 'Encontrado'
174
159
  : 'Não encontrado';
@@ -182,16 +167,23 @@ var Liminar = function () {
182
167
  }, [
183
168
  ctx.type,
184
169
  ctx.document,
185
- (_c = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _c === void 0 ? void 0 : _c.carousel,
186
- (_d = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _d === void 0 ? void 0 : _d.empresa,
170
+ globalData === null || globalData === void 0 ? void 0 : globalData.dossie,
171
+ globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData,
187
172
  processosComAssuntoValido,
188
173
  setData
189
174
  ]);
190
- /* -------- Limpa timeout do tooltip ao desmontar -------- */
191
- useEffect(function () { return function () {
192
- return hideTooltipTimeout.current && clearTimeout(hideTooltipTimeout.current);
193
- }; }, []);
194
- /* ---------------------- UI auxiliares ------------------- */
175
+ /* ----------------------------------
176
+ * Flags de renderização
177
+ * ---------------------------------*/
178
+ var ready = processedRef.current &&
179
+ !!((_c = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _c === void 0 ? void 0 : _c.isLoaded) &&
180
+ !!((_d = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _d === void 0 ? void 0 : _d.carousel) &&
181
+ ctx.type !== RequestStatus.Loading;
182
+ /* ctx “loading” enqto não pronto */
183
+ var ctxLoading = useMemo(function () { return (__assign(__assign({}, ctx), { type: RequestStatus.Loading })); }, [ctx]);
184
+ /* ----------------------------------
185
+ * UI helpers
186
+ * ---------------------------------*/
195
187
  var scrollToProcesso = function (id) {
196
188
  var el = document.getElementById(id);
197
189
  if (!el)
@@ -200,38 +192,42 @@ var Liminar = function () {
200
192
  el.classList.add('highlighted-process');
201
193
  setTimeout(function () { return el.classList.remove('highlighted-process'); }, 3000);
202
194
  };
203
- if (processedRef.current && ((_e = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _e === void 0 ? void 0 : _e.message) === 'Não encontrado')
204
- return null;
205
- var renderTooltipIcon = function () {
206
- var color = origensDetectadas.length
195
+ var renderTooltipIcon = function () { return (React.createElement(WarningCircle, { weight: "fill", size: 24, color: origensDetectadas.length
207
196
  ? theme.colors.erroClaro
208
- : theme.colors.cinzaClaro;
209
- return (React.createElement(WarningCircle, { weight: "fill", size: 24, color: color, style: { marginLeft: 4 } }));
210
- };
211
- /* ---------------------- Render -------------------------- */
197
+ : theme.colors.cinzaClaro, style: { marginLeft: 4 } })); };
198
+ /* ----------------------------------
199
+ * Render
200
+ * ---------------------------------*/
212
201
  return (React.createElement(Section, { title: React.createElement(TitleWithTooltip, null,
213
202
  "Liminares para Remo\u00E7\u00E3o de Protesto",
214
- !!processosComAssuntoValido.length && (React.createElement(TooltipContainer, { onMouseEnter: showTooltip, onMouseLeave: hideTooltip },
203
+ !!processosComAssuntoValido.length && ready && (React.createElement(TooltipContainer, { onMouseEnter: function () {
204
+ clearTimeout(hideTt.current);
205
+ setTooltipVisible(true);
206
+ }, onMouseLeave: function () {
207
+ hideTt.current = setTimeout(function () { return setTooltipVisible(false); }, 300);
208
+ } },
215
209
  renderTooltipIcon(),
216
210
  React.createElement(TooltipText, { visible: isTooltipVisible },
217
211
  React.createElement(React.Fragment, null,
218
212
  "Processos com ind\u00EDcios encontrados:",
219
- React.createElement("ul", { style: { marginTop: 6, paddingLeft: 18 } }, processosComAssuntoValido.map(function (proc) { return (React.createElement("li", { key: proc.id, onClick: function () { return scrollToProcesso(proc.id); }, style: {
213
+ React.createElement("ul", { style: { marginTop: 6, paddingLeft: 18 } }, processosComAssuntoValido.map(function (p) { return (React.createElement("li", { key: p.id, onClick: function () { return scrollToProcesso(p.id); }, style: {
220
214
  fontSize: 13,
221
215
  cursor: 'pointer',
222
216
  textDecoration: 'underline',
223
217
  color: '#007aff'
224
- } }, proc.id)); }))))))), subtitle: "Ind\u00EDcios de liminares para oculta\u00E7\u00E3o de registros.", icon: ProtestosIcon, ctx: ctx, onSuccess: function () {
225
- var _a;
226
- var msg = ((_a = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _a === void 0 ? void 0 : _a.message) || 'Não encontrado';
227
- var variant = msg === 'Encontrado' ? 'error' : 'default';
228
- return {
229
- children: React.createElement(React.Fragment, null),
230
- variant: variant,
231
- description: (React.createElement(React.Fragment, null,
232
- React.createElement(StatusMessage, { type: variant }, msg),
233
- origensDetectadas.map(function (o) { return (React.createElement(StatusMessage, { key: o, type: variant }, o)); })))
234
- };
235
- } }));
218
+ } }, p.id)); }))))))), subtitle: "Ind\u00EDcios de liminares para oculta\u00E7\u00E3o de registros.", icon: ProtestosIcon, ctx: ready ? ctx : ctxLoading, onSuccess: ready
219
+ ? function () {
220
+ var _a, _b;
221
+ var msg = (_b = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Não encontrado';
222
+ var variant = msg === 'Encontrado' ? 'error' : 'default';
223
+ return {
224
+ children: React.createElement(React.Fragment, null),
225
+ variant: variant,
226
+ description: (React.createElement(React.Fragment, null,
227
+ React.createElement(StatusMessage, { type: variant }, msg),
228
+ origensDetectadas.map(function (o) { return (React.createElement(StatusMessage, { key: o, type: variant }, o)); })))
229
+ };
230
+ }
231
+ : undefined }));
236
232
  };
237
233
  export default Liminar;