@credithub/harlan-components 1.88.0 → 1.89.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.
@@ -1,5 +1,17 @@
1
- import React, { useMemo } from 'react';
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import React, { useEffect, useMemo, useState } from 'react';
2
13
  import FalenciaIcon from '../../assets/icones/falenciaIcon';
14
+ import { useGlobalData } from '../../contexts/globalDataContext';
3
15
  import Section from '../section';
4
16
  import { RequestStatus, useQuery } from '../webservice';
5
17
  function parseFalencia(document) {
@@ -36,29 +48,38 @@ function parseFalencia(document) {
36
48
  }
37
49
  var Falencia = function (_a) {
38
50
  var documento = _a.documento;
39
- var _b = useQuery("SELECT FROM 'ValorEconomico'.'Falencia'", { documento: documento }), response = _b.response, error = _b.error, isLoading = _b.isLoading, refetch = _b.refetch;
51
+ var setData = useGlobalData().setData;
52
+ var _b = useState(false), dataUpdated = _b[0], setDataUpdated = _b[1];
53
+ // ⬇️ 1. traga o loadingProgress
54
+ var _c = useQuery("SELECT FROM 'ValorEconomico'.'Falencia'", { documento: documento }), response = _c.response, error = _c.error, isLoading = _c.isLoading, loadingProgress = _c.loadingProgress, refetch = _c.refetch;
40
55
  var items = useMemo(function () { return parseFalencia(response === null || response === void 0 ? void 0 : response.document); }, [response]);
41
- var shouldRender = isLoading || items.length > 0;
42
- if (!shouldRender)
56
+ var insolvencia = useMemo(function () { return items.length > 0; }, [items]);
57
+ useEffect(function () {
58
+ if (insolvencia && !dataUpdated) {
59
+ setData(function (prev) { return (__assign(__assign({}, prev), { insolvencia: insolvencia })); });
60
+ setDataUpdated(true);
61
+ }
62
+ }, [insolvencia, setData, dataUpdated]);
63
+ if (!isLoading && items.length === 0)
43
64
  return null;
44
- // 🔴 cora a seção de vermelho se houver falência
45
65
  var variant = isLoading
46
66
  ? 'loading'
47
- : items.length > 0
67
+ : insolvencia
48
68
  ? 'error'
49
69
  : 'default';
50
- /** ------------------------------------------------------------
51
- * ctx precisa ter `Section` e `refetch`
52
- * ----------------------------------------------------------- */
53
70
  var ctx = {
54
- type: isLoading ? RequestStatus.Loading : RequestStatus.Success,
71
+ type: isLoading
72
+ ? RequestStatus.Loading
73
+ : error
74
+ ? RequestStatus.Error
75
+ : RequestStatus.Success,
55
76
  error: error,
56
77
  document: response === null || response === void 0 ? void 0 : response.document,
57
78
  response: response === null || response === void 0 ? void 0 : response.response,
58
- refetch: refetch, // ← agora existe
59
- Section: Section // ← pode ser o próprio componente (não é usado)
79
+ refetch: refetch,
80
+ Section: Section,
81
+ progress: loadingProgress
60
82
  };
61
- // Passa o variant para colorir header/icon de acordo
62
83
  return (React.createElement(Section, { title: "Fal\u00EAncias", subtitle: "Movimentos falimentares encontrados.", icon: FalenciaIcon, variant: variant, minimized: false, ctx: ctx }));
63
84
  };
64
85
  export default Falencia;
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import { Client } from '@credithub/webservice';
38
- import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
38
+ import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
39
39
  import Section from './section';
40
40
  export var WebService = createContext(new Client.WebService());
41
41
  export var WebServiceProvider = function (_a) {
@@ -207,17 +207,16 @@ export function useQuery(query, data, enabled) {
207
207
  var _b = useState(null), error = _b[0], setError = _b[1];
208
208
  var _c = useState(false), isLoading = _c[0], setIsLoading = _c[1];
209
209
  var _d = useState(true), shouldFetch = _d[0], setShouldFetch = _d[1];
210
- var loadingProgressRef = useRef(0);
210
+ var _e = useState(0), loadingProgress = _e[0], setProgress = _e[1];
211
211
  var memoizedData = useMemo(function () { return data; }, [JSON.stringify(data)]);
212
212
  var simulateProgress = useCallback(function () {
213
- loadingProgressRef.current = 0;
214
- var progress = 0;
213
+ setProgress(0);
214
+ var p = 0;
215
215
  var interval = setInterval(function () {
216
- progress += 15;
217
- loadingProgressRef.current = progress;
218
- if (progress >= 90) {
216
+ p += 15;
217
+ setProgress(Math.min(p, 90));
218
+ if (p >= 90)
219
219
  clearInterval(interval);
220
- }
221
220
  }, 300);
222
221
  return function () { return clearInterval(interval); };
223
222
  }, []);
@@ -238,7 +237,7 @@ export function useQuery(query, data, enabled) {
238
237
  .then(function (parsedResponse) {
239
238
  setResponse(parsedResponse);
240
239
  setError(null);
241
- loadingProgressRef.current = 100;
240
+ setProgress(100);
242
241
  })
243
242
  .catch(function (requestError) {
244
243
  if (requestError.name !== 'AbortError') {
@@ -246,7 +245,7 @@ export function useQuery(query, data, enabled) {
246
245
  ? requestError
247
246
  : new Error(String(requestError)));
248
247
  }
249
- loadingProgressRef.current = 100;
248
+ setProgress(100);
250
249
  })
251
250
  .finally(function () {
252
251
  setIsLoading(false);
@@ -271,7 +270,7 @@ export function useQuery(query, data, enabled) {
271
270
  response: response,
272
271
  error: error,
273
272
  isLoading: isLoading,
274
- loadingProgress: loadingProgressRef.current,
273
+ loadingProgress: loadingProgress,
275
274
  refetch: refetch
276
275
  };
277
276
  }