@controleonline/ui-common 1.2.70
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/.github/agents/developer.agent.md +30 -0
- package/.github/agents/devops.agent.md +30 -0
- package/.github/agents/qa.agent.md +30 -0
- package/.github/agents/security.agent.md +30 -0
- package/.github/workflows/npmjs.yml +35 -0
- package/.github/workflows/pull-request-checks.yml +19 -0
- package/.scrutinizer.yml +24 -0
- package/FUNDING.yml +1 -0
- package/package.json +28 -0
- package/src/api/fetch.js +74 -0
- package/src/api/index.js +155 -0
- package/src/api/localDB.js +131 -0
- package/src/api/queue.js +66 -0
- package/src/react/assets/tap.mp3 +0 -0
- package/src/react/components/AddImportModal.js +157 -0
- package/src/react/components/AddImportModal.styles.js +81 -0
- package/src/react/components/BackgroundRuntimeBridge.js +219 -0
- package/src/react/components/BottomNavigationBar.config.js +238 -0
- package/src/react/components/BottomNavigationBar.js +120 -0
- package/src/react/components/BottomNavigationBar.styles.js +110 -0
- package/src/react/components/CategoryForm.js +572 -0
- package/src/react/components/CategoryForm.styles.js +334 -0
- package/src/react/components/ConfirmModal.js +24 -0
- package/src/react/components/ConfirmModal.styles.js +43 -0
- package/src/react/components/ContextHelpButton.js +69 -0
- package/src/react/components/ContextHelpButton.styles.js +62 -0
- package/src/react/components/DefaultProvider.native.js +848 -0
- package/src/react/components/DefaultProvider.styles.js +21 -0
- package/src/react/components/DefaultProvider.web.js +909 -0
- package/src/react/components/DeliveryPushBridge.native.js +314 -0
- package/src/react/components/DeliveryPushBridge.web.js +5 -0
- package/src/react/components/DeviceAlertSoundService.js +499 -0
- package/src/react/components/EntityLogContent.js +909 -0
- package/src/react/components/EntityLogContent.styles.js +400 -0
- package/src/react/components/EventBus.js +12 -0
- package/src/react/components/KioskModeBridge.js +65 -0
- package/src/react/components/LauncherModeBridge.js +47 -0
- package/src/react/components/LinkedOrderProductsTab.js +388 -0
- package/src/react/components/LinkedOrderProductsTab.styles.js +180 -0
- package/src/react/components/ManagerPushBridge.native.js +345 -0
- package/src/react/components/MessageService.js +314 -0
- package/src/react/components/Paywall/Google.js +89 -0
- package/src/react/components/PrintService.js +778 -0
- package/src/react/components/ProductCatalogCacheService.js +45 -0
- package/src/react/components/RemoteCheckoutService.js +292 -0
- package/src/react/components/RuntimeBottomNavigationBar.js +151 -0
- package/src/react/components/RuntimeInfoFooter.js +214 -0
- package/src/react/components/RuntimeInfoFooter.styles.js +56 -0
- package/src/react/components/SystemErrorToast.js +29 -0
- package/src/react/components/SystemErrorToast.styles.js +38 -0
- package/src/react/components/TouchFeedbackProvider.js +65 -0
- package/src/react/components/UnifiedPaymentBar.js +155 -0
- package/src/react/components/UnifiedPaymentBar.styles.js +174 -0
- package/src/react/components/WebsocketListener.native.js +487 -0
- package/src/react/components/WebsocketListener.web.js +102 -0
- package/src/react/components/inputs/IdInput.js +49 -0
- package/src/react/components/inputs/IdInput.styles.js +26 -0
- package/src/react/components/inputs/InvoiceDueDateFilterInput.js +74 -0
- package/src/react/components/inputs/InvoiceDueDateFilterInput.styles.js +34 -0
- package/src/react/components/inputs/InvoiceDueDateRangeFilterInput.js +115 -0
- package/src/react/components/inputs/InvoiceDueDateRangeFilterInput.styles.js +39 -0
- package/src/react/components/lists/CategoriesList.js +56 -0
- package/src/react/components/lists/PaymentTypeList.js +55 -0
- package/src/react/components/lists/ReceiverList.js +56 -0
- package/src/react/components/lists/SelectList.styles.js +18 -0
- package/src/react/components/lists/StatusList.js +55 -0
- package/src/react/components/lists/WalletList.js +54 -0
- package/src/react/components/radio/Spotify.js +144 -0
- package/src/react/components/radio/Spotify.styles.js +32 -0
- package/src/react/components/radio/YouTube.js +82 -0
- package/src/react/components/radio/YouTube.styles.js +16 -0
- package/src/react/components/toastConfig.js +16 -0
- package/src/react/config/deviceConfigBootstrap.js +571 -0
- package/src/react/index.js +4 -0
- package/src/react/localStorage.js +30 -0
- package/src/react/pages/EntityLogPage.js +124 -0
- package/src/react/pages/EntityLogPage.styles.js +17 -0
- package/src/react/pages/GenericLogPage.js +760 -0
- package/src/react/pages/GenericLogPage.styles.js +401 -0
- package/src/react/pages/Imports.js +361 -0
- package/src/react/pages/Imports.styles.js +223 -0
- package/src/react/pages/SettingsPage/PaymentTypesByWalletTab.js +462 -0
- package/src/react/pages/SettingsPage/index.js +1171 -0
- package/src/react/pages/SettingsPage/index.styles.js +122 -0
- package/src/react/print/jobs.js +147 -0
- package/src/react/print/providers/local.js +53 -0
- package/src/react/print/providers/remote.js +81 -0
- package/src/react/print/selection.js +296 -0
- package/src/react/print/usePrintButtonController.js +474 -0
- package/src/react/router/routes.js +42 -0
- package/src/react/services/NetworkPrinterService.native.js +391 -0
- package/src/react/services/NetworkPrinterService.web.js +15 -0
- package/src/react/stores/index.js +128 -0
- package/src/react/stores/storeErrorBridge.js +36 -0
- package/src/react/utils/backgroundRuntimeRegistration.js +69 -0
- package/src/react/utils/cashPayment.js +87 -0
- package/src/react/utils/commercialDocumentOrders.js +269 -0
- package/src/react/utils/dateRangeFilter.js +264 -0
- package/src/react/utils/deviceRuntime.js +193 -0
- package/src/react/utils/entityDisplay.js +231 -0
- package/src/react/utils/entityLog.js +649 -0
- package/src/react/utils/fileUrl.js +102 -0
- package/src/react/utils/frontendDebugLog.js +45 -0
- package/src/react/utils/googleMapsConfig.js +49 -0
- package/src/react/utils/importStatus.js +100 -0
- package/src/react/utils/invoiceDueDateMessages.js +14 -0
- package/src/react/utils/invoicePresentation.js +46 -0
- package/src/react/utils/logSettings.js +143 -0
- package/src/react/utils/maintenanceSettings.js +53 -0
- package/src/react/utils/managerOrderNotifications.js +523 -0
- package/src/react/utils/mapNavigation.js +76 -0
- package/src/react/utils/menuCatalogConfig.js +8 -0
- package/src/react/utils/menuCatalogDownload.js +157 -0
- package/src/react/utils/networkCameraDevices.js +175 -0
- package/src/react/utils/networkDeviceProfiles.js +135 -0
- package/src/react/utils/normalizedCatalogDownload.js +157 -0
- package/src/react/utils/notificationNavigation.js +94 -0
- package/src/react/utils/notificationSound.js +42 -0
- package/src/react/utils/paymentDevices.js +397 -0
- package/src/react/utils/paymentGatewayExecution.js +91 -0
- package/src/react/utils/paymentOptions.js +88 -0
- package/src/react/utils/peopleDisplay.js +39 -0
- package/src/react/utils/printerDevices.js +465 -0
- package/src/react/utils/remotePayment.js +61 -0
- package/src/react/utils/runtimeFooter.js +475 -0
- package/src/react/utils/runtimeLanguage.js +50 -0
- package/src/react/utils/runtimeMenu.js +224 -0
- package/src/react/utils/screenMetrics.js +30 -0
- package/src/react/utils/shopConfig.js +294 -0
- package/src/react/utils/shopFranchises.js +114 -0
- package/src/react/utils/socketRuntimePipeline.js +454 -0
- package/src/react/utils/spoolAckTracker.js +77 -0
- package/src/react/utils/storeColumns.js +427 -0
- package/src/react/utils/systemErrorChannel.js +109 -0
- package/src/react/utils/systemErrorMessage.js +67 -0
- package/src/react/utils/toastPresentation.js +53 -0
- package/src/react/utils/websocketSharedRuntime.js +826 -0
- package/src/store/acl/getters.js +4 -0
- package/src/store/acl/index.js +19 -0
- package/src/store/acl/mutation_types.js +4 -0
- package/src/store/acl/mutations.js +17 -0
- package/src/store/address/city.js +22 -0
- package/src/store/categories/category_file/index.js +25 -0
- package/src/store/categories/index.js +93 -0
- package/src/store/configs/customActions.js +131 -0
- package/src/store/configs/index.js +25 -0
- package/src/store/connections/customActions.js +26 -0
- package/src/store/connections/index.js +124 -0
- package/src/store/device/index.js +22 -0
- package/src/store/device_config/customActions.js +190 -0
- package/src/store/device_config/index.js +28 -0
- package/src/store/entity_log/customActions.js +63 -0
- package/src/store/entity_log/index.js +25 -0
- package/src/store/extra/data.js +85 -0
- package/src/store/extra/fields.js +88 -0
- package/src/store/file/actions.js +27 -0
- package/src/store/file/index.js +24 -0
- package/src/store/imports/index.js +88 -0
- package/src/store/print/customActions.js +251 -0
- package/src/store/print/index.js +28 -0
- package/src/store/printer/customActions.js +54 -0
- package/src/store/printer/index.js +26 -0
- package/src/store/runtime_debug/customActions.js +71 -0
- package/src/store/runtime_debug/index.js +30 -0
- package/src/store/status/index.js +65 -0
- package/src/store/timezones/index.js +43 -0
- package/src/store/websocket/customActions.js +24 -0
- package/src/store/websocket/index.js +28 -0
- package/src/tests/react/components/LauncherModeBridge.test.js +93 -0
- package/src/tests/react/config/deviceConfigBootstrap.test.js +337 -0
- package/src/tests/react/print/localPrintProvider.test.js +45 -0
- package/src/tests/react/utils/backgroundRuntimeRegistration.test.js +123 -0
- package/src/tests/react/utils/cashPayment.test.js +41 -0
- package/src/tests/react/utils/dateRangeFilter.test.mjs +29 -0
- package/src/tests/react/utils/entityDisplay.test.js +18 -0
- package/src/tests/react/utils/googleMapsConfig.test.js +32 -0
- package/src/tests/react/utils/importStatus.test.js +85 -0
- package/src/tests/react/utils/invoicePresentation.test.mjs +40 -0
- package/src/tests/react/utils/managerOrderNotifications.test.js +127 -0
- package/src/tests/react/utils/mapNavigation.test.js +58 -0
- package/src/tests/react/utils/notificationNavigation.test.js +39 -0
- package/src/tests/react/utils/notificationSound.test.js +27 -0
- package/src/tests/react/utils/paymentDevices.test.js +88 -0
- package/src/tests/react/utils/runtimeFooter.test.js +429 -0
- package/src/tests/react/utils/runtimeLanguage.test.js +80 -0
- package/src/tests/react/utils/runtimeMenu.test.js +174 -0
- package/src/tests/react/utils/shopFranchises.test.js +82 -0
- package/src/tests/react/utils/socketRuntimePipeline.test.js +124 -0
- package/src/tests/react/utils/spoolAckTracker.test.js +40 -0
- package/src/tests/react/utils/storeErrorBridge.test.js +66 -0
- package/src/tests/react/utils/systemErrorChannel.test.js +58 -0
- package/src/tests/react/utils/systemErrorMessage.test.js +59 -0
- package/src/tests/react/utils/toastPresentation.test.js +75 -0
- package/src/tests/react/utils/translate.test.mjs +396 -0
- package/src/tests/react/utils/websocketSharedRuntime.test.js +245 -0
- package/src/utils/apiEntryPoint.js +31 -0
- package/src/utils/appDomain.js +50 -0
- package/src/utils/config.js +14 -0
- package/src/utils/formatter.js +419 -0
- package/src/utils/integrationConfigs.js +79 -0
- package/src/utils/methods.js +23 -0
- package/src/utils/oauth.js +42 -0
- package/src/utils/translate.js +620 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import {useCallback, useEffect, useMemo, useRef} from 'react';
|
|
2
|
+
import {useStore} from '@store';
|
|
3
|
+
import {
|
|
4
|
+
canDisplayChangePrinter,
|
|
5
|
+
parseConfigsObject,
|
|
6
|
+
} from '@controleonline/ui-common/src/react/config/deviceConfigBootstrap';
|
|
7
|
+
import {isWebRuntimeDevice} from '@controleonline/ui-common/src/react/utils/deviceRuntime';
|
|
8
|
+
import {
|
|
9
|
+
DISPLAY_DEVICE_TYPE,
|
|
10
|
+
getDeviceTypeLabel,
|
|
11
|
+
normalizeDeviceType,
|
|
12
|
+
} from '@controleonline/ui-common/src/react/utils/printerDevices';
|
|
13
|
+
import {normalizeDeviceId} from '@controleonline/ui-common/src/react/utils/paymentDevices';
|
|
14
|
+
import {
|
|
15
|
+
PRINT_CONTEXT_DEVICE,
|
|
16
|
+
PRINT_CONTEXT_DISPLAY,
|
|
17
|
+
PRINT_JOB_TYPE_SPOOL,
|
|
18
|
+
buildPrintRequestKey,
|
|
19
|
+
buildPrintSelectionKey,
|
|
20
|
+
normalizePrintJob,
|
|
21
|
+
} from '@controleonline/ui-common/src/react/print/jobs';
|
|
22
|
+
import {
|
|
23
|
+
resolveCompanyConfiguredPrinterValue,
|
|
24
|
+
resolveConfiguredPrinterValue,
|
|
25
|
+
resolvePrintDeviceConfig,
|
|
26
|
+
resolvePrintSelectionValue,
|
|
27
|
+
resolvePrinterOptions,
|
|
28
|
+
resolvePrinterSelectionValue,
|
|
29
|
+
resolveSelectedPrinter,
|
|
30
|
+
} from '@controleonline/ui-common/src/react/print/selection';
|
|
31
|
+
|
|
32
|
+
const resolveCurrentItemId = storeGetters =>
|
|
33
|
+
storeGetters?.item?.['@id']
|
|
34
|
+
? String(storeGetters.item['@id']).split('/').pop()
|
|
35
|
+
: null;
|
|
36
|
+
|
|
37
|
+
const resolveRuntimeDeviceType = ({
|
|
38
|
+
runtimeDeviceConfig = null,
|
|
39
|
+
currentDevice = null,
|
|
40
|
+
}) => {
|
|
41
|
+
if (isWebRuntimeDevice(currentDevice)) {
|
|
42
|
+
return 'WEB';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return normalizeDeviceType(
|
|
46
|
+
runtimeDeviceConfig?.type ||
|
|
47
|
+
runtimeDeviceConfig?.device?.type ||
|
|
48
|
+
currentDevice?.type,
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const usePrintButtonController = ({
|
|
53
|
+
job = null,
|
|
54
|
+
printType = '',
|
|
55
|
+
store = '',
|
|
56
|
+
printerSelection = {},
|
|
57
|
+
onSuccess = null,
|
|
58
|
+
onError = null,
|
|
59
|
+
} = {}) => {
|
|
60
|
+
const currentStore = useStore(store || 'print');
|
|
61
|
+
const peopleStore = useStore('people');
|
|
62
|
+
const configsStore = useStore('configs');
|
|
63
|
+
const deviceStore = useStore('device');
|
|
64
|
+
const deviceConfigStore = useStore('device_config');
|
|
65
|
+
const printStore = useStore('print');
|
|
66
|
+
const printerStore = useStore('printer');
|
|
67
|
+
|
|
68
|
+
const storeGetters = currentStore?.getters || {};
|
|
69
|
+
const storeActions = currentStore?.actions || {};
|
|
70
|
+
const {currentCompany} = peopleStore.getters;
|
|
71
|
+
const {items: companyConfigs} = configsStore.getters;
|
|
72
|
+
const {item: currentDevice} = deviceStore.getters;
|
|
73
|
+
const {item: runtimeDeviceConfig, items: companyDeviceConfigs = []} =
|
|
74
|
+
deviceConfigStore.getters;
|
|
75
|
+
const {items: printers = [], isLoading: isLoadingPrinters} =
|
|
76
|
+
printerStore.getters;
|
|
77
|
+
const {
|
|
78
|
+
selections = {},
|
|
79
|
+
selectorModalKey = '',
|
|
80
|
+
activeRequestKey = '',
|
|
81
|
+
lastCompletedRequest = null,
|
|
82
|
+
} = printStore.getters;
|
|
83
|
+
const printActions = printStore.actions;
|
|
84
|
+
|
|
85
|
+
const completionRef = useRef('');
|
|
86
|
+
const currentItemId = useMemo(
|
|
87
|
+
() => resolveCurrentItemId(storeGetters),
|
|
88
|
+
[storeGetters],
|
|
89
|
+
);
|
|
90
|
+
const normalizedJob = useMemo(
|
|
91
|
+
() =>
|
|
92
|
+
normalizePrintJob({
|
|
93
|
+
job,
|
|
94
|
+
fallbackType: printType,
|
|
95
|
+
fallbackId: currentItemId,
|
|
96
|
+
}),
|
|
97
|
+
[currentItemId, job, printType],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const currentDeviceId = useMemo(
|
|
101
|
+
() => normalizeDeviceId(currentDevice?.id || currentDevice?.device),
|
|
102
|
+
[currentDevice?.device, currentDevice?.id],
|
|
103
|
+
);
|
|
104
|
+
const runtimeDeviceType = useMemo(
|
|
105
|
+
() =>
|
|
106
|
+
resolveRuntimeDeviceType({
|
|
107
|
+
runtimeDeviceConfig,
|
|
108
|
+
currentDevice,
|
|
109
|
+
}),
|
|
110
|
+
[currentDevice, runtimeDeviceConfig],
|
|
111
|
+
);
|
|
112
|
+
const effectiveCompanyConfigs = useMemo(() => {
|
|
113
|
+
const storedCompanyConfigs = parseConfigsObject(companyConfigs);
|
|
114
|
+
if (Object.keys(storedCompanyConfigs).length > 0) {
|
|
115
|
+
return storedCompanyConfigs;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return parseConfigsObject(currentCompany?.configs);
|
|
119
|
+
}, [companyConfigs, currentCompany?.configs]);
|
|
120
|
+
|
|
121
|
+
const contextType = useMemo(() => {
|
|
122
|
+
if (normalizedJob?.type === PRINT_JOB_TYPE_SPOOL) {
|
|
123
|
+
return 'spool';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (printerSelection?.context === PRINT_CONTEXT_DISPLAY) {
|
|
127
|
+
return PRINT_CONTEXT_DISPLAY;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return PRINT_CONTEXT_DEVICE;
|
|
131
|
+
}, [normalizedJob?.type, printerSelection?.context]);
|
|
132
|
+
|
|
133
|
+
const displayId = useMemo(
|
|
134
|
+
() =>
|
|
135
|
+
String(
|
|
136
|
+
printerSelection?.displayId ||
|
|
137
|
+
printerSelection?.display?.id ||
|
|
138
|
+
printerSelection?.display?.['@id'] ||
|
|
139
|
+
'',
|
|
140
|
+
)
|
|
141
|
+
.replace(/\D+/g, '')
|
|
142
|
+
.trim(),
|
|
143
|
+
[printerSelection?.display, printerSelection?.displayId],
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const effectiveDeviceConfig = useMemo(
|
|
147
|
+
() =>
|
|
148
|
+
resolvePrintDeviceConfig({
|
|
149
|
+
contextType,
|
|
150
|
+
companyDeviceConfigs,
|
|
151
|
+
currentCompanyId: currentCompany?.id,
|
|
152
|
+
currentDeviceId,
|
|
153
|
+
displayId,
|
|
154
|
+
runtimeDeviceConfig,
|
|
155
|
+
}),
|
|
156
|
+
[
|
|
157
|
+
companyDeviceConfigs,
|
|
158
|
+
contextType,
|
|
159
|
+
currentCompany?.id,
|
|
160
|
+
currentDeviceId,
|
|
161
|
+
displayId,
|
|
162
|
+
runtimeDeviceConfig,
|
|
163
|
+
],
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
const contextDeviceId = useMemo(
|
|
167
|
+
() =>
|
|
168
|
+
normalizeDeviceId(
|
|
169
|
+
effectiveDeviceConfig?.device?.device ||
|
|
170
|
+
effectiveDeviceConfig?.device?.id ||
|
|
171
|
+
currentDeviceId,
|
|
172
|
+
),
|
|
173
|
+
[
|
|
174
|
+
currentDeviceId,
|
|
175
|
+
effectiveDeviceConfig?.device?.device,
|
|
176
|
+
effectiveDeviceConfig?.device?.id,
|
|
177
|
+
],
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const configuredPrinterValue = useMemo(
|
|
181
|
+
() => resolveConfiguredPrinterValue(effectiveDeviceConfig),
|
|
182
|
+
[effectiveDeviceConfig],
|
|
183
|
+
);
|
|
184
|
+
const effectiveDeviceType = useMemo(
|
|
185
|
+
() =>
|
|
186
|
+
normalizeDeviceType(
|
|
187
|
+
effectiveDeviceConfig?.type ||
|
|
188
|
+
effectiveDeviceConfig?.device?.type ||
|
|
189
|
+
runtimeDeviceType,
|
|
190
|
+
),
|
|
191
|
+
[effectiveDeviceConfig?.device?.type, effectiveDeviceConfig?.type, runtimeDeviceType],
|
|
192
|
+
);
|
|
193
|
+
const allowDisplayPrinterChange = useMemo(
|
|
194
|
+
() =>
|
|
195
|
+
contextType !== PRINT_CONTEXT_DISPLAY ||
|
|
196
|
+
effectiveDeviceType !== DISPLAY_DEVICE_TYPE ||
|
|
197
|
+
canDisplayChangePrinter(effectiveDeviceConfig?.configs),
|
|
198
|
+
[contextType, effectiveDeviceConfig?.configs, effectiveDeviceType],
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const selectionKey = useMemo(
|
|
202
|
+
() =>
|
|
203
|
+
buildPrintSelectionKey({
|
|
204
|
+
companyId: currentCompany?.id,
|
|
205
|
+
contextType,
|
|
206
|
+
deviceId: contextDeviceId,
|
|
207
|
+
displayId,
|
|
208
|
+
}),
|
|
209
|
+
[contextDeviceId, contextType, currentCompany?.id, displayId],
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const transientPrinterValue = selections?.[selectionKey] || '';
|
|
213
|
+
const printerOptions = useMemo(
|
|
214
|
+
() =>
|
|
215
|
+
resolvePrinterOptions({
|
|
216
|
+
printers,
|
|
217
|
+
companyDeviceConfigs,
|
|
218
|
+
currentCompanyId: currentCompany?.id,
|
|
219
|
+
}),
|
|
220
|
+
[companyDeviceConfigs, currentCompany?.id, printers],
|
|
221
|
+
);
|
|
222
|
+
const companyConfiguredPrinterValue = useMemo(
|
|
223
|
+
() =>
|
|
224
|
+
resolveCompanyConfiguredPrinterValue({
|
|
225
|
+
companyConfigs: effectiveCompanyConfigs,
|
|
226
|
+
currentDeviceConfig: effectiveDeviceConfig,
|
|
227
|
+
printerOptions,
|
|
228
|
+
currentDeviceId,
|
|
229
|
+
runtimeDeviceType,
|
|
230
|
+
}),
|
|
231
|
+
[
|
|
232
|
+
currentDeviceId,
|
|
233
|
+
effectiveDeviceConfig,
|
|
234
|
+
effectiveCompanyConfigs,
|
|
235
|
+
printerOptions,
|
|
236
|
+
runtimeDeviceType,
|
|
237
|
+
],
|
|
238
|
+
);
|
|
239
|
+
const selectedPrinterValue = useMemo(
|
|
240
|
+
() =>
|
|
241
|
+
resolvePrintSelectionValue({
|
|
242
|
+
transientPrinterValue: allowDisplayPrinterChange
|
|
243
|
+
? transientPrinterValue
|
|
244
|
+
: '',
|
|
245
|
+
configuredPrinterValue,
|
|
246
|
+
companyConfiguredPrinterValue,
|
|
247
|
+
currentDeviceConfig: effectiveDeviceConfig,
|
|
248
|
+
printerOptions,
|
|
249
|
+
currentDeviceId,
|
|
250
|
+
runtimeDeviceType,
|
|
251
|
+
}),
|
|
252
|
+
[
|
|
253
|
+
companyConfiguredPrinterValue,
|
|
254
|
+
configuredPrinterValue,
|
|
255
|
+
currentDeviceId,
|
|
256
|
+
effectiveDeviceConfig,
|
|
257
|
+
printerOptions,
|
|
258
|
+
runtimeDeviceType,
|
|
259
|
+
transientPrinterValue,
|
|
260
|
+
allowDisplayPrinterChange,
|
|
261
|
+
],
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
const selectedPrinter = useMemo(
|
|
265
|
+
() =>
|
|
266
|
+
resolveSelectedPrinter({
|
|
267
|
+
currentDeviceConfig: effectiveDeviceConfig,
|
|
268
|
+
printerOptions,
|
|
269
|
+
selectedPrinterValue,
|
|
270
|
+
currentDevice,
|
|
271
|
+
runtimeDeviceType,
|
|
272
|
+
}),
|
|
273
|
+
[
|
|
274
|
+
currentDevice,
|
|
275
|
+
effectiveDeviceConfig,
|
|
276
|
+
printerOptions,
|
|
277
|
+
runtimeDeviceType,
|
|
278
|
+
selectedPrinterValue,
|
|
279
|
+
],
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
const requestKey = useMemo(
|
|
283
|
+
() =>
|
|
284
|
+
buildPrintRequestKey({
|
|
285
|
+
type: normalizedJob?.type,
|
|
286
|
+
id: normalizedJob?.id,
|
|
287
|
+
orderId: normalizedJob?.orderId,
|
|
288
|
+
orderProductId: normalizedJob?.orderProductId,
|
|
289
|
+
orderProductQueueId: normalizedJob?.orderProductQueueId,
|
|
290
|
+
spoolId: normalizedJob?.spoolId,
|
|
291
|
+
selectionKey,
|
|
292
|
+
}),
|
|
293
|
+
[
|
|
294
|
+
normalizedJob?.id,
|
|
295
|
+
normalizedJob?.orderId,
|
|
296
|
+
normalizedJob?.orderProductId,
|
|
297
|
+
normalizedJob?.orderProductQueueId,
|
|
298
|
+
normalizedJob?.spoolId,
|
|
299
|
+
normalizedJob?.type,
|
|
300
|
+
selectionKey,
|
|
301
|
+
],
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const isRequestLoading = activeRequestKey === requestKey && requestKey !== '';
|
|
305
|
+
const canSelectPrinter =
|
|
306
|
+
printerSelection?.enabled === true &&
|
|
307
|
+
allowDisplayPrinterChange &&
|
|
308
|
+
normalizedJob?.type !== PRINT_JOB_TYPE_SPOOL &&
|
|
309
|
+
printerOptions.length >= 2;
|
|
310
|
+
const isModalVisible =
|
|
311
|
+
selectionKey !== '' &&
|
|
312
|
+
selectorModalKey === selectionKey &&
|
|
313
|
+
canSelectPrinter;
|
|
314
|
+
|
|
315
|
+
const selectedPrinterLabel = useMemo(() => {
|
|
316
|
+
if (!selectedPrinter) {
|
|
317
|
+
return '';
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return `${selectedPrinter.alias || selectedPrinter.device} • ${getDeviceTypeLabel(
|
|
321
|
+
selectedPrinter?.type,
|
|
322
|
+
)}`;
|
|
323
|
+
}, [selectedPrinter]);
|
|
324
|
+
|
|
325
|
+
useEffect(() => {
|
|
326
|
+
if (!lastCompletedRequest?.requestKey || lastCompletedRequest.requestKey !== requestKey) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const completionKey = [
|
|
331
|
+
lastCompletedRequest.requestKey,
|
|
332
|
+
lastCompletedRequest.status || '',
|
|
333
|
+
lastCompletedRequest.completedAt || '',
|
|
334
|
+
].join(':');
|
|
335
|
+
if (completionRef.current === completionKey) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
completionRef.current = completionKey;
|
|
340
|
+
|
|
341
|
+
if (lastCompletedRequest?.status === 'success') {
|
|
342
|
+
onSuccess?.(lastCompletedRequest);
|
|
343
|
+
} else {
|
|
344
|
+
onError?.(lastCompletedRequest);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (transientPrinterValue && selectionKey) {
|
|
348
|
+
printActions.clearSelection(selectionKey);
|
|
349
|
+
}
|
|
350
|
+
}, [
|
|
351
|
+
lastCompletedRequest,
|
|
352
|
+
onError,
|
|
353
|
+
onSuccess,
|
|
354
|
+
printActions,
|
|
355
|
+
requestKey,
|
|
356
|
+
selectionKey,
|
|
357
|
+
transientPrinterValue,
|
|
358
|
+
]);
|
|
359
|
+
|
|
360
|
+
const setError = useCallback(
|
|
361
|
+
message => {
|
|
362
|
+
if (typeof storeActions?.setError === 'function') {
|
|
363
|
+
storeActions.setError(message);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
printActions.setError(message);
|
|
368
|
+
},
|
|
369
|
+
[printActions, storeActions],
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
const handleSelectPrinter = useCallback(
|
|
373
|
+
printer => {
|
|
374
|
+
const nextValue = resolvePrinterSelectionValue(printer);
|
|
375
|
+
if (!nextValue || !selectionKey) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
printActions.setSelection({
|
|
380
|
+
key: selectionKey,
|
|
381
|
+
value: nextValue,
|
|
382
|
+
});
|
|
383
|
+
printActions.setSelectorModalKey('');
|
|
384
|
+
},
|
|
385
|
+
[printActions, selectionKey],
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
const handlePrint = useCallback(() => {
|
|
389
|
+
if (!normalizedJob || isRequestLoading) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (normalizedJob.type !== PRINT_JOB_TYPE_SPOOL && !selectedPrinter?.device) {
|
|
394
|
+
if (canSelectPrinter) {
|
|
395
|
+
printActions.setSelectorModalKey(selectionKey);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
setError(global.t?.t('orders', 'title', 'selectPrinter') || 'Selecione a impressora.');
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
printActions.requestPrint({
|
|
404
|
+
...normalizedJob,
|
|
405
|
+
requestKey,
|
|
406
|
+
selectionKey,
|
|
407
|
+
configuredPrinterValue,
|
|
408
|
+
contextType,
|
|
409
|
+
displayId,
|
|
410
|
+
currentDeviceId,
|
|
411
|
+
currentDeviceType: runtimeDeviceType,
|
|
412
|
+
targetPrinterValue: selectedPrinterValue,
|
|
413
|
+
targetPrinterDevice: selectedPrinter?.device || '',
|
|
414
|
+
targetPrinterType: selectedPrinter?.type || runtimeDeviceType,
|
|
415
|
+
targetPrinterLabel: selectedPrinter?.alias || selectedPrinter?.device || '',
|
|
416
|
+
companyId: currentCompany?.id || null,
|
|
417
|
+
});
|
|
418
|
+
}, [
|
|
419
|
+
canSelectPrinter,
|
|
420
|
+
configuredPrinterValue,
|
|
421
|
+
contextType,
|
|
422
|
+
currentCompany?.id,
|
|
423
|
+
currentDeviceId,
|
|
424
|
+
displayId,
|
|
425
|
+
isRequestLoading,
|
|
426
|
+
normalizedJob,
|
|
427
|
+
printActions,
|
|
428
|
+
requestKey,
|
|
429
|
+
runtimeDeviceType,
|
|
430
|
+
selectedPrinter?.alias,
|
|
431
|
+
selectedPrinter?.device,
|
|
432
|
+
selectedPrinter?.type,
|
|
433
|
+
selectedPrinterValue,
|
|
434
|
+
selectionKey,
|
|
435
|
+
setError,
|
|
436
|
+
]);
|
|
437
|
+
|
|
438
|
+
const closePrinterModal = useCallback(() => {
|
|
439
|
+
if (isLoadingPrinters) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
printActions.setSelectorModalKey('');
|
|
444
|
+
}, [isLoadingPrinters, printActions]);
|
|
445
|
+
|
|
446
|
+
const openPrinterModal = useCallback(() => {
|
|
447
|
+
if (!canSelectPrinter || !selectionKey) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
printActions.setSelectorModalKey(selectionKey);
|
|
452
|
+
}, [canSelectPrinter, printActions, selectionKey]);
|
|
453
|
+
|
|
454
|
+
return {
|
|
455
|
+
canSelectPrinter,
|
|
456
|
+
closePrinterModal,
|
|
457
|
+
currentDeviceId,
|
|
458
|
+
currentDeviceType: runtimeDeviceType,
|
|
459
|
+
displayId,
|
|
460
|
+
handlePrint,
|
|
461
|
+
handleSelectPrinter,
|
|
462
|
+
isModalVisible,
|
|
463
|
+
isRequestLoading,
|
|
464
|
+
isWebRuntime: runtimeDeviceType === 'WEB',
|
|
465
|
+
normalizedJob,
|
|
466
|
+
openPrinterModal,
|
|
467
|
+
printerOptions,
|
|
468
|
+
requestKey,
|
|
469
|
+
selectedPrinter,
|
|
470
|
+
selectedPrinterLabel,
|
|
471
|
+
selectedPrinterValue,
|
|
472
|
+
setError,
|
|
473
|
+
};
|
|
474
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import ImportsPage from '@controleonline/ui-common/src/react/pages/Imports';
|
|
2
|
+
import EntityLogPage from '@controleonline/ui-common/src/react/pages/EntityLogPage';
|
|
3
|
+
import GenericLogPage from '@controleonline/ui-common/src/react/pages/GenericLogPage';
|
|
4
|
+
|
|
5
|
+
const commonRoutes = [
|
|
6
|
+
{
|
|
7
|
+
name: 'EntityLogPage',
|
|
8
|
+
component: EntityLogPage,
|
|
9
|
+
options: {
|
|
10
|
+
headerShown: true,
|
|
11
|
+
headerBackVisible: true,
|
|
12
|
+
title: 'Historico',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'GenericLogPage',
|
|
17
|
+
component: GenericLogPage,
|
|
18
|
+
options: {
|
|
19
|
+
headerShown: true,
|
|
20
|
+
headerBackVisible: true,
|
|
21
|
+
showBottomToolBar: true,
|
|
22
|
+
showCompanyFilter: true,
|
|
23
|
+
companyFilterMode: 'icon',
|
|
24
|
+
title: 'Logs',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'ImportsPage',
|
|
29
|
+
component: ImportsPage,
|
|
30
|
+
options: {
|
|
31
|
+
showCompanyFilter: true,
|
|
32
|
+
headerShown: true,
|
|
33
|
+
showBottomToolBar: true,
|
|
34
|
+
title: 'Importações',
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
export default commonRoutes;
|