@credithub/harlan-components 1.109.4 → 1.110.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/common/printButton.js +9 -2
- package/dist/components/section.js +39 -1
- package/dist/components/webservice.js +1 -1
- package/dist/consultaSimples.js +40 -38
- package/dist/contexts/printReadinessContext.d.ts +29 -0
- package/dist/contexts/printReadinessContext.js +85 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/lib/cjs/index.js +174 -42
- package/lib/esm/index.js +174 -44
- package/package.json +1 -1
|
@@ -32,14 +32,21 @@ var SkipButton = styled.button(templateObject_8 || (templateObject_8 = __makeTem
|
|
|
32
32
|
});
|
|
33
33
|
var PrintButton = function (_a) {
|
|
34
34
|
var onClick = _a.onClick, _b = _a.isLoading, isLoading = _b === void 0 ? false : _b, _c = _a.tooltipMessage, tooltipMessage = _c === void 0 ? 'Carregando dados das consultas...' : _c;
|
|
35
|
-
var
|
|
35
|
+
var requestImmediatePrint = function () {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
if (typeof window !== 'undefined') {
|
|
38
|
+
(_b = (_a = window.__harlanPrintState) === null || _a === void 0 ? void 0 : _a.forceReady) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
39
|
+
}
|
|
40
|
+
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
41
|
+
};
|
|
42
|
+
var button = (React.createElement(BtnWrapper, { onClick: !isLoading ? requestImmediatePrint : undefined },
|
|
36
43
|
React.createElement(IconContainer, null, isLoading ? React.createElement(Spinner, null) : React.createElement(PrintIcon, null))));
|
|
37
44
|
if (isLoading) {
|
|
38
45
|
return (React.createElement(TooltipWrapper, null,
|
|
39
46
|
React.createElement(Tooltip, { placement: "left", content: React.createElement(TooltipContent, null,
|
|
40
47
|
React.createElement(TooltipTitle, null, "\uD83D\uDCC4 Preparando impress\u00E3o"),
|
|
41
48
|
React.createElement(TooltipMessage, null, tooltipMessage),
|
|
42
|
-
onClick && (React.createElement(SkipButton, { onClick:
|
|
49
|
+
onClick && (React.createElement(SkipButton, { onClick: requestImmediatePrint }, "Imprimir agora"))), icon: button })));
|
|
43
50
|
}
|
|
44
51
|
return button;
|
|
45
52
|
};
|
|
@@ -29,9 +29,10 @@ import BtnWrapper from '../assets/btn/btnWrapper';
|
|
|
29
29
|
import ChevronDown from '../assets/btn/chevronDown';
|
|
30
30
|
import ChevronUp from '../assets/btn/chevronUp';
|
|
31
31
|
import { usePrintMode } from '../contexts/printModeContext';
|
|
32
|
+
import { usePrintReadiness } from '../contexts/printReadinessContext';
|
|
32
33
|
import useToggle from '../hooks/useToggle';
|
|
33
34
|
import cn from 'classnames';
|
|
34
|
-
import React, { forwardRef, useCallback, useMemo } from 'react';
|
|
35
|
+
import React, { forwardRef, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
35
36
|
import styled from 'styled-components';
|
|
36
37
|
import Button from './common/button';
|
|
37
38
|
import { PrintSectionWrapper } from './common/printSectionWrapper';
|
|
@@ -39,6 +40,40 @@ import Header from './interface/header';
|
|
|
39
40
|
import StatusMessage from './interface/statusMessage';
|
|
40
41
|
import { RequestStatus } from './webservice';
|
|
41
42
|
var ButtonWrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n justify-content: center;\n width: 100%;\n height: 40%;\n max-height: 52px;\n max-width: 300px;\n margin: 0 auto;\n"], ["\n justify-content: center;\n width: 100%;\n height: 40%;\n max-height: 52px;\n max-width: 300px;\n margin: 0 auto;\n"])));
|
|
43
|
+
var sectionIdCounter = 0;
|
|
44
|
+
var nextSectionId = function () {
|
|
45
|
+
sectionIdCounter += 1;
|
|
46
|
+
return "section-".concat(sectionIdCounter);
|
|
47
|
+
};
|
|
48
|
+
var stringifyTitle = function (title) {
|
|
49
|
+
if (typeof title === 'string')
|
|
50
|
+
return title;
|
|
51
|
+
return undefined;
|
|
52
|
+
};
|
|
53
|
+
var useSectionPrintBlocker = function (ctx, title, enabled, registerBlocker, resolveBlocker) {
|
|
54
|
+
var blockerIdRef = useRef(nextSectionId());
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
if (!enabled)
|
|
57
|
+
return;
|
|
58
|
+
return function () {
|
|
59
|
+
resolveBlocker(blockerIdRef.current);
|
|
60
|
+
};
|
|
61
|
+
}, [enabled, resolveBlocker]);
|
|
62
|
+
useEffect(function () {
|
|
63
|
+
var _a;
|
|
64
|
+
if (!enabled || !ctx)
|
|
65
|
+
return;
|
|
66
|
+
var shouldBlock = ctx.type === RequestStatus.Loading ||
|
|
67
|
+
ctx.type === RequestStatus.Empty ||
|
|
68
|
+
((_a = ctx.activeRequests) !== null && _a !== void 0 ? _a : 0) > 0;
|
|
69
|
+
if (shouldBlock) {
|
|
70
|
+
registerBlocker(blockerIdRef.current, stringifyTitle(title));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
resolveBlocker(blockerIdRef.current);
|
|
74
|
+
}
|
|
75
|
+
}, [ctx, enabled, registerBlocker, resolveBlocker, title]);
|
|
76
|
+
};
|
|
42
77
|
var Section = forwardRef(function (_a, ref) {
|
|
43
78
|
var onSuccess = _a.onSuccess, _b = _a.isError, isError = _b === void 0 ? function (err, ctx) {
|
|
44
79
|
var shouldPush = (err === null || err === void 0 ? void 0 : err.push) === true;
|
|
@@ -55,6 +90,9 @@ var Section = forwardRef(function (_a, ref) {
|
|
|
55
90
|
} : _b, _c = _a.onLoading, onLoading = _c === void 0 ? function () { return React.createElement(React.Fragment, null); } : _c, ctx = _a.ctx, className = _a.className, _d = _a.hideHeader, hideHeader = _d === void 0 ? false : _d, _e = _a.minimized, minimized = _e === void 0 ? false : _e, headerProps = __rest(_a, ["onSuccess", "isError", "onLoading", "ctx", "className", "hideHeader", "minimized"]);
|
|
56
91
|
var _f = useToggle(!minimized), isOpen = _f[0], toggleOpen = _f[1];
|
|
57
92
|
var printMode = usePrintMode().printMode;
|
|
93
|
+
var printReadiness = usePrintReadiness();
|
|
94
|
+
var readinessEnabled = Boolean(printMode && printReadiness.enabled);
|
|
95
|
+
useSectionPrintBlocker(ctx, headerProps === null || headerProps === void 0 ? void 0 : headerProps.title, readinessEnabled, printReadiness.registerBlocker, printReadiness.resolveBlocker);
|
|
58
96
|
if (!ctx)
|
|
59
97
|
return null;
|
|
60
98
|
var type = ctx.type, progress = ctx.progress, warningMessage = ctx.warningMessage;
|
|
@@ -436,7 +436,7 @@ export function query(query) {
|
|
|
436
436
|
}
|
|
437
437
|
export var Queries = {
|
|
438
438
|
Finder: query("SELECT FROM 'FINDER'.'BILLING'"),
|
|
439
|
-
Protestos: query("SELECT FROM '
|
|
439
|
+
Protestos: query("SELECT FROM 'APICENPROTTESTE'.'CONSULTA'"),
|
|
440
440
|
CCF: query("SELECT FROM 'SEEKLOC'.'CCF'"),
|
|
441
441
|
ProcessosJuridicos: query("SELECT FROM 'PROCESSOSJURIDICOS'.'PROCESSOS'"),
|
|
442
442
|
Liminar: query("SELECT FROM 'LIMINAR'.'CONSULTA'"),
|
package/dist/consultaSimples.js
CHANGED
|
@@ -23,6 +23,7 @@ import { PostHogProvider } from './contexts/PostHogContext';
|
|
|
23
23
|
import { ErrorModalProvider } from './contexts/errorModalContext';
|
|
24
24
|
import { GlobalDataProvider } from './contexts/globalDataContext';
|
|
25
25
|
import { PrintModeProvider } from './contexts/printModeContext';
|
|
26
|
+
import { PrintReadinessProvider } from './contexts/printReadinessContext';
|
|
26
27
|
import useToggle from './hooks/useToggle';
|
|
27
28
|
import GlobalStyle from './styles/globalStyle';
|
|
28
29
|
import theme from './styles/theme';
|
|
@@ -89,44 +90,45 @@ var ConsultaSimples = function (_a) {
|
|
|
89
90
|
React.createElement(ErrorModalProvider, null,
|
|
90
91
|
React.createElement(PostHogProvider, { posthog: posthog },
|
|
91
92
|
React.createElement(PrintModeProvider, { printMode: printMode },
|
|
92
|
-
React.createElement(
|
|
93
|
-
React.createElement(
|
|
94
|
-
React.createElement(
|
|
95
|
-
React.createElement(
|
|
96
|
-
React.createElement(Queries.
|
|
97
|
-
React.createElement(
|
|
98
|
-
React.createElement(
|
|
99
|
-
React.createElement(Queries.
|
|
100
|
-
React.createElement(Queries.
|
|
101
|
-
React.createElement(
|
|
102
|
-
React.createElement(
|
|
103
|
-
React.createElement(
|
|
104
|
-
React.createElement(
|
|
105
|
-
React.createElement(
|
|
106
|
-
React.createElement(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
React.createElement(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
93
|
+
React.createElement(PrintReadinessProvider, { enabled: Boolean(printMode) },
|
|
94
|
+
React.createElement(ConsultasComplementaresProvider, { hasCredits: hasCredits, initRefinBoaVista: initRefinBoaVista, initRefinSerasa: initRefinSerasa, initVeiculos: initVeiculos },
|
|
95
|
+
React.createElement(WebServiceProvider, { credential: apiKey, defaultData: queryParams === null || queryParams === void 0 ? void 0 : queryParams.data, defaultUrlData: queryParams === null || queryParams === void 0 ? void 0 : queryParams.urlData },
|
|
96
|
+
React.createElement(HasCreditsVerification, { documento: documento, apiKey: apiKey },
|
|
97
|
+
React.createElement(Queries.Dominios.Request, { data: { documento: documento, cnpj: documento } },
|
|
98
|
+
React.createElement(Queries.Finder.Request, { data: { documento: documento } },
|
|
99
|
+
React.createElement(FinderDependency, { documento: documento },
|
|
100
|
+
React.createElement(Queries.ProcessosJuridicos.Request, { data: { documento: documento } },
|
|
101
|
+
React.createElement(Queries.Liminar.Request, { data: { documento: documento } },
|
|
102
|
+
React.createElement(Queries.LiminarCenprot.Request, { data: { documento: documento } },
|
|
103
|
+
React.createElement(EditalQueryWrapper, { hasDiamanteAccess: hasDiamanteAccess, documento: documento },
|
|
104
|
+
React.createElement(Wrapper, null,
|
|
105
|
+
React.createElement(GlobalDataProvider, null,
|
|
106
|
+
React.createElement(ConsultaSimplesSection, { documento: documento, onClose: onClose, onClickPrint: onClickPrint, isFinancial: isFinancial, ctime: ctimeProp, printMode: printMode, tags: tags },
|
|
107
|
+
React.createElement(ConsultaRfbProvider, { documento: documento },
|
|
108
|
+
React.createElement(Dossie, { documento: documento, printMode: printMode, isFinancial: isFinancial }),
|
|
109
|
+
React.createElement(Liminar, { isFinancial: isFinancial, hasCredits: hasCredits, tags: tags }),
|
|
110
|
+
React.createElement(Falencia, { documento: documento }),
|
|
111
|
+
React.createElement(Addresses, { apiKey: apiKey }),
|
|
112
|
+
React.createElement(Contacts, null),
|
|
113
|
+
React.createElement(Partners, { onClickQSA: onClickQSA })),
|
|
114
|
+
React.createElement(Dominios, null),
|
|
115
|
+
React.createElement(BankAccounts, null),
|
|
116
|
+
React.createElement(GraficosAnaliticosDependency, { documento: documento },
|
|
117
|
+
React.createElement(ChartSystem, { documento: documento }),
|
|
118
|
+
React.createElement(ConsultaSCR, { documento: documento }),
|
|
119
|
+
React.createElement(RefinBoaVista, { documento: documento }),
|
|
120
|
+
React.createElement(RefinSerasa, { documento: documento }),
|
|
121
|
+
React.createElement(ConsultaScore, { documento: documento }),
|
|
122
|
+
React.createElement(ConsultaScoreSerasa, { documento: documento }),
|
|
123
|
+
React.createElement(ConsultaImoveis, { documento: documento }),
|
|
124
|
+
React.createElement(Veiculos, { documento: documento })),
|
|
125
|
+
React.createElement(ProtestosSP, null),
|
|
126
|
+
React.createElement(Protestos, null),
|
|
127
|
+
React.createElement(Edital, { isFinancial: isFinancial, tags: tags }),
|
|
128
|
+
React.createElement(ProtestosPagosBaixados, { isFinancial: isFinancial }),
|
|
129
|
+
React.createElement(CCF, null),
|
|
130
|
+
React.createElement(DividasPublicas, null),
|
|
131
|
+
React.createElement(ProcessosJuridicos, { onClickConsultarProcessoJuridico: onClickConsultarProcessoJuridico })))))))))))))))))),
|
|
130
132
|
React.createElement(GlobalStyle, null)));
|
|
131
133
|
};
|
|
132
134
|
export default ConsultaSimples;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type BlockerMeta = {
|
|
3
|
+
id: string;
|
|
4
|
+
reason?: string;
|
|
5
|
+
createdAt: number;
|
|
6
|
+
};
|
|
7
|
+
type PrintState = {
|
|
8
|
+
pending: BlockerMeta[];
|
|
9
|
+
isReady: () => boolean;
|
|
10
|
+
forceReady: () => void;
|
|
11
|
+
};
|
|
12
|
+
type PrintReadinessContextValue = {
|
|
13
|
+
registerBlocker: (id: string, reason?: string) => void;
|
|
14
|
+
resolveBlocker: (id: string) => void;
|
|
15
|
+
forceReady: () => void;
|
|
16
|
+
isReady: boolean;
|
|
17
|
+
pending: BlockerMeta[];
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare const PrintReadinessProvider: React.FC<React.PropsWithChildren<{
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
}>>;
|
|
23
|
+
export declare const usePrintReadiness: () => PrintReadinessContextValue;
|
|
24
|
+
declare global {
|
|
25
|
+
interface Window {
|
|
26
|
+
__harlanPrintState?: PrintState;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
var noop = function () { };
|
|
3
|
+
var PrintReadinessContext = createContext({
|
|
4
|
+
registerBlocker: noop,
|
|
5
|
+
resolveBlocker: noop,
|
|
6
|
+
forceReady: noop,
|
|
7
|
+
isReady: true,
|
|
8
|
+
pending: [],
|
|
9
|
+
enabled: false
|
|
10
|
+
});
|
|
11
|
+
var PRINT_STATE_EVENT = 'harlan-print-state-change';
|
|
12
|
+
export var PrintReadinessProvider = function (_a) {
|
|
13
|
+
var enabled = _a.enabled, children = _a.children;
|
|
14
|
+
var _b = useState(function () { return new Map(); }), blockers = _b[0], setBlockers = _b[1];
|
|
15
|
+
var registerBlocker = useCallback(function (id, reason) {
|
|
16
|
+
if (!enabled || !id)
|
|
17
|
+
return;
|
|
18
|
+
setBlockers(function (prev) {
|
|
19
|
+
var _a;
|
|
20
|
+
var existing = prev.get(id);
|
|
21
|
+
if (existing && existing.reason === reason) {
|
|
22
|
+
return prev;
|
|
23
|
+
}
|
|
24
|
+
var next = new Map(prev);
|
|
25
|
+
next.set(id, {
|
|
26
|
+
id: id,
|
|
27
|
+
reason: reason,
|
|
28
|
+
createdAt: (_a = existing === null || existing === void 0 ? void 0 : existing.createdAt) !== null && _a !== void 0 ? _a : Date.now()
|
|
29
|
+
});
|
|
30
|
+
return next;
|
|
31
|
+
});
|
|
32
|
+
}, [enabled]);
|
|
33
|
+
var resolveBlocker = useCallback(function (id) {
|
|
34
|
+
if (!enabled || !id)
|
|
35
|
+
return;
|
|
36
|
+
setBlockers(function (prev) {
|
|
37
|
+
if (!prev.has(id))
|
|
38
|
+
return prev;
|
|
39
|
+
var next = new Map(prev);
|
|
40
|
+
next.delete(id);
|
|
41
|
+
return next;
|
|
42
|
+
});
|
|
43
|
+
}, [enabled]);
|
|
44
|
+
var forceReady = useCallback(function () {
|
|
45
|
+
if (!enabled)
|
|
46
|
+
return;
|
|
47
|
+
setBlockers(new Map());
|
|
48
|
+
}, [enabled]);
|
|
49
|
+
var pending = useMemo(function () { return Array.from(blockers.values()); }, [blockers]);
|
|
50
|
+
var isReady = pending.length === 0;
|
|
51
|
+
useEffect(function () {
|
|
52
|
+
if (typeof window === 'undefined')
|
|
53
|
+
return;
|
|
54
|
+
if (!enabled) {
|
|
55
|
+
delete window
|
|
56
|
+
.__harlanPrintState;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
window
|
|
60
|
+
.__harlanPrintState = {
|
|
61
|
+
pending: pending,
|
|
62
|
+
isReady: function () { return pending.length === 0; },
|
|
63
|
+
forceReady: forceReady
|
|
64
|
+
};
|
|
65
|
+
window.dispatchEvent(new CustomEvent(PRINT_STATE_EVENT, {
|
|
66
|
+
detail: {
|
|
67
|
+
pending: pending
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
return function () {
|
|
71
|
+
delete window
|
|
72
|
+
.__harlanPrintState;
|
|
73
|
+
};
|
|
74
|
+
}, [enabled, pending, forceReady]);
|
|
75
|
+
var value = useMemo(function () { return ({
|
|
76
|
+
registerBlocker: registerBlocker,
|
|
77
|
+
resolveBlocker: resolveBlocker,
|
|
78
|
+
forceReady: forceReady,
|
|
79
|
+
isReady: isReady,
|
|
80
|
+
pending: pending,
|
|
81
|
+
enabled: enabled
|
|
82
|
+
}); }, [registerBlocker, resolveBlocker, forceReady, isReady, pending, enabled]);
|
|
83
|
+
return (React.createElement(PrintReadinessContext.Provider, { value: value }, children));
|
|
84
|
+
};
|
|
85
|
+
export var usePrintReadiness = function () { return useContext(PrintReadinessContext); };
|
package/dist/index.d.ts
CHANGED
|
@@ -26,4 +26,5 @@ export { default as Veiculos } from './components/veiculos/veiculos';
|
|
|
26
26
|
export * from './components/webservice';
|
|
27
27
|
export { default as ConsultaSimples } from './consultaSimples';
|
|
28
28
|
export { PrintModeProvider, usePrintMode } from './contexts/printModeContext';
|
|
29
|
+
export { PrintReadinessProvider, usePrintReadiness } from './contexts/printReadinessContext';
|
|
29
30
|
export { default as usePrintWhenStable } from './hooks/usePrintWhenStable';
|
package/dist/index.js
CHANGED
|
@@ -26,4 +26,5 @@ export { default as Veiculos } from './components/veiculos/veiculos';
|
|
|
26
26
|
export * from './components/webservice';
|
|
27
27
|
export { default as ConsultaSimples } from './consultaSimples';
|
|
28
28
|
export { PrintModeProvider, usePrintMode } from './contexts/printModeContext';
|
|
29
|
+
export { PrintReadinessProvider, usePrintReadiness } from './contexts/printReadinessContext';
|
|
29
30
|
export { default as usePrintWhenStable } from './hooks/usePrintWhenStable';
|