@credithub/harlan-components 1.59.6 → 1.59.8

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.
@@ -10,14 +10,12 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  /* eslint-disable @typescript-eslint/no-unused-vars */
13
- import React, { memo, useState } from 'react';
13
+ import React, { memo } from 'react';
14
14
  import Carousel from '../common/carousel';
15
- import { useQuery } from '../webservice';
16
15
  import ChevronLeft from '../../assets/btn/chevronLeft';
17
16
  import ChevronRight from '../../assets/btn/chevronRight';
18
17
  import { formatValue } from '../../utils/number';
19
18
  import { statusMap } from '../../constants/reclameAqui';
20
- import { useGlobalData } from '../../contexts/globalDataContext';
21
19
  import Carrousel from '../dossie/carrousel/carrousel';
22
20
  import { CarrouselBtn, CompanyName, ContainerSummary, DocumentContainer, DocumentPrefix, LogoContainer, ProblemsSolved, ReclameAquiStatsContainer, StatsImage, StyledImage } from './styles';
23
21
  var translateStatus = function (status) {
@@ -51,30 +49,16 @@ var ReclameAquiStats = function (_a) {
51
49
  "/10")),
52
50
  React.createElement(ProblemasResolvidos, { value: percentualProblemasResolvidos + '%' }))));
53
51
  };
52
+ // Convert this to a pure presentational component
54
53
  export var ReclameAquiCarousel = memo(function (_a) {
55
- var _b;
56
- var nome = _a.nome, documento = _a.documento;
57
- var _c = useQuery("SELECT FROM 'RECLAMEAQUI'.'CONSULTA'", { documento: documento }), response = _c.response, isLoading = _c.isLoading, error = _c.error;
58
- var setData = useGlobalData().setData;
59
- var _d = useState(false), dataUpdated = _d[0], setDataUpdated = _d[1];
60
- if (isLoading ||
61
- error ||
62
- ((response === null || response === void 0 ? void 0 : response.document) && !((_b = response === null || response === void 0 ? void 0 : response.document) === null || _b === void 0 ? void 0 : _b.length))) {
54
+ var nome = _a.nome, documento = _a.documento, companies = _a.companies;
55
+ // If no companies data is provided, fallback to regular carousel
56
+ if (!companies || companies.length === 0) {
63
57
  return React.createElement(Carrousel, { name: nome, document: documento });
64
58
  }
65
- var companies = response === null || response === void 0 ? void 0 : response.document.map(function (item) { return ({
66
- nome: nome,
67
- cnpj: documento,
68
- score: item.infos.finalScore,
69
- status: item.infos.status,
70
- shortname: item.infos.shortname,
71
- imageUrl: item.infos.logo,
72
- quantidadeProblemasResolvidos: item.infos.count.toString(),
73
- percentualProblemasResolvidos: item.infos.solvedPercentual
74
- }); });
75
59
  return (React.createElement(ContainerSummary, null,
76
- React.createElement(Carousel, { pagination: false, isRTL: false, showArrows: companies && companies.length > 1, renderArrow: function (_a) {
60
+ React.createElement(Carousel, { pagination: false, isRTL: false, showArrows: companies.length > 1, renderArrow: function (_a) {
77
61
  var type = _a.type, onClick = _a.onClick;
78
62
  return (React.createElement(CarrouselBtn, null, type === 'PREV' ? (React.createElement(ChevronLeft, { onClick: onClick })) : (React.createElement(ChevronRight, { onClick: onClick }))));
79
- } }, companies === null || companies === void 0 ? void 0 : companies.map(function (empresa, index) { return (React.createElement(ReclameAquiStats, __assign({ key: index }, empresa))); }))));
63
+ } }, companies.map(function (empresa, index) { return (React.createElement(ReclameAquiStats, __assign({ key: "reclameaqui-".concat(index) }, empresa))); }))));
80
64
  });
@@ -208,6 +208,7 @@ export function useQuery(query, data, enabled) {
208
208
  var _c = useState(false), isLoading = _c[0], setIsLoading = _c[1];
209
209
  var _d = useState(false), shouldFetch = _d[0], setShouldFetch = _d[1];
210
210
  var loadingProgressRef = useRef(0);
211
+ var memoizedData = useMemo(function () { return data; }, [JSON.stringify(data)]);
211
212
  var simulateProgress = useCallback(function () {
212
213
  loadingProgressRef.current = 0;
213
214
  var progress = 0;
@@ -227,7 +228,7 @@ export function useQuery(query, data, enabled) {
227
228
  simulateProgress();
228
229
  var abortController = new AbortController();
229
230
  client
230
- .request(query, data, undefined, abortController.signal)
231
+ .request(query, memoizedData, undefined, abortController.signal)
231
232
  .then(function (response) {
232
233
  return Client.WebService.parse(response).then(function (document) { return ({
233
234
  response: response,
@@ -252,20 +253,20 @@ export function useQuery(query, data, enabled) {
252
253
  setShouldFetch(false);
253
254
  });
254
255
  return function () { return abortController.abort(); };
255
- }, [shouldFetch, isLoading, client, query, data, simulateProgress]);
256
+ }, [shouldFetch, isLoading, client, query, memoizedData, simulateProgress]);
257
+ useEffect(function () {
258
+ if (enabled && !response && !error && !isLoading && !shouldFetch) {
259
+ setShouldFetch(true);
260
+ }
261
+ }, []);
256
262
  useEffect(function () {
257
263
  if (enabled && shouldFetch) {
258
264
  fetch();
259
265
  }
260
266
  }, [fetch, shouldFetch, enabled]);
261
- useEffect(function () {
262
- if (enabled && !isLoading && !shouldFetch && !response && !error) {
263
- setShouldFetch(true);
264
- }
265
- }, [enabled, isLoading, shouldFetch, response, error]);
266
267
  var refetch = useCallback(function () {
267
268
  setShouldFetch(true);
268
- }, [query]);
269
+ }, []);
269
270
  return {
270
271
  response: response,
271
272
  error: error,