@controleonline/ui-common 1.2.80 → 1.2.81
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/AGENTS.md +8 -0
- package/package.json +9 -3
- package/src/api/fetch.js +7 -7
- package/src/react/components/AddImportModal.js +6 -2
- package/src/react/components/BackgroundRuntimeBridge.js +201 -215
- package/src/react/components/ConfirmModal.js +44 -9
- package/src/react/components/ConfirmModal.styles.js +55 -41
- package/src/react/components/CopyDeviceConfigModal.js +193 -0
- package/src/react/components/CopyDeviceConfigModal.styles.js +123 -0
- package/src/react/components/DefaultProvider.native.js +22 -0
- package/src/react/components/DefaultProvider.web.js +25 -1
- package/src/react/components/EntityLogBranch.js +482 -0
- package/src/react/components/EntityLogCards.js +369 -0
- package/src/react/components/EntityLogContent.js +113 -794
- package/src/react/components/LinkedOrderProductsTab.js +3 -3
- package/src/react/components/PrintService.js +130 -409
- package/src/react/components/RemoteCheckoutService.js +2 -2
- package/src/react/components/RuntimeBottomNavigationBar.js +141 -146
- package/src/react/components/RuntimeFooterMarqueeText.js +137 -0
- package/src/react/components/RuntimeInfoFooter.js +12 -15
- package/src/react/components/SystemErrorToast.js +49 -29
- package/src/react/components/SystemErrorToast.styles.js +43 -38
- package/src/react/components/UserAvatar.js +120 -28
- package/src/react/config/deviceConfigBootstrap.js +330 -304
- package/src/react/hooks/usePrintSpoolEffects.js +161 -0
- package/src/react/pages/DeviceDetailPage.js +6 -2882
- package/src/react/pages/Devices/detail/DeviceDetailAlertsCommandsSection.js +233 -0
- package/src/react/pages/Devices/detail/DeviceDetailHeader.js +138 -0
- package/src/react/pages/Devices/detail/DeviceDetailMovementSections.js +167 -0
- package/src/react/pages/Devices/detail/DeviceDetailOrdersPrintSection.js +216 -0
- package/src/react/pages/Devices/detail/DeviceDetailPaymentSection.js +40 -0
- package/src/react/pages/Devices/detail/DeviceDetailPdvConfigSection.js +390 -0
- package/src/react/pages/Devices/detail/DeviceDetailRenderers.js +135 -0
- package/src/react/pages/Devices/detail/DeviceDetailScreen.js +493 -0
- package/src/react/pages/Devices/detail/OptionButtonChip.js +65 -0
- package/src/react/pages/Devices/detail/deviceDetailConstants.js +36 -0
- package/src/react/pages/Devices/detail/deviceDetailHelpers.js +70 -0
- package/src/react/pages/Devices/detail/useDeviceDetailActions.js +483 -0
- package/src/react/pages/Devices/detail/useDeviceDetailCopyConfig.js +87 -0
- package/src/react/pages/Devices/detail/useDeviceDetailLoaders.js +327 -0
- package/src/react/pages/Devices/detail/useDeviceDetailSaves.js +429 -0
- package/src/react/pages/Devices/detail/useDeviceDetailStateA.js +484 -0
- package/src/react/pages/Devices/detail/useDeviceDetailStateB.js +71 -0
- package/src/react/pages/Devices/deviceTypes/index.js +2 -0
- package/src/react/pages/Devices/deviceTypes/pdv.js +11 -0
- package/src/react/pages/Imports.js +3 -2
- package/src/react/pages/IntegrationConfigFields.js +126 -0
- package/src/react/pages/IntegrationConfigPage.js +122 -591
- package/src/react/pages/IntegrationConfigPage.utils.js +95 -0
- package/src/react/print/usePrintButtonController.js +9 -1
- package/src/react/services/Getnet/Checkout.js +81 -0
- package/src/react/services/Getnet/Getnet.js +77 -0
- package/src/react/services/paymentGatewayExecution.js +20 -0
- package/src/react/utils/bottomNavigationToolbar.js +161 -0
- package/src/react/utils/commercialDocumentOrders.js +18 -6
- package/src/react/utils/copyDeviceConfigs.js +198 -0
- package/src/react/utils/fileUrl.js +43 -0
- package/src/react/utils/importStatus.js +19 -10
- package/src/react/utils/logSettings.js +7 -7
- package/src/react/utils/maintenanceSettings.js +16 -0
- package/src/react/utils/paymentDevices.js +6 -0
- package/src/react/utils/printManagedPrinter.js +45 -0
- package/src/react/utils/printRouting.js +63 -0
- package/src/react/utils/printSpoolUtils.js +119 -0
- package/src/react/utils/printerDevices.js +368 -368
- package/src/react/utils/runtimeFooter.js +10 -19
- package/src/react/utils/shopFranchises.js +186 -65
- package/src/react/utils/systemErrorMessage.js +71 -67
- package/src/store/device_config/customActions.js +119 -30
- package/src/tests/browser/manager/bottom-navigation-role-toolbar.spec.js +353 -0
- package/src/tests/browser/manager/device-detail-alias-save.spec.js +345 -0
- package/src/tests/browser/manager/device-detail-copy-config.spec.js +365 -0
- package/src/tests/browser/manager/runtime-footer-marquee.spec.js +262 -0
- package/src/tests/browser/manager/theme-confirm-toast.spec.js +236 -0
- package/src/tests/react/components/RuntimeFooterMarqueeText.test.js +171 -0
- package/src/tests/react/components/UserAvatar.test.js +6 -2
- package/src/tests/react/components/themeAwareModals.test.mjs +60 -0
- package/src/tests/react/config/deviceConfigBootstrap.test.js +104 -66
- package/src/tests/react/pages/deviceDetailDelete.test.js +78 -0
- package/src/tests/react/pages/receitaFederalIntegrationContract.test.mjs +48 -0
- package/src/tests/react/utils/bottomNavigationToolbar.test.js +222 -0
- package/src/tests/react/utils/copyDeviceConfigs.test.mjs +127 -0
- package/src/tests/react/utils/fileUrl.test.js +38 -0
- package/src/tests/react/utils/importStatus.test.js +26 -9
- package/src/tests/react/utils/passwordPolicy.test.js +27 -0
- package/src/tests/react/utils/printRouting.test.mjs +86 -0
- package/src/tests/react/utils/printSpoolUtils.test.mjs +52 -0
- package/src/tests/react/utils/runtimeFooter.test.js +7 -0
- package/src/tests/react/utils/shopFranchises.test.js +121 -115
- package/src/tests/react/utils/systemErrorMessage.test.js +32 -59
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
|
|
2
2
|
import {api} from '@controleonline/ui-common/src/api';
|
|
3
|
-
import {
|
|
4
|
-
decodeNetworkPrinterPayload,
|
|
5
|
-
printOnNetworkPrinter,
|
|
6
|
-
} from '@controleonline/ui-common/src/react/services/NetworkPrinterService';
|
|
7
|
-
import {
|
|
8
|
-
DEFAULT_NETWORK_PRINTER_PORT,
|
|
9
|
-
DEFAULT_NETWORK_PRINTER_CODE_PAGE,
|
|
10
|
-
DISPLAY_DEVICE_TYPE,
|
|
11
|
-
PDV_DEVICE_TYPE,
|
|
12
|
-
getManagedPrinterDevices,
|
|
13
|
-
getPrinterHost,
|
|
14
|
-
NETWORK_PRINTER_CODE_PAGE_CONFIG_KEY,
|
|
15
|
-
NETWORK_PRINTER_PORT_CONFIG_KEY,
|
|
16
|
-
normalizePrinterPort,
|
|
17
|
-
} from '@controleonline/ui-common/src/react/utils/printerDevices';
|
|
3
|
+
import {getManagedPrinterDevices} from '@controleonline/ui-common/src/react/utils/printerDevices';
|
|
18
4
|
import {isWebRuntimeDevice} from '@controleonline/ui-common/src/react/utils/deviceRuntime';
|
|
19
5
|
import {
|
|
20
6
|
isLocalCieloPrintCapableDeviceConfig,
|
|
@@ -29,33 +15,22 @@ import {
|
|
|
29
15
|
import {PRINT_JOB_TYPE_SPOOL} from '@controleonline/ui-common/src/react/print/jobs';
|
|
30
16
|
import {printOnLocalCielo} from '@controleonline/ui-common/src/react/print/providers/local';
|
|
31
17
|
import {executeRemotePrintRequest} from '@controleonline/ui-common/src/react/print/providers/remote';
|
|
18
|
+
import {resolveSpoolDeviceIdsForRuntime} from '@controleonline/ui-common/src/react/utils/printRouting';
|
|
19
|
+
import {
|
|
20
|
+
SPOOL_ACK_RETRY_DELAY_MS,
|
|
21
|
+
normalizeDeviceType,
|
|
22
|
+
resolveSpoolId as resolveSpoolIdPure,
|
|
23
|
+
fetchOpenSpoolsForDevices,
|
|
24
|
+
resolveRequestedTargetDeviceId,
|
|
25
|
+
resolveRequestedTargetDeviceTypeValue,
|
|
26
|
+
} from '@controleonline/ui-common/src/react/utils/printSpoolUtils';
|
|
27
|
+
import {printOnManagedNetworkPrinter} from '@controleonline/ui-common/src/react/utils/printManagedPrinter';
|
|
28
|
+
import {usePrintSpoolEffects} from '@controleonline/ui-common/src/react/hooks/usePrintSpoolEffects';
|
|
32
29
|
import {useStore} from '@store';
|
|
33
30
|
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const normalizeDeviceType = value => String(value || '').trim().toUpperCase();
|
|
39
|
-
|
|
40
|
-
const extractCollectionMembers = data => {
|
|
41
|
-
if (Array.isArray(data)) {
|
|
42
|
-
return data;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (Array.isArray(data?.member)) {
|
|
46
|
-
return data.member;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (Array.isArray(data?.['hydra:member'])) {
|
|
50
|
-
return data['hydra:member'];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return [];
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const PrintService = () => {
|
|
57
|
-
const peopleStore = useStore('people');
|
|
58
|
-
const peopleGetters = peopleStore.getters;
|
|
31
|
+
const PrintService = () => {
|
|
32
|
+
const peopleStore = useStore('people');
|
|
33
|
+
const peopleGetters = peopleStore.getters;
|
|
59
34
|
const printStore = useStore('print');
|
|
60
35
|
const printGetters = printStore.getters;
|
|
61
36
|
const printActions = printStore.actions;
|
|
@@ -65,13 +40,11 @@ const PrintService = () => {
|
|
|
65
40
|
const deviceConfigGetters = deviceConfigStore.getters;
|
|
66
41
|
const websocketStore = useStore('websocket');
|
|
67
42
|
const websocketGetters = websocketStore.getters;
|
|
68
|
-
|
|
69
43
|
const {item: storagedDevice} = deviceGetters;
|
|
70
44
|
const {reload, print, items: spool, message, messages} = printGetters;
|
|
71
|
-
const {currentCompany} = peopleGetters;
|
|
72
|
-
const {item: runtimeDeviceConfig, items: companyDeviceConfigs = []} = deviceConfigGetters;
|
|
73
|
-
const {summary: websocketSummary} = websocketGetters;
|
|
74
|
-
|
|
45
|
+
const {currentCompany} = peopleGetters;
|
|
46
|
+
const {item: runtimeDeviceConfig, items: companyDeviceConfigs = []} = deviceConfigGetters;
|
|
47
|
+
const {summary: websocketSummary} = websocketGetters;
|
|
75
48
|
const isPrintingRef = useRef(false);
|
|
76
49
|
const spoolRef = useRef([]);
|
|
77
50
|
// Once the device prints locally, only the backend ack may remain pending.
|
|
@@ -79,31 +52,13 @@ const PrintService = () => {
|
|
|
79
52
|
const connectedPollTimeoutRef = useRef(null);
|
|
80
53
|
const ackRetryTimeoutRef = useRef(null);
|
|
81
54
|
const [lastPrintCommandAt, setLastPrintCommandAt] = useState(null);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}, [spool]);
|
|
90
|
-
|
|
91
|
-
const resolveSpoolId = useCallback(value => {
|
|
92
|
-
if (!value) return null;
|
|
93
|
-
if (typeof value === 'number') return value;
|
|
94
|
-
if (typeof value === 'string') {
|
|
95
|
-
const numericValue = value.replace(/\D/g, '');
|
|
96
|
-
return numericValue ? Number(numericValue) : null;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return (
|
|
100
|
-
resolveSpoolId(value?.id) ||
|
|
101
|
-
resolveSpoolId(value?.spoolId) ||
|
|
102
|
-
resolveSpoolId(value?.spool) ||
|
|
103
|
-
resolveSpoolId(value?.['@id'])
|
|
104
|
-
);
|
|
105
|
-
}, []);
|
|
106
|
-
|
|
55
|
+
const markPrintCommand = useCallback(() => {
|
|
56
|
+
setLastPrintCommandAt(Date.now());
|
|
57
|
+
}, []);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
spoolRef.current = Array.isArray(spool) ? spool : [];
|
|
60
|
+
}, [spool]);
|
|
61
|
+
const resolveSpoolId = resolveSpoolIdPure;
|
|
107
62
|
const resolveTargetDevice = useCallback(
|
|
108
63
|
printJob =>
|
|
109
64
|
normalizeDeviceId(
|
|
@@ -111,26 +66,22 @@ const PrintService = () => {
|
|
|
111
66
|
),
|
|
112
67
|
[storagedDevice?.id],
|
|
113
68
|
);
|
|
114
|
-
|
|
115
69
|
const clearAckRetry = useCallback(() => {
|
|
116
70
|
if (ackRetryTimeoutRef.current) {
|
|
117
71
|
clearTimeout(ackRetryTimeoutRef.current);
|
|
118
72
|
ackRetryTimeoutRef.current = null;
|
|
119
73
|
}
|
|
120
74
|
}, []);
|
|
121
|
-
|
|
122
75
|
const scheduleAckRetry = useCallback(() => {
|
|
123
76
|
clearAckRetry();
|
|
124
77
|
ackRetryTimeoutRef.current = setTimeout(() => {
|
|
125
78
|
printActions.setReload(true);
|
|
126
79
|
}, SPOOL_ACK_RETRY_DELAY_MS);
|
|
127
80
|
}, [clearAckRetry, printActions]);
|
|
128
|
-
|
|
129
81
|
const hasPendingSpoolAck = useCallback(
|
|
130
82
|
spoolId => hasTrackedSpool(pendingAckSpoolsRef.current, spoolId),
|
|
131
83
|
[],
|
|
132
84
|
);
|
|
133
|
-
|
|
134
85
|
const rememberPendingSpoolAck = useCallback(
|
|
135
86
|
spoolId => {
|
|
136
87
|
rememberTrackedSpool(pendingAckSpoolsRef.current, spoolId, {
|
|
@@ -139,7 +90,6 @@ const PrintService = () => {
|
|
|
139
90
|
},
|
|
140
91
|
[],
|
|
141
92
|
);
|
|
142
|
-
|
|
143
93
|
const forgetPendingSpoolAck = useCallback(
|
|
144
94
|
spoolId => {
|
|
145
95
|
forgetTrackedSpool(pendingAckSpoolsRef.current, spoolId);
|
|
@@ -149,7 +99,6 @@ const PrintService = () => {
|
|
|
149
99
|
},
|
|
150
100
|
[clearAckRetry],
|
|
151
101
|
);
|
|
152
|
-
|
|
153
102
|
const syncPendingSpoolAcks = useCallback(
|
|
154
103
|
openSpools => {
|
|
155
104
|
const openSpoolIds = (Array.isArray(openSpools) ? openSpools : []).map(
|
|
@@ -162,7 +111,6 @@ const PrintService = () => {
|
|
|
162
111
|
},
|
|
163
112
|
[clearAckRetry, resolveSpoolId],
|
|
164
113
|
);
|
|
165
|
-
|
|
166
114
|
const finalizeSpoolAck = useCallback(
|
|
167
115
|
async spoolId => {
|
|
168
116
|
if (!spoolId) {
|
|
@@ -175,112 +123,64 @@ const PrintService = () => {
|
|
|
175
123
|
},
|
|
176
124
|
[forgetPendingSpoolAck, printActions],
|
|
177
125
|
);
|
|
178
|
-
|
|
179
126
|
const runtimeDeviceType = useMemo(
|
|
180
127
|
() =>
|
|
181
128
|
normalizeDeviceType(
|
|
182
129
|
runtimeDeviceConfig?.type ||
|
|
183
|
-
runtimeDeviceConfig?.device?.type ||
|
|
184
|
-
storagedDevice?.type,
|
|
130
|
+
runtimeDeviceConfig?.device?.type ||
|
|
131
|
+
storagedDevice?.type,
|
|
185
132
|
),
|
|
186
133
|
[runtimeDeviceConfig?.device?.type, runtimeDeviceConfig?.type, storagedDevice?.type],
|
|
187
134
|
);
|
|
188
|
-
|
|
189
135
|
const canUseLocalCieloPrint = useMemo(
|
|
190
136
|
() => isLocalCieloPrintCapableDeviceConfig(runtimeDeviceConfig),
|
|
191
137
|
[runtimeDeviceConfig],
|
|
192
138
|
);
|
|
193
|
-
|
|
194
139
|
const managedPrinters = useMemo(
|
|
195
140
|
() =>
|
|
196
141
|
getManagedPrinterDevices({
|
|
197
142
|
deviceConfigs: companyDeviceConfigs,
|
|
198
143
|
companyId: currentCompany?.id,
|
|
199
|
-
managerDeviceId: storagedDevice?.id,
|
|
200
|
-
}),
|
|
201
|
-
[companyDeviceConfigs, currentCompany?.id, storagedDevice?.id],
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
...(canUseLocalCieloPrint ? [deviceId] : []),
|
|
236
|
-
...managedPrinterDeviceIds,
|
|
237
|
-
].filter(Boolean),
|
|
238
|
-
),
|
|
144
|
+
managerDeviceId: storagedDevice?.id,
|
|
145
|
+
}),
|
|
146
|
+
[companyDeviceConfigs, currentCompany?.id, storagedDevice?.id],
|
|
147
|
+
);
|
|
148
|
+
const isWebDevice = useMemo(
|
|
149
|
+
() => isWebRuntimeDevice(storagedDevice),
|
|
150
|
+
[storagedDevice],
|
|
151
|
+
);
|
|
152
|
+
const spoolDeviceIds = useMemo(
|
|
153
|
+
() =>
|
|
154
|
+
resolveSpoolDeviceIdsForRuntime({
|
|
155
|
+
runtimeDeviceId: storagedDevice?.id,
|
|
156
|
+
runtimeDeviceType,
|
|
157
|
+
isWebRuntime: isWebDevice,
|
|
158
|
+
managedPrinters,
|
|
159
|
+
includeLocalDevice: canUseLocalCieloPrint,
|
|
160
|
+
}),
|
|
161
|
+
[
|
|
162
|
+
canUseLocalCieloPrint,
|
|
163
|
+
isWebDevice,
|
|
164
|
+
managedPrinters,
|
|
165
|
+
runtimeDeviceType,
|
|
166
|
+
storagedDevice?.id,
|
|
167
|
+
],
|
|
168
|
+
);
|
|
169
|
+
const shouldHandleSpool = useMemo(
|
|
170
|
+
() => spoolDeviceIds.length > 0,
|
|
171
|
+
[spoolDeviceIds],
|
|
172
|
+
);
|
|
173
|
+
const resolveManagedPrinter = useCallback(
|
|
174
|
+
printJob => {
|
|
175
|
+
const targetDeviceId = resolveTargetDevice(printJob);
|
|
176
|
+
return (
|
|
177
|
+
managedPrinters.find(
|
|
178
|
+
printer => normalizeDeviceId(printer?.device) === targetDeviceId,
|
|
179
|
+
) || null
|
|
239
180
|
);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return managedPrinterDeviceIds;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return [];
|
|
247
|
-
}, [
|
|
248
|
-
isWebDevice,
|
|
249
|
-
canUseLocalCieloPrint,
|
|
250
|
-
managedPrinterDeviceIds,
|
|
251
|
-
runtimeDeviceType,
|
|
252
|
-
storagedDevice?.id,
|
|
253
|
-
]);
|
|
254
|
-
|
|
255
|
-
const shouldHandleSpool = useMemo(
|
|
256
|
-
() => spoolDeviceIds.length > 0,
|
|
257
|
-
[spoolDeviceIds],
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
const resolveManagedPrinter = useCallback(
|
|
261
|
-
printJob => {
|
|
262
|
-
const targetDeviceId = resolveTargetDevice(printJob);
|
|
263
|
-
return (
|
|
264
|
-
managedPrinters.find(
|
|
265
|
-
printer => normalizeDeviceId(printer?.device) === targetDeviceId,
|
|
266
|
-
) || null
|
|
267
|
-
);
|
|
268
|
-
},
|
|
269
|
-
[managedPrinters, resolveTargetDevice],
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
useEffect(() => {
|
|
273
|
-
if (!currentCompany?.id) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
printActions
|
|
278
|
-
.ensurePrintDependenciesLoaded({
|
|
279
|
-
companyId: currentCompany.id,
|
|
280
|
-
})
|
|
281
|
-
.catch(() => {});
|
|
282
|
-
}, [currentCompany?.id, printActions]);
|
|
283
|
-
|
|
181
|
+
},
|
|
182
|
+
[managedPrinters, resolveTargetDevice],
|
|
183
|
+
);
|
|
284
184
|
const loadOpenSpools = useCallback(async () => {
|
|
285
185
|
if (!shouldHandleSpool) {
|
|
286
186
|
pendingAckSpoolsRef.current.clear();
|
|
@@ -289,7 +189,6 @@ const PrintService = () => {
|
|
|
289
189
|
printActions.setReload(false);
|
|
290
190
|
return [];
|
|
291
191
|
}
|
|
292
|
-
|
|
293
192
|
const deviceIds = Array.from(new Set(spoolDeviceIds.filter(Boolean)));
|
|
294
193
|
|
|
295
194
|
if (deviceIds.length === 0) {
|
|
@@ -299,41 +198,9 @@ const PrintService = () => {
|
|
|
299
198
|
printActions.setReload(false);
|
|
300
199
|
return [];
|
|
301
200
|
}
|
|
302
|
-
|
|
303
|
-
try {
|
|
304
|
-
const spoolCollections = await Promise.all(
|
|
305
|
-
deviceIds.map(deviceId =>
|
|
306
|
-
api
|
|
307
|
-
.fetch('spools', {
|
|
308
|
-
params: {
|
|
309
|
-
'device.device': deviceId,
|
|
310
|
-
'status.realStatus': 'open',
|
|
311
|
-
},
|
|
312
|
-
})
|
|
313
|
-
.then(extractCollectionMembers)
|
|
314
|
-
.catch(() => []),
|
|
315
|
-
),
|
|
316
|
-
);
|
|
317
|
-
|
|
318
|
-
const mergedSpools = [];
|
|
319
|
-
const spoolIds = new Set();
|
|
320
|
-
|
|
321
|
-
spoolCollections.flat().forEach(item => {
|
|
322
|
-
const spoolId = resolveSpoolId(item);
|
|
323
|
-
const spoolKey = spoolId ? String(spoolId) : JSON.stringify(item);
|
|
324
|
-
|
|
325
|
-
if (!spoolIds.has(spoolKey)) {
|
|
326
|
-
spoolIds.add(spoolKey);
|
|
327
|
-
mergedSpools.push(item);
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
mergedSpools.sort((left, right) => {
|
|
332
|
-
const leftId = resolveSpoolId(left) || 0;
|
|
333
|
-
const rightId = resolveSpoolId(right) || 0;
|
|
334
|
-
return leftId - rightId;
|
|
335
|
-
});
|
|
336
201
|
|
|
202
|
+
try {
|
|
203
|
+
const mergedSpools = await fetchOpenSpoolsForDevices(api, deviceIds);
|
|
337
204
|
syncPendingSpoolAcks(mergedSpools);
|
|
338
205
|
printActions.setItems(mergedSpools);
|
|
339
206
|
return mergedSpools;
|
|
@@ -343,77 +210,52 @@ const PrintService = () => {
|
|
|
343
210
|
}, [
|
|
344
211
|
clearAckRetry,
|
|
345
212
|
printActions,
|
|
346
|
-
resolveSpoolId,
|
|
347
213
|
shouldHandleSpool,
|
|
348
214
|
spoolDeviceIds,
|
|
349
215
|
syncPendingSpoolAcks,
|
|
350
216
|
]);
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
nextQueue
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
);
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
[printActions, resolveSpoolId],
|
|
369
|
-
);
|
|
370
|
-
|
|
217
|
+
const removeSpoolFromQueue = useCallback(
|
|
218
|
+
spoolId => {
|
|
219
|
+
if (!spoolId) {
|
|
220
|
+
const nextQueue = [...(spoolRef.current || [])];
|
|
221
|
+
nextQueue.shift();
|
|
222
|
+
spoolRef.current = nextQueue;
|
|
223
|
+
printActions.setItems(nextQueue);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const nextQueue = (spoolRef.current || []).filter(
|
|
227
|
+
item => resolveSpoolId(item) !== spoolId,
|
|
228
|
+
);
|
|
229
|
+
spoolRef.current = nextQueue;
|
|
230
|
+
printActions.setItems(nextQueue);
|
|
231
|
+
},
|
|
232
|
+
[printActions, resolveSpoolId],
|
|
233
|
+
);
|
|
371
234
|
const getSpoolData = useCallback(
|
|
372
235
|
async printJob => {
|
|
373
236
|
const spoolId = resolveSpoolId(printJob);
|
|
374
237
|
if (!spoolId) {
|
|
375
238
|
return printJob || null;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
try {
|
|
379
|
-
return await printActions.get(spoolId);
|
|
380
|
-
} catch (e) {
|
|
381
|
-
return printJob || null;
|
|
382
|
-
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
return await printActions.get(spoolId);
|
|
243
|
+
} catch (e) {
|
|
244
|
+
return printJob || null;
|
|
245
|
+
}
|
|
383
246
|
},
|
|
384
247
|
[printActions, resolveSpoolId],
|
|
385
248
|
);
|
|
386
|
-
|
|
387
249
|
const printManagedSpool = useCallback(
|
|
388
250
|
async (printJob, spoolData) => {
|
|
389
251
|
const managedPrinter = resolveManagedPrinter(spoolData || printJob);
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
const printerHost = getPrinterHost(managedPrinter);
|
|
395
|
-
const printerPort = normalizePrinterPort(
|
|
396
|
-
managedPrinter?.configs?.[NETWORK_PRINTER_PORT_CONFIG_KEY] ||
|
|
397
|
-
DEFAULT_NETWORK_PRINTER_PORT,
|
|
398
|
-
);
|
|
399
|
-
const printerCodePage =
|
|
400
|
-
managedPrinter?.configs?.[NETWORK_PRINTER_CODE_PAGE_CONFIG_KEY] ||
|
|
401
|
-
DEFAULT_NETWORK_PRINTER_CODE_PAGE;
|
|
402
|
-
|
|
403
|
-
await printOnNetworkPrinter({
|
|
404
|
-
host: printerHost,
|
|
405
|
-
port: printerPort,
|
|
406
|
-
codePage: printerCodePage,
|
|
407
|
-
payload: decodeNetworkPrinterPayload(spoolData?.file?.content, {
|
|
408
|
-
codePage: printerCodePage,
|
|
409
|
-
}),
|
|
252
|
+
return printOnManagedNetworkPrinter({
|
|
253
|
+
managedPrinter,
|
|
254
|
+
content: spoolData?.file?.content,
|
|
410
255
|
});
|
|
411
|
-
|
|
412
|
-
return true;
|
|
413
256
|
},
|
|
414
257
|
[resolveManagedPrinter],
|
|
415
258
|
);
|
|
416
|
-
|
|
417
259
|
const processResolvedSpool = useCallback(
|
|
418
260
|
async ({printJob, spoolData, removeFromQueue = false}) => {
|
|
419
261
|
const spoolId = resolveSpoolId(spoolData || printJob);
|
|
@@ -441,7 +283,6 @@ const PrintService = () => {
|
|
|
441
283
|
}
|
|
442
284
|
return {spoolId, printed: false};
|
|
443
285
|
}
|
|
444
|
-
|
|
445
286
|
const managedPrinterPrinted = await printManagedSpool(printJob, spoolData);
|
|
446
287
|
|
|
447
288
|
if (!managedPrinterPrinted) {
|
|
@@ -473,7 +314,6 @@ const PrintService = () => {
|
|
|
473
314
|
if (removeFromQueue) {
|
|
474
315
|
removeSpoolFromQueue(spoolId);
|
|
475
316
|
}
|
|
476
|
-
|
|
477
317
|
return {spoolId, printed: true};
|
|
478
318
|
},
|
|
479
319
|
[
|
|
@@ -487,40 +327,24 @@ const PrintService = () => {
|
|
|
487
327
|
scheduleAckRetry,
|
|
488
328
|
],
|
|
489
329
|
);
|
|
490
|
-
|
|
491
330
|
const resolveRequestedTargetDevice = useCallback(
|
|
492
|
-
printJob =>
|
|
493
|
-
normalizeDeviceId(
|
|
494
|
-
printJob?.targetPrinterDevice ||
|
|
495
|
-
printJob?.device?.device ||
|
|
496
|
-
printJob?.device ||
|
|
497
|
-
storagedDevice?.id,
|
|
498
|
-
),
|
|
331
|
+
printJob => resolveRequestedTargetDeviceId(printJob, storagedDevice?.id),
|
|
499
332
|
[storagedDevice?.id],
|
|
500
333
|
);
|
|
501
|
-
|
|
502
334
|
const resolveRequestedTargetDeviceType = useCallback(
|
|
503
|
-
printJob =>
|
|
504
|
-
|
|
505
|
-
printJob?.targetPrinterType ||
|
|
506
|
-
printJob?.deviceType ||
|
|
507
|
-
printJob?.type ||
|
|
508
|
-
storagedDevice?.type,
|
|
509
|
-
),
|
|
510
|
-
[storagedDevice?.type],
|
|
335
|
+
printJob => resolveRequestedTargetDeviceTypeValue(printJob),
|
|
336
|
+
[],
|
|
511
337
|
);
|
|
512
|
-
|
|
513
338
|
const goPrint = useCallback(
|
|
514
339
|
async printJob => {
|
|
515
340
|
if (isPrintingRef.current) {
|
|
516
341
|
return;
|
|
517
342
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
}
|
|
343
|
+
const spoolId = resolveSpoolId(printJob);
|
|
344
|
+
if (!spoolId) {
|
|
345
|
+
removeSpoolFromQueue(null);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
524
348
|
|
|
525
349
|
isPrintingRef.current = true;
|
|
526
350
|
|
|
@@ -535,10 +359,10 @@ const PrintService = () => {
|
|
|
535
359
|
printActions.setError(
|
|
536
360
|
e?.message || global.t?.t('orders', 'message', 'printProcessingError'),
|
|
537
361
|
);
|
|
538
|
-
removeSpoolFromQueue(spoolId);
|
|
539
|
-
} finally {
|
|
540
|
-
isPrintingRef.current = false;
|
|
541
|
-
}
|
|
362
|
+
removeSpoolFromQueue(spoolId);
|
|
363
|
+
} finally {
|
|
364
|
+
isPrintingRef.current = false;
|
|
365
|
+
}
|
|
542
366
|
},
|
|
543
367
|
[
|
|
544
368
|
getSpoolData,
|
|
@@ -548,7 +372,6 @@ const PrintService = () => {
|
|
|
548
372
|
resolveSpoolId,
|
|
549
373
|
],
|
|
550
374
|
);
|
|
551
|
-
|
|
552
375
|
const executePrintRequest = useCallback(
|
|
553
376
|
async printJob => {
|
|
554
377
|
const requestKey = String(printJob?.requestKey || '').trim();
|
|
@@ -586,7 +409,6 @@ const PrintService = () => {
|
|
|
586
409
|
});
|
|
587
410
|
return;
|
|
588
411
|
}
|
|
589
|
-
|
|
590
412
|
const targetDeviceId = resolveRequestedTargetDevice(printJob);
|
|
591
413
|
const targetDeviceType = resolveRequestedTargetDeviceType(printJob);
|
|
592
414
|
|
|
@@ -650,129 +472,28 @@ const PrintService = () => {
|
|
|
650
472
|
spoolDeviceIds,
|
|
651
473
|
],
|
|
652
474
|
);
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
if (shouldHandleSpool) {
|
|
656
|
-
printActions.setReload(true);
|
|
657
|
-
return;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
printActions.setItems([]);
|
|
661
|
-
printActions.setReload(false);
|
|
662
|
-
}, [printActions, shouldHandleSpool]);
|
|
663
|
-
|
|
664
|
-
useEffect(() => {
|
|
665
|
-
if (!reload) {
|
|
666
|
-
return;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
loadOpenSpools();
|
|
670
|
-
}, [loadOpenSpools, reload]);
|
|
671
|
-
|
|
672
|
-
useEffect(() => {
|
|
673
|
-
if (!shouldHandleSpool || websocketSummary?.connected === true) {
|
|
674
|
-
return;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
printActions.setReload(true);
|
|
678
|
-
const intervalId = setInterval(() => {
|
|
679
|
-
printActions.setReload(true);
|
|
680
|
-
}, SOCKET_PRINT_POLL_INTERVAL_DISCONNECTED);
|
|
681
|
-
|
|
682
|
-
return () => {
|
|
683
|
-
clearInterval(intervalId);
|
|
684
|
-
};
|
|
685
|
-
}, [printActions, shouldHandleSpool, websocketSummary?.connected]);
|
|
686
|
-
|
|
687
|
-
useEffect(() => {
|
|
688
|
-
if (connectedPollTimeoutRef.current) {
|
|
689
|
-
clearTimeout(connectedPollTimeoutRef.current);
|
|
690
|
-
connectedPollTimeoutRef.current = null;
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
if (!shouldHandleSpool || !websocketSummary?.connected || !lastPrintCommandAt) {
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
const elapsed = Date.now() - lastPrintCommandAt;
|
|
698
|
-
const delay = Math.max(SOCKET_PRINT_POLL_DELAY_CONNECTED - elapsed, 0);
|
|
699
|
-
|
|
700
|
-
connectedPollTimeoutRef.current = setTimeout(() => {
|
|
701
|
-
printActions.setReload(true);
|
|
702
|
-
}, delay);
|
|
703
|
-
|
|
704
|
-
return () => {
|
|
705
|
-
if (connectedPollTimeoutRef.current) {
|
|
706
|
-
clearTimeout(connectedPollTimeoutRef.current);
|
|
707
|
-
connectedPollTimeoutRef.current = null;
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
}, [
|
|
711
|
-
lastPrintCommandAt,
|
|
712
|
-
printActions,
|
|
713
|
-
shouldHandleSpool,
|
|
714
|
-
websocketSummary?.connected,
|
|
715
|
-
]);
|
|
716
|
-
|
|
717
|
-
useEffect(() => {
|
|
718
|
-
if (print && print.length > 0) {
|
|
719
|
-
for (const p of print) {
|
|
720
|
-
printActions.addToQueue(() => executePrintRequest(p));
|
|
721
|
-
}
|
|
722
|
-
printActions.initQueue(() => {
|
|
723
|
-
printActions.setPrint([]);
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
}, [
|
|
727
|
-
executePrintRequest,
|
|
728
|
-
print,
|
|
475
|
+
usePrintSpoolEffects({
|
|
476
|
+
currentCompanyId: currentCompany?.id,
|
|
729
477
|
printActions,
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
if (message?.action === 'print' || message?.store === 'print') {
|
|
753
|
-
if (shouldHandleSpool) {
|
|
754
|
-
markPrintCommand();
|
|
755
|
-
printActions.setReload(true);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
printActions.setMessage(null);
|
|
760
|
-
}, [markPrintCommand, message, printActions, shouldHandleSpool]);
|
|
761
|
-
|
|
762
|
-
useEffect(() => {
|
|
763
|
-
if (
|
|
764
|
-
messages &&
|
|
765
|
-
messages.length > 0 &&
|
|
766
|
-
(!message || Object.keys(message).length === 0)
|
|
767
|
-
) {
|
|
768
|
-
const queuedMessages = [...messages];
|
|
769
|
-
printActions.setMessage(queuedMessages.pop());
|
|
770
|
-
printActions.setMessages(queuedMessages);
|
|
771
|
-
}
|
|
772
|
-
}, [messages, message, printActions]);
|
|
773
|
-
|
|
774
|
-
return null;
|
|
775
|
-
};
|
|
776
|
-
|
|
777
|
-
export default PrintService;
|
|
478
|
+
shouldHandleSpool,
|
|
479
|
+
loadOpenSpools,
|
|
480
|
+
reload,
|
|
481
|
+
websocketConnected: websocketSummary?.connected,
|
|
482
|
+
lastPrintCommandAt,
|
|
483
|
+
connectedPollTimeoutRef,
|
|
484
|
+
print,
|
|
485
|
+
executePrintRequest,
|
|
486
|
+
spoolRef,
|
|
487
|
+
isPrintingRef,
|
|
488
|
+
goPrint,
|
|
489
|
+
spool,
|
|
490
|
+
clearAckRetry,
|
|
491
|
+
message,
|
|
492
|
+
messages,
|
|
493
|
+
markPrintCommand,
|
|
494
|
+
});
|
|
495
|
+
return null;
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
export default PrintService;
|
|
778
499
|
// TODO(store-first): quando este arquivo for mexido, mover a leitura para stores, remover api.fetch e evitar repassar dados em objetos quando o store ja resolver isso.
|