@credithub/harlan-components 1.51.3 → 1.52.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,9 @@
1
1
  import React from 'react';
2
- declare function ConsultaSCR({ documento }: {
2
+ declare function ConsultaSCR({ documento, onAlert }: {
3
3
  documento: string;
4
+ onAlert?: (parameters: {
5
+ title?: string;
6
+ message: string;
7
+ }) => void;
4
8
  }): React.JSX.Element | null;
5
9
  export default ConsultaSCR;
@@ -49,40 +49,39 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
49
49
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
50
  }
51
51
  };
52
- /* eslint-disable react-hooks/exhaustive-deps */
53
- /* eslint-disable @typescript-eslint/no-unused-vars */
54
52
  import ScrIcon from '../../assets/icones/scr';
55
53
  import { useGlobalData } from '../../contexts/globalDataContext';
56
54
  import useToggle from '../../hooks/useToggle';
57
55
  import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
58
56
  import styled from 'styled-components';
59
57
  import AddItemField from '../common/addItem';
58
+ import Button from '../common/button';
60
59
  import { ConsultasComplementaresContext } from '../consultasComplementares';
61
60
  import { Result, ResultContent } from '../interface/result';
62
61
  import StatusMessage from '../interface/statusMessage';
63
62
  import Section from '../section';
64
63
  import { RequestStatus, useFetch, useQuery } from '../webservice';
65
- import Button from '../common/button';
66
64
  var ResumosWrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: ", ";\n flex-direction: column;\n gap: 20px;\n"], ["\n display: ", ";\n flex-direction: column;\n gap: 20px;\n"])), function (_a) {
67
65
  var _b = _a.isOpen, isOpen = _b === void 0 ? true : _b;
68
66
  return (isOpen ? 'flex' : 'none');
69
67
  });
70
68
  function ConsultaSCR(_a) {
71
69
  var _this = this;
72
- var _b, _c;
73
- var documento = _a.documento;
70
+ var _b, _c, _d, _e;
71
+ var documento = _a.documento, onAlert = _a.onAlert;
74
72
  var consultasComplementaresContext = useContext(ConsultasComplementaresContext);
75
73
  var setData = useGlobalData().setData;
76
- var _d = useState(false), dataUpdated = _d[0], setDataUpdated = _d[1];
77
- var _e = consultasComplementaresContext !== null && consultasComplementaresContext !== void 0 ? consultasComplementaresContext : {}, consultasComplementares = _e.consultasComplementares, setConsultasComplementares = _e.setConsultasComplementares;
78
- var _f = useQuery("SELECT FROM 'SCR'.'CONSULTA'", { documento: documento }, !!((_b = consultasComplementares === null || consultasComplementares === void 0 ? void 0 : consultasComplementares.scr) === null || _b === void 0 ? void 0 : _b.consultaRealizada)), response = _f.response, isLoading = _f.isLoading, error = _f.error, loadingProgress = _f.loadingProgress;
74
+ var _f = useState(false), dataUpdated = _f[0], setDataUpdated = _f[1];
75
+ var _g = useState(false), alertShown = _g[0], setAlertShown = _g[1];
76
+ var _h = consultasComplementaresContext !== null && consultasComplementaresContext !== void 0 ? consultasComplementaresContext : {}, consultasComplementares = _h.consultasComplementares, setConsultasComplementares = _h.setConsultasComplementares;
77
+ var _j = useQuery("SELECT FROM 'SCR'.'CONSULTA'", { documento: documento }, !!((_b = consultasComplementares === null || consultasComplementares === void 0 ? void 0 : consultasComplementares.scr) === null || _b === void 0 ? void 0 : _b.consultaRealizada)), response = _j.response, isLoading = _j.isLoading, error = _j.error, loadingProgress = _j.loadingProgress;
79
78
  var fetch = useFetch("SELECT FROM 'SCR'.'PDF'").fetch;
80
79
  var isOpen = useToggle()[0];
81
80
  var scrRef = useRef(null);
82
81
  var consultaRealizada = useMemo(function () { var _a; return (_a = consultasComplementares === null || consultasComplementares === void 0 ? void 0 : consultasComplementares.scr) === null || _a === void 0 ? void 0 : _a.consultaRealizada; }, [(_c = consultasComplementares === null || consultasComplementares === void 0 ? void 0 : consultasComplementares.scr) === null || _c === void 0 ? void 0 : _c.consultaRealizada]);
83
- //const resumoDeCreditos = (scr && getResumoDeCreditos(scr)) || [];
84
82
  var scr = response === null || response === void 0 ? void 0 : response.document;
85
- var description = scr
83
+ var basicData = useMemo(function () { var _a; return (_a = scr === null || scr === void 0 ? void 0 : scr.response) === null || _a === void 0 ? void 0 : _a.basicData; }, [scr]);
84
+ var description = ((_e = (_d = scr === null || scr === void 0 ? void 0 : scr.response) === null || _d === void 0 ? void 0 : _d.basicData) === null || _e === void 0 ? void 0 : _e.length)
86
85
  ? 'Resumo do Cliente'
87
86
  : 'Não há informação disponível para este documento.';
88
87
  useEffect(function () {
@@ -104,6 +103,18 @@ function ConsultaSCR(_a) {
104
103
  setDataUpdated(true);
105
104
  }
106
105
  }, [response, consultaRealizada, dataUpdated, setData]);
106
+ useEffect(function () {
107
+ if (consultaRealizada &&
108
+ onAlert &&
109
+ !alertShown &&
110
+ (!Array.isArray(basicData) || basicData.length === 0)) {
111
+ onAlert({
112
+ title: 'Dados não encontrados',
113
+ message: 'Nenhuma informação foi retornada pela fonte de dados. No momento, não há informações disponíveis para exibição para este documento. Nossa equipe de suporte já está analisando o caso.'
114
+ });
115
+ setAlertShown(true);
116
+ }
117
+ }, [consultaRealizada, basicData, onAlert, alertShown]);
107
118
  return consultaRealizada ? (React.createElement(Section, { ref: scrRef, ctx: {
108
119
  type: isLoading
109
120
  ? RequestStatus.Loading
@@ -118,7 +129,9 @@ function ConsultaSCR(_a) {
118
129
  progress: loadingProgress
119
130
  }, title: "SCR", subtitle: "Resumo do Cliente", icon: ScrIcon, description: !error && (React.createElement(StatusMessage, { type: scr ? 'success' : 'default' }, description)), onSuccess: function () { return (React.createElement(React.Fragment, null,
120
131
  React.createElement(Result, null,
121
- React.createElement(ResultContent, { desktop: "repeat(4, 1fr)", tablet: "repeat(3, 1fr)", mobile: "1fr 1fr" }, scr === null || scr === void 0 ? void 0 : scr.response.basicData.map(function (data) { return (React.createElement(AddItemField, { name: data.label, value: data.value })); })),
132
+ React.createElement(ResultContent, { desktop: "repeat(4, 1fr)", tablet: "repeat(3, 1fr)", mobile: "1fr 1fr" }, Array.isArray(basicData)
133
+ ? basicData.map(function (data) { return (React.createElement(AddItemField, { key: data.label, name: data.label, value: data.value })); })
134
+ : null),
122
135
  React.createElement(ResultContent, { desktop: "repeat(4, 1fr)", tablet: "repeat(3, 1fr)", mobile: "1fr 1fr" },
123
136
  React.createElement(AddItemField, { name: "Total de cr\u00E9ditos a vencer", value: scr === null || scr === void 0 ? void 0 : scr.response.expiringTotal }),
124
137
  React.createElement(AddItemField, { name: "Total de cr\u00E9ditos vencidos", value: scr === null || scr === void 0 ? void 0 : scr.response.expiredTotal }),
@@ -7,6 +7,10 @@ type ConsultaSimplesProps = {
7
7
  onClose?: () => void;
8
8
  hasCredits?: HasCreditsType;
9
9
  onClickPrint: () => void;
10
+ onAlert?: (parameters: {
11
+ title?: string;
12
+ message: string;
13
+ }) => void;
10
14
  onClickConsultarProcessoJuridico?: (processoId: string) => void;
11
15
  initRefinBoaVista?: boolean;
12
16
  initRefinSerasa?: boolean;