@credithub/harlan-components 1.91.2 → 1.91.4

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.
@@ -1,4 +1,7 @@
1
1
  import React from 'react';
2
+ /** ------------------------------------------------------------------
3
+ * Componente principal ---------------------------------------------
4
+ * ------------------------------------------------------------------*/
2
5
  declare const Falencia: React.FC<{
3
6
  documento: string;
4
7
  }>;
@@ -12,54 +12,72 @@ var __assign = (this && this.__assign) || function () {
12
12
  import React, { useEffect, useMemo, useState } from 'react';
13
13
  import FalenciaIcon from '../../assets/icones/falenciaIcon';
14
14
  import { useGlobalData } from '../../contexts/globalDataContext';
15
+ import AddItemField from '../common/addItem';
16
+ import { Result, ResultContent } from '../interface/result';
15
17
  import Section from '../section';
16
18
  import { RequestStatus, useQuery } from '../webservice';
17
- function parseFalencia(document) {
18
- var _a;
19
- if (!document)
20
- return [];
21
- if (Array.isArray(document)) {
22
- return document;
23
- }
24
- try {
25
- var raw = (_a = document.textContent) === null || _a === void 0 ? void 0 : _a.trim();
26
- if (raw) {
27
- var json = JSON.parse(raw);
28
- if (Array.isArray(json))
29
- return json;
30
- }
31
- }
32
- catch (_b) { }
33
- try {
34
- var items = document.querySelectorAll('item');
35
- if (items === null || items === void 0 ? void 0 : items.length) {
36
- return Array.from(items).map(function (item) {
37
- var _a, _b, _c, _d, _e, _f, _g;
38
- return ({
39
- title: (_c = (_b = (_a = item.querySelector('title')) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '',
40
- description: (_e = (_d = item.querySelector('description')) === null || _d === void 0 ? void 0 : _d.textContent) !== null && _e !== void 0 ? _e : '',
41
- link: (_g = (_f = item.querySelector('link')) === null || _f === void 0 ? void 0 : _f.textContent) !== null && _g !== void 0 ? _g : ''
42
- });
43
- });
44
- }
45
- }
46
- catch (_c) { }
47
- return [];
19
+ /** ------------------------------------------------------------------
20
+ * Helpers -----------------------------------------------------------
21
+ * ------------------------------------------------------------------*/
22
+ function normalizeMovimentacao(text) {
23
+ return text
24
+ .replace('Falências', 'Falência')
25
+ .replace('Requeridas', 'Requerida')
26
+ .replace('Decretadas', 'Decretada')
27
+ .replace('Extintos', 'Extinto')
28
+ .trim();
29
+ }
30
+ function cleanDate(dateStr) {
31
+ return dateStr.replace(/\s+\d{2}h\d{2}/, '').trim();
32
+ }
33
+ function buildSubtitle(records) {
34
+ // Busca o primeiro registro que realmente possua movimentação
35
+ var rec = records.find(function (r) { return Array.isArray(r.falimentar) && r.falimentar.length; });
36
+ if (!rec)
37
+ return 'Movimentos falimentares encontrados.';
38
+ var latest = rec.falimentar[0];
39
+ if (!latest)
40
+ return 'Movimentos falimentares encontrados.';
41
+ var movimentacao = normalizeMovimentacao(latest.movimentacao);
42
+ var date = cleanDate(latest.data);
43
+ return "".concat(movimentacao, " - ").concat(date);
48
44
  }
45
+ /** ------------------------------------------------------------------
46
+ * Componente principal ---------------------------------------------
47
+ * ------------------------------------------------------------------*/
49
48
  var Falencia = function (_a) {
50
49
  var documento = _a.documento;
51
50
  var setData = useGlobalData().setData;
52
51
  var _b = useState(false), dataUpdated = _b[0], setDataUpdated = _b[1];
53
52
  var _c = useQuery("SELECT FROM 'ValorEconomico'.'Falencia'", { documento: documento }), response = _c.response, error = _c.error, isLoading = _c.isLoading, loadingProgress = _c.loadingProgress, refetch = _c.refetch;
54
- var items = useMemo(function () { return parseFalencia(response === null || response === void 0 ? void 0 : response.document); }, [response]);
55
- var insolvencia = useMemo(function () { return items.length > 0; }, [items]);
53
+ // Transforma o retorno em array tipado ----------------------------------
54
+ var records = useMemo(function () {
55
+ if (!(response === null || response === void 0 ? void 0 : response.document))
56
+ return [];
57
+ try {
58
+ if (Array.isArray(response.document))
59
+ return response.document;
60
+ return JSON.parse(response.document);
61
+ }
62
+ catch (_a) {
63
+ return [];
64
+ }
65
+ }, [response]);
66
+ /**
67
+ * Há insolvência quando existe pelo menos UMA movimentação falimentar.
68
+ */
69
+ var insolvencia = useMemo(function () {
70
+ return records.some(function (r) { return Array.isArray(r.falimentar) && r.falimentar.length > 0; });
71
+ }, [records]);
72
+ /** Atualiza o contexto global apenas uma vez ---------------------------*/
56
73
  useEffect(function () {
57
74
  if (insolvencia && !dataUpdated) {
58
75
  setData(function (prev) { return (__assign(__assign({}, prev), { insolvencia: insolvencia })); });
59
76
  setDataUpdated(true);
60
77
  }
61
78
  }, [insolvencia, setData, dataUpdated]);
62
- if (!isLoading && items.length === 0)
79
+ /** Se não dados e não estamos carregando, não renderiza o componente */
80
+ if (!isLoading && !insolvencia)
63
81
  return null;
64
82
  var variant = isLoading
65
83
  ? 'loading'
@@ -79,6 +97,23 @@ var Falencia = function (_a) {
79
97
  Section: Section,
80
98
  progress: loadingProgress
81
99
  };
82
- return (React.createElement(Section, { title: "Fal\u00EAncias", subtitle: "Movimentos falimentares encontrados.", icon: FalenciaIcon, variant: variant, minimized: false, ctx: ctx }));
100
+ var subtitle = buildSubtitle(records);
101
+ /** ------------------------------------------------------------------
102
+ * RENDERIZA LISTA DE MOVIMENTAÇÕES ANTERIORES ------------------------
103
+ * ------------------------------------------------------------------*/
104
+ var renderMovimentacoes = function () {
105
+ var movimentos = records
106
+ .flatMap(function (r) { return r.falimentar; })
107
+ .map(function (m) { return ({
108
+ movimentacao: normalizeMovimentacao(m.movimentacao),
109
+ data: cleanDate(m.data)
110
+ }); });
111
+ if (!movimentos.length)
112
+ return null;
113
+ return (React.createElement(Result, { resultContentStriped: true, className: "falencia" }, movimentos.map(function (mov, idx) { return (React.createElement(ResultContent, { desktop: "repeat(2, 1fr)", tablet: "repeat(2, 1fr)", mobile: "repeat(2, 1fr)", key: idx },
114
+ React.createElement(AddItemField, { name: "Movimenta\u00E7\u00E3o", value: mov.movimentacao, style: { display: 'inline-block' } }),
115
+ React.createElement(AddItemField, { name: "Data", value: mov.data, style: { display: 'inline-block' } }))); })));
116
+ };
117
+ return (React.createElement(Section, { title: "Movimento Falimentar", subtitle: subtitle, icon: FalenciaIcon, variant: variant, minimized: false, ctx: ctx, onError: renderMovimentacoes, onSuccess: renderMovimentacoes }));
83
118
  };
84
119
  export default Falencia;
@@ -11,7 +11,6 @@ import { ConsultaRfbProvider } from './components/consultaRfb';
11
11
  import ConsultaSimplesSection from './components/consultaSimplesSection/consultaSimplesSection';
12
12
  import { ConsultasComplementaresProvider } from './components/consultasComplementares';
13
13
  import Dominios from './components/dominios/dominios';
14
- import Falencia from './components/falencia/falencia';
15
14
  import ConsultaImoveis from './components/imoveis/imoveisService';
16
15
  import Liminar from './components/liminar/liminar';
17
16
  import ProtestosSP from './components/protestos/protestosSp';
@@ -79,7 +78,6 @@ var ConsultaSimples = function (_a) {
79
78
  React.createElement(ConsultaRfbProvider, { documento: documento },
80
79
  React.createElement(Dossie, { documento: documento, printMode: printMode, isFinancial: isFinancial }),
81
80
  React.createElement(Liminar, { isFinancial: isFinancial, hasCredits: hasCredits, tags: tags }),
82
- React.createElement(Falencia, { documento: documento }),
83
81
  React.createElement(Addresses, { apiKey: apiKey }),
84
82
  React.createElement(Contacts, null),
85
83
  React.createElement(Partners, { onClickQSA: onClickQSA })),