@credithub/harlan-components 1.95.4 → 1.96.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.
@@ -29,11 +29,12 @@ import { useGlobalData } from '../../contexts/globalDataContext';
29
29
  import { formatMoney } from '../../utils/number';
30
30
  import { formatDocument } from '../../utils/string';
31
31
  import { format } from 'date-fns';
32
- import React, { useContext } from 'react';
32
+ import React, { useContext, useEffect } from 'react';
33
33
  import styled, { keyframes } from 'styled-components';
34
34
  import Section from '../interface/section';
35
35
  import StatusMessage from '../interface/statusMessage';
36
36
  import { Queries, RequestStatus } from '../webservice';
37
+ import { usePostHog } from '../../contexts/PostHogContext';
37
38
  // Animação do spinner
38
39
  var spin = keyframes(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n"], ["\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n"])));
39
40
  // Componente Spinner sutil
@@ -43,6 +44,7 @@ var ConsultaSimplesSection = function (_a) {
43
44
  var documento = _a.documento, children = _a.children, onClose = _a.onClose, isFinancial = _a.isFinancial, rest = __rest(_a, ["documento", "children", "onClose", "isFinancial"]);
44
45
  var ctx = useContext(Queries.Finder);
45
46
  var data = useGlobalData().data;
47
+ var posthog = usePostHog().posthog;
46
48
  // Extraindo valores do globalData
47
49
  var receitaStatus = ((_c = (_b = data.dossie) === null || _b === void 0 ? void 0 : _b.summary) === null || _c === void 0 ? void 0 : _c.receitaStatus) &&
48
50
  ['ATIVA', 'REGULAR'].indexOf(data.dossie.summary.receitaStatus) === -1
@@ -104,6 +106,16 @@ var ConsultaSimplesSection = function (_a) {
104
106
  receitaStatus ||
105
107
  ((_p = data.liminar) === null || _p === void 0 ? void 0 : _p.message) === 'Encontrado';
106
108
  var statusType = isError ? 'warning' : hasPendencias ? 'error' : 'success';
109
+ useEffect(function () {
110
+ if (posthog && pendencias.every(function (pendencia) { return pendencia.loaded; }))
111
+ posthog === null || posthog === void 0 ? void 0 : posthog.capture('consulta_simples', {
112
+ documento: documento,
113
+ pendencias: pendencias.map(function (pendencia) { return ({
114
+ label: pendencia.label,
115
+ text: pendencia.text,
116
+ }); }),
117
+ });
118
+ }, [posthog, pendencias]);
107
119
  return (React.createElement(Section, __assign({ title: "Consulta Simples", subtitle: "Consulta de informa\u00E7\u00F5es do documento.", description: React.createElement(React.Fragment, null,
108
120
  React.createElement(StatusMessage, null, format(new Date(), "dd/MM/yyyy 'às' HH:mm")),
109
121
  React.createElement(StatusMessage, { type: "found" }, formatDocument(documento)),
@@ -41,13 +41,14 @@ var GraficosAnaliticosDependency = function (_a) {
41
41
  };
42
42
  var HasCreditsVerification = function (_a) {
43
43
  var children = _a.children, documento = _a.documento, apiKey = _a.apiKey;
44
- var _b = useQuery("SELECT FROM 'HARLANCREDITS'.'HASCREDITS'", { documento: documento }), response = _b.response, error = _b.error, isLoading = _b.isLoading;
45
- var _c = useToggle(true), isOpen = _c[0], toggle = _c[1];
46
- if (isLoading || error)
47
- return React.createElement(React.Fragment, null);
48
- if (response === null || response === void 0 ? void 0 : response.document) {
44
+ var response = useQuery("SELECT FROM 'HARLANCREDITS'.'HASCREDITS'", { documento: documento }).response;
45
+ var _b = useToggle(true), isOpen = _b[0], toggle = _b[1];
46
+ // Se não houver resposta ainda ou se a consulta retornar "tem créditos",
47
+ // libera os filhos normalmente (não desmonta nada).
48
+ if (!response || response.document) {
49
49
  return React.createElement(React.Fragment, null, children);
50
50
  }
51
+ // Caso a resposta indique ausência de créditos, mostra o modal.
51
52
  return (React.createElement(Modal, { isOpen: isOpen, onClose: toggle, title: "Aten\u00E7\u00E3o: Voc\u00EA precisa de cr\u00E9ditos!", footer: null },
52
53
  React.createElement("p", { style: { fontSize: 18 } },
53
54
  "Voc\u00EA n\u00E3o possui cr\u00E9ditos para realizar esta consulta.",