@credithub/harlan-components 1.76.0 → 1.77.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,10 +1,13 @@
1
1
  import React from 'react';
2
+ import { HasCreditsType } from '../consultasComplementares';
2
3
  interface LiminarProps {
3
4
  /**
4
5
  * Se verdadeiro, exibe ações exclusivas para instituições financeiras,
5
6
  * como o download de protestos ocultos.
6
7
  */
7
- isFinanceira?: boolean;
8
+ isFinancial?: boolean;
9
+ hasCredits?: HasCreditsType;
10
+ tags?: (string | RegExp)[];
8
11
  }
9
12
  declare const Liminar: React.FC<LiminarProps>;
10
13
  export default Liminar;
@@ -59,6 +59,9 @@ import Section from '../section';
59
59
  import { Queries, RequestStatus, useFetch } from '../webservice';
60
60
  import { TitleWithTooltip, TooltipContainer, TooltipText } from './liminarStyles';
61
61
  import useLiminarProtestosDoPassado from './useLiminarProtestosDoPassado';
62
+ import { hasOneOfTags } from '../../utils/tags';
63
+ import { SummaryButton } from '../dossie/summary/styles';
64
+ import { formatMoney } from '../../utils/number';
62
65
  /* ----------------------------------
63
66
  * Constantes
64
67
  * ---------------------------------*/
@@ -81,20 +84,24 @@ var businessTypes = [
81
84
  ];
82
85
  var Liminar = function (_a) {
83
86
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
84
- var _o = _a.isFinanceira, isFinanceira = _o === void 0 ? false : _o;
87
+ var _o = _a.isFinancial, isFinancial = _o === void 0 ? false : _o, hasCredits = _a.hasCredits, _p = _a.tags, tags = _p === void 0 ? [] : _p;
85
88
  var ctx = useContext(Queries.LiminarCenprot);
86
- var _p = useGlobalData(), globalData = _p.data, setData = _p.setData;
89
+ var _q = useGlobalData(), globalData = _q.data, setData = _q.setData;
87
90
  var fetchLiminarProtestosDoPassado = useLiminarProtestosDoPassado({
88
91
  documento: ((_c = (_b = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _b === void 0 ? void 0 : _b.carousel) === null || _c === void 0 ? void 0 : _c.document) || ''
89
92
  }).fetchLiminarProtestosDoPassado;
90
- var _q = useState(false), isLoadingLiminarProtestosDoPassado = _q[0], setIsLoadingLiminarProtestosDoPassado = _q[1];
93
+ var _r = useState(false), isLoadingLiminarProtestosDoPassado = _r[0], setIsLoadingLiminarProtestosDoPassado = _r[1];
91
94
  var processedRef = useRef(false);
92
95
  var dataHashRef = useRef('');
93
96
  var invertedIdsRef = useRef([]);
94
- var _r = useState(false), isTooltipVisible = _r[0], setTooltipVisible = _r[1];
95
- var _s = useState(false), isEmailModalOpen = _s[0], setIsEmailModalOpen = _s[1];
96
- var _t = useState(''), emailModalMessage = _t[0], setEmailModalMessage = _t[1];
97
- var _u = useFetch("SELECT FROM 'LIMINAR'.'SENDMAIL'"), sendIndiciosEmail = _u.fetch, isEmailSending = _u.isLoading, emailError = _u.error;
97
+ var _s = useState(false), isTooltipVisible = _s[0], setTooltipVisible = _s[1];
98
+ var _t = useState(false), isEmailModalOpen = _t[0], setIsEmailModalOpen = _t[1];
99
+ var _u = useState(''), emailModalMessage = _u[0], setEmailModalMessage = _u[1];
100
+ var liminarMailPrice = useMemo(function () {
101
+ var isDiamanteNew = hasOneOfTags(tags, ['diamante-new']);
102
+ return isDiamanteNew ? 0 : 50000;
103
+ }, [tags]);
104
+ var _v = useFetch("SELECT FROM 'LIMINAR'.'SENDMAIL'"), sendIndiciosEmail = _v.fetch, isEmailSending = _v.isLoading, emailError = _v.error;
98
105
  var hideTt = useRef();
99
106
  /*
100
107
  * Extrai e normaliza os tipos de documento presentes em ctx.document, retornando sempre um array de strings em minúsculo.
@@ -138,7 +145,7 @@ var Liminar = function (_a) {
138
145
  /*
139
146
  * Identifica as origens de liminares detectadas e verifica se existe liminar de protesto invertida
140
147
  */
141
- var _v = useMemo(function () {
148
+ var _w = useMemo(function () {
142
149
  var _a, _b;
143
150
  var labels = new Set();
144
151
  var indiciosApi = ((_a = ctx.document) === null || _a === void 0 ? void 0 : _a.indiciosDeLiminar) === true;
@@ -174,7 +181,7 @@ var Liminar = function (_a) {
174
181
  tiposDocumento,
175
182
  processosComAssuntoValido,
176
183
  (_f = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _f === void 0 ? void 0 : _f.indiciosDeLiminarProtestosDoPassado
177
- ]), origensDetectadas = _v.origensDetectadas, foundBusinessEntity = _v.foundBusinessEntity;
184
+ ]), origensDetectadas = _w.origensDetectadas, foundBusinessEntity = _w.foundBusinessEntity;
178
185
  useEffect(function () {
179
186
  var fetch = function () { return __awaiter(void 0, void 0, void 0, function () {
180
187
  var dossie, processosJuridicos, depsLoaded, newIds, hash, indiciosApi, indiciosDeLiminarProtestosDoPassado, protestosDoPassadoIds, _a, possuiIndiciosDeLiminarProtestosDoPassado, protestosIds, finalStatus;
@@ -209,7 +216,6 @@ var Liminar = function (_a) {
209
216
  return [4 /*yield*/, fetchLiminarProtestosDoPassado()];
210
217
  case 1:
211
218
  _a = _e.sent(), possuiIndiciosDeLiminarProtestosDoPassado = _a.possuiIndiciosDeLiminarProtestosDoPassado, protestosIds = _a.protestosDoPassadoIds;
212
- console.log('possuiIndiciosDeLiminarProtestosDoPassado', possuiIndiciosDeLiminarProtestosDoPassado);
213
219
  if (possuiIndiciosDeLiminarProtestosDoPassado) {
214
220
  origensDetectadas.push('Liminar no Cenprot');
215
221
  indiciosDeLiminarProtestosDoPassado =
@@ -275,27 +281,42 @@ var Liminar = function (_a) {
275
281
  ((_m = (_l = (_k = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _k === void 0 ? void 0 : _k.processosComLiminarIds) === null || _l === void 0 ? void 0 : _l.length) !== null && _m !== void 0 ? _m : 0) > 0));
276
282
  // Função para disparar o envio do e-mail e configurar a mensagem do modal
277
283
  var handleSendEmailIndicios = function (e) { return __awaiter(void 0, void 0, void 0, function () {
278
- var documento, ids;
279
- var _a, _b, _c;
280
- return __generator(this, function (_d) {
281
- switch (_d.label) {
282
- case 0:
283
- e.preventDefault();
284
- e.stopPropagation();
285
- documento = ((_b = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel) === null || _b === void 0 ? void 0 : _b.document) || '';
286
- ids = ((_c = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _c === void 0 ? void 0 : _c.protestosDoPassadoIds) || '';
287
- return [4 /*yield*/, sendIndiciosEmail({ documento: documento, nm_chave: ids })];
288
- case 1:
289
- _d.sent();
290
- if (emailError) {
291
- setEmailModalMessage("Falha ao enviar e-mail: ".concat(emailError.message));
292
- }
293
- else {
294
- setEmailModalMessage('Você deve ter recebido um e-mail nosso com os detalhes que encontramos sobre esse indício.');
295
- }
296
- setIsEmailModalOpen(true);
297
- return [2 /*return*/];
284
+ var callback;
285
+ return __generator(this, function (_a) {
286
+ e.preventDefault();
287
+ e.stopPropagation();
288
+ if (!hasOneOfTags(tags, ['diamante', 'diamante-new'])) {
289
+ setEmailModalMessage('Disponível apenas no plano Diamante.');
290
+ setIsEmailModalOpen(true);
291
+ return [2 /*return*/];
298
292
  }
293
+ callback = function () { return __awaiter(void 0, void 0, void 0, function () {
294
+ var documento, ids;
295
+ var _a, _b, _c;
296
+ return __generator(this, function (_d) {
297
+ switch (_d.label) {
298
+ case 0:
299
+ documento = ((_b = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel) === null || _b === void 0 ? void 0 : _b.document) || '';
300
+ ids = ((_c = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _c === void 0 ? void 0 : _c.protestosDoPassadoIds) || '';
301
+ return [4 /*yield*/, sendIndiciosEmail({ documento: documento, nm_chave: ids })];
302
+ case 1:
303
+ _d.sent();
304
+ if (emailError) {
305
+ setEmailModalMessage("Falha ao enviar e-mail: ".concat(emailError.message));
306
+ }
307
+ else {
308
+ setEmailModalMessage('Você deve ter recebido um e-mail nosso com os detalhes que encontramos sobre esse indício.');
309
+ }
310
+ setIsEmailModalOpen(true);
311
+ return [2 /*return*/];
312
+ }
313
+ });
314
+ }); };
315
+ if (hasCredits)
316
+ hasCredits(liminarMailPrice, callback);
317
+ else
318
+ callback();
319
+ return [2 /*return*/];
299
320
  });
300
321
  }); };
301
322
  if (!shouldRender)
@@ -329,16 +350,16 @@ var Liminar = function (_a) {
329
350
  description: (React.createElement(React.Fragment, null,
330
351
  React.createElement(StatusMessage, { type: variant }, msg),
331
352
  origensDetectadas.map(function (o) { return (React.createElement(StatusMessage, { key: o, type: variant }, o)); }))),
332
- actions: (React.createElement("div", { style: { textAlign: 'center' }, onClick: function (e) { return e.stopPropagation(); } }, isFinanceira &&
353
+ actions: (React.createElement("div", { style: { textAlign: 'center' }, onClick: function (e) { return e.stopPropagation(); } }, isFinancial &&
333
354
  ((_c = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _c === void 0 ? void 0 : _c.indiciosDeLiminarProtestosDoPassado) &&
334
- ((_d = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _d === void 0 ? void 0 : _d.protestosDoPassadoIds) && (React.createElement(Button, { onClick: handleSendEmailIndicios, disabled: isEmailSending }, "Baixar Protestos Ocultos"))))
355
+ ((_d = globalData === null || globalData === void 0 ? void 0 : globalData.liminar) === null || _d === void 0 ? void 0 : _d.protestosDoPassadoIds) && (React.createElement(SummaryButton, { onClick: handleSendEmailIndicios, disabled: isEmailSending, smallContent: liminarMailPrice && !isEmailSending ? formatMoney(liminarMailPrice / 1000) : '' }, "Baixar Protestos Ocultos"))))
335
356
  };
336
357
  }
337
358
  : undefined }),
338
359
  React.createElement(Modal, { isOpen: isEmailModalOpen, onClose: function () {
339
360
  setIsEmailModalOpen(false);
340
361
  setEmailModalMessage('');
341
- }, title: "Detalhes enviados por e-mail" },
362
+ }, title: "Envio de protestos ocultos por e-mail" },
342
363
  React.createElement("p", null, emailModalMessage),
343
364
  React.createElement("div", { style: { textAlign: 'center', marginTop: '16px' } },
344
365
  React.createElement(Button, { onClick: function () {
@@ -312,10 +312,11 @@ export function useFetch(query) {
312
312
  var abortController = useMemo(function () { return new AbortController(); }, []);
313
313
  var _a = useState(null), response = _a[0], setResponse = _a[1];
314
314
  var _b = useState(null), error = _b[0], setError = _b[1];
315
- var _c = useState(true), isLoading = _c[0], setIsLoading = _c[1];
315
+ var _c = useState(false), isLoading = _c[0], setIsLoading = _c[1];
316
316
  var fetch = useCallback(function (data) { return __awaiter(_this, void 0, void 0, function () {
317
317
  return __generator(this, function (_a) {
318
318
  setIsLoading(true);
319
+ setError(null);
319
320
  return [2 /*return*/, client
320
321
  .request(query, data, undefined, abortController.signal)
321
322
  .then(function (document) {
@@ -16,7 +16,8 @@ type ConsultaSimplesProps = {
16
16
  initRefinSerasa?: boolean;
17
17
  initVeiculos?: boolean;
18
18
  printMode?: boolean;
19
- isFinanceira?: boolean;
19
+ isFinancial?: boolean;
20
+ tags?: (string | RegExp)[];
20
21
  };
21
22
  declare const ConsultaSimples: React.FC<ConsultaSimplesProps>;
22
23
  export default ConsultaSimples;
@@ -13,11 +13,11 @@ import Dominios from './components/dominios/dominios';
13
13
  import ConsultaImoveis from './components/imoveis/imoveisService';
14
14
  import Liminar from './components/liminar/liminar';
15
15
  import ConsultaScore from './components/score/scoreService';
16
+ import ConsultaScoreSerasa from './components/scoreSerasa/scoreSerasa';
16
17
  import ConsultaSCR from './components/scr/scr';
17
18
  import { GlobalDataProvider } from './contexts/globalDataContext';
18
19
  import GlobalStyle from './styles/globalStyle';
19
20
  import theme from './styles/theme';
20
- import ConsultaScoreSerasa from './components/scoreSerasa/scoreSerasa';
21
21
  Chart.register.apply(Chart, registerables);
22
22
  var Wrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n font-family: 'Open Sans Condensed';\n display: flex;\n flex-direction: column;\n gap: 20px;\n margin-bottom: 20px;\n\n * {\n -webkit-print-color-adjust: exact !important;\n print-color-adjust: exact !important;\n }\n\n @media print {\n @page {\n size: auto;\n margin: 5mm;\n }\n }\n"], ["\n font-family: 'Open Sans Condensed';\n display: flex;\n flex-direction: column;\n gap: 20px;\n margin-bottom: 20px;\n\n * {\n -webkit-print-color-adjust: exact !important;\n print-color-adjust: exact !important;\n }\n\n @media print {\n @page {\n size: auto;\n margin: 5mm;\n }\n }\n"])));
23
23
  var FinderDependency = function (_a) {
@@ -27,7 +27,7 @@ var FinderDependency = function (_a) {
27
27
  React.createElement(Queries.Protestos.Request, { data: { documento: documento }, depends: [ctxFinder] }, children)));
28
28
  };
29
29
  var ConsultaSimples = function (_a) {
30
- var _documento = _a.documento, onClickConsultarProcessoJuridico = _a.onClickConsultarProcessoJuridico, onClickQSA = _a.onClickQSA, onClickPrint = _a.onClickPrint, apiKey = _a.apiKey, onClose = _a.onClose, hasCredits = _a.hasCredits, _b = _a.initRefinBoaVista, initRefinBoaVista = _b === void 0 ? false : _b, _c = _a.initRefinSerasa, initRefinSerasa = _c === void 0 ? false : _c, _d = _a.initVeiculos, initVeiculos = _d === void 0 ? false : _d, _e = _a.printMode, printMode = _e === void 0 ? false : _e, _f = _a.isFinanceira, isFinanceira = _f === void 0 ? false : _f;
30
+ var _documento = _a.documento, onClickConsultarProcessoJuridico = _a.onClickConsultarProcessoJuridico, onClickQSA = _a.onClickQSA, onClickPrint = _a.onClickPrint, apiKey = _a.apiKey, onClose = _a.onClose, hasCredits = _a.hasCredits, _b = _a.initRefinBoaVista, initRefinBoaVista = _b === void 0 ? false : _b, _c = _a.initRefinSerasa, initRefinSerasa = _c === void 0 ? false : _c, _d = _a.initVeiculos, initVeiculos = _d === void 0 ? false : _d, _e = _a.printMode, printMode = _e === void 0 ? false : _e, _f = _a.isFinancial, isFinancial = _f === void 0 ? false : _f, _g = _a.tags, tags = _g === void 0 ? [] : _g;
31
31
  var documento = _documento.replace(/\D+/g, '');
32
32
  return (React.createElement(ThemeProvider, { theme: theme },
33
33
  React.createElement(ConsultasComplementaresProvider, { hasCredits: hasCredits, initRefinBoaVista: initRefinBoaVista, initRefinSerasa: initRefinSerasa, initVeiculos: initVeiculos },
@@ -43,7 +43,7 @@ var ConsultaSimples = function (_a) {
43
43
  React.createElement(ConsultaSimplesSection, { documento: documento, onClose: onClose, onClickPrint: onClickPrint },
44
44
  React.createElement(ConsultaRfbProvider, { documento: documento },
45
45
  React.createElement(Dossie, { documento: documento, printMode: printMode }),
46
- React.createElement(Liminar, { isFinanceira: isFinanceira }),
46
+ React.createElement(Liminar, { isFinancial: isFinancial, hasCredits: hasCredits, tags: tags }),
47
47
  React.createElement(Addresses, { apiKey: apiKey }),
48
48
  React.createElement(Contacts, null),
49
49
  React.createElement(Partners, { onClickQSA: onClickQSA })),
@@ -0,0 +1,2 @@
1
+ export declare function hasOneOfTags(userTags: (string | RegExp)[], tagsToVerify: (string | RegExp)[]): boolean;
2
+ export declare function hasAllTags(userTags: (string | RegExp)[], tagsToCompare: (string | RegExp)[]): boolean;
@@ -0,0 +1,37 @@
1
+ function parseValuesArrayToLowerCase() {
2
+ var array = [];
3
+ for (var _i = 0; _i < arguments.length; _i++) {
4
+ array[_i] = arguments[_i];
5
+ }
6
+ return array.map(function (item) {
7
+ return typeof item === 'string' ? item.toLowerCase() : item;
8
+ });
9
+ }
10
+ // Função pura: verifica se um array contém um valor (igualdade simples)
11
+ function contains(array, value) {
12
+ return array.includes(value);
13
+ }
14
+ // Função pura: verifica se pelo menos uma tag está presente
15
+ export function hasOneOfTags(userTags, tagsToVerify) {
16
+ if (!userTags.length || !tagsToVerify.length)
17
+ return false;
18
+ var userTagsLower = parseValuesArrayToLowerCase.apply(void 0, userTags);
19
+ var tagsToVerifyLower = parseValuesArrayToLowerCase.apply(void 0, tagsToVerify);
20
+ return tagsToVerifyLower.some(function (tag) {
21
+ return tag instanceof RegExp
22
+ ? tag.test(userTags.join(','))
23
+ : contains(userTagsLower, tag);
24
+ });
25
+ }
26
+ // Função pura: verifica se todas as tags estão presentes
27
+ export function hasAllTags(userTags, tagsToCompare) {
28
+ if (!userTags.length || !tagsToCompare.length)
29
+ return false;
30
+ var userTagsLower = parseValuesArrayToLowerCase.apply(void 0, userTags);
31
+ var tagsToCompareLower = parseValuesArrayToLowerCase.apply(void 0, tagsToCompare);
32
+ return tagsToCompareLower.every(function (tag) {
33
+ return tag instanceof RegExp
34
+ ? tag.test(userTags.join(','))
35
+ : contains(userTagsLower, tag);
36
+ });
37
+ }