@credithub/harlan-components 1.94.0 → 1.95.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.
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import PefinRefinBoaVistaIcon from '../../assets/icones/pefinRefinBoaVista';
13
13
  import { useGlobalData } from '../../contexts/globalDataContext';
14
- import { formatMoney } from '../../utils/number';
14
+ import { clearMoneyString, formatMoney } from '../../utils/number';
15
15
  import { addNoValueContent } from '../../utils/string';
16
16
  import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
17
17
  import AddItemField from '../common/addItem';
@@ -97,9 +97,7 @@ function RefinBoaVista(_a) {
97
97
  progress: loadingProgress
98
98
  }, title: "Restri\u00E7\u00F5es Pefin/Refin Boa Vista", subtitle: "Apontamentos e Restri\u00E7\u00F5es Financeiras e Comerciais", icon: PefinRefinBoaVistaIcon, description: !error && (React.createElement(StatusMessage, { type: pendencias.length === 0 ? 'default' : 'error' }, description)), variant: pendencias.length === 0 ? 'default' : 'error', onSuccess: function () { return (React.createElement(Result, null, pendencias.map(function (pendencia, i) { return (React.createElement(ResultContent, { key: i, desktop: "repeat(5, 1fr)", tablet: "repeat(3, 1fr)", mobile: "1fr 1fr" },
99
99
  React.createElement(AddItemField, { name: "Associado", value: pendencia.NomeAssociado }),
100
- React.createElement(AddItemField, { name: "Valor", value: pendencia.Valor && !isNaN(parseFloat(pendencia.Valor))
101
- ? "".concat(formatMoney(parseFloat(pendencia.Valor)))
102
- : 'Sem Valor' }),
100
+ React.createElement(AddItemField, { name: "Valor", value: formatMoney(clearMoneyString(pendencia.Valor)) }),
103
101
  React.createElement(AddItemField, { name: "Data da Inclus\u00E3o", value: pendencia.DataDeInclusao }),
104
102
  React.createElement(AddItemField, { name: "Data do Vencimento", value: pendencia.DataDoVencimento }),
105
103
  React.createElement(AddItemField, { name: "Entidade", value: pendencia.Entidade }),
@@ -51,6 +51,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
51
51
  };
52
52
  import ScrIcon from '../../assets/icones/scr';
53
53
  import { useGlobalData } from '../../contexts/globalDataContext';
54
+ import { useSafeQuery } from '../../hooks/useSafeQuery';
54
55
  import useToggle from '../../hooks/useToggle';
55
56
  import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
56
57
  import styled from 'styled-components';
@@ -61,7 +62,6 @@ import { Result, ResultContent } from '../interface/result';
61
62
  import StatusMessage from '../interface/statusMessage';
62
63
  import Section from '../section';
63
64
  import { RequestStatus, useFetch } from '../webservice';
64
- import { useSafeQuery } from '../../hooks/useSafeQuery';
65
65
  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) {
66
66
  var _b = _a.isOpen, isOpen = _b === void 0 ? true : _b;
67
67
  return (isOpen ? 'flex' : 'none');
@@ -142,26 +142,58 @@ function ConsultaSCR(_a) {
142
142
  React.createElement(AddItemField, { name: "Total de cr\u00E9ditos a vencer", value: scr === null || scr === void 0 ? void 0 : scr.response.expiringTotal }),
143
143
  React.createElement(AddItemField, { name: "Total de cr\u00E9ditos vencidos", value: scr === null || scr === void 0 ? void 0 : scr.response.expiredTotal }),
144
144
  React.createElement(Button, { style: { maxWidth: 'fit-content', minHeight: '0' }, onClick: function () { return __awaiter(_this, void 0, void 0, function () {
145
- var response, fileBlob, file, fileURL, pdfWindow;
145
+ var win, response_1, fileBlob, file, fileURL_1, a, err_1;
146
146
  return __generator(this, function (_a) {
147
147
  switch (_a.label) {
148
- case 0: return [4 /*yield*/, fetch({
149
- uuid: scr === null || scr === void 0 ? void 0 : scr.uuidQuery
150
- })];
148
+ case 0:
149
+ win = window.open('', '_blank');
150
+ _a.label = 1;
151
151
  case 1:
152
- response = _a.sent();
153
- if (!response) return [3 /*break*/, 3];
154
- return [4 /*yield*/, response.blob()];
152
+ _a.trys.push([1, 4, , 5]);
153
+ return [4 /*yield*/, fetch({
154
+ uuid: scr === null || scr === void 0 ? void 0 : scr.uuidQuery
155
+ })];
155
156
  case 2:
157
+ response_1 = _a.sent();
158
+ if (!response_1 ||
159
+ typeof response_1.blob !== 'function') {
160
+ throw new Error('Resposta inválida ao solicitar o PDF.');
161
+ }
162
+ return [4 /*yield*/, response_1.blob()];
163
+ case 3:
156
164
  fileBlob = _a.sent();
157
165
  file = new Blob([fileBlob], {
158
166
  type: 'application/pdf'
159
167
  });
160
- fileURL = URL.createObjectURL(file);
161
- pdfWindow = window.open();
162
- pdfWindow.location.href = fileURL;
163
- _a.label = 3;
164
- case 3: return [2 /*return*/];
168
+ fileURL_1 = URL.createObjectURL(file);
169
+ if (win && !win.closed) {
170
+ // Janela aberta com sucesso: navega para o PDF
171
+ win.location.href = fileURL_1;
172
+ // Revoga o objectURL após um tempo para evitar leak
173
+ setTimeout(function () { return URL.revokeObjectURL(fileURL_1); }, 10000);
174
+ }
175
+ else {
176
+ a = document.createElement('a');
177
+ a.href = fileURL_1;
178
+ a.download = 'relatorio-scr.pdf';
179
+ document.body.appendChild(a);
180
+ a.click();
181
+ a.remove();
182
+ URL.revokeObjectURL(fileURL_1);
183
+ }
184
+ return [3 /*break*/, 5];
185
+ case 4:
186
+ err_1 = _a.sent();
187
+ // Fecha a janela em branco se algo falhar após a abertura
188
+ if (win && !win.closed) {
189
+ try {
190
+ win.close();
191
+ }
192
+ catch (_b) { }
193
+ }
194
+ console.error('Erro ao baixar PDF:', err_1);
195
+ return [3 /*break*/, 5];
196
+ case 5: return [2 /*return*/];
165
197
  }
166
198
  });
167
199
  }); } }, "Baixar relat\u00F3rio detalhado"))),
@@ -3,3 +3,4 @@ export declare const phoneMask: (value?: string) => string;
3
3
  export declare function formatValue(valor?: number): string | undefined;
4
4
  export declare function sum(valores: number[]): number;
5
5
  export declare const extractIntegerFromText: (text: string | null) => number;
6
+ export declare const clearMoneyString: (value: string) => string;
@@ -24,3 +24,6 @@ export var extractIntegerFromText = function (text) {
24
24
  var parsed = parseInt(text, 10);
25
25
  return isNaN(parsed) ? 0 : parsed;
26
26
  };
27
+ export var clearMoneyString = function (value) {
28
+ return value.replace(/\./g, '').replace(/,/g, '.');
29
+ };