@credithub/harlan-components 1.94.1 → 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.
- package/dist/components/scr/scr.js +45 -13
- package/lib/cjs/index.js +45 -13
- package/lib/esm/index.js +45 -13
- package/package.json +1 -1
|
@@ -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
|
|
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:
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
case 0:
|
|
149
|
+
win = window.open('', '_blank');
|
|
150
|
+
_a.label = 1;
|
|
151
151
|
case 1:
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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"))),
|