@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
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { useNavigation, useRoute } from '@react-navigation/native';
|
|
3
|
+
import { useStore } from '@store';
|
|
4
|
+
import { useMessage } from '@controleonline/ui-common/src/react/components/MessageService';
|
|
5
|
+
import { resolveThemePalette } from '@controleonline/../../src/styles/branding';
|
|
6
|
+
import { colors } from '@controleonline/../../src/styles/colors';
|
|
7
|
+
import packageJson from '@package';
|
|
8
|
+
import {
|
|
9
|
+
canDisplayChangePrinter, DEVICE_ANDROID_KIOSK_ENABLED_CONFIG_KEY, DEVICE_ANDROID_LAUNCHER_ENABLED_CONFIG_KEY,
|
|
10
|
+
DISPLAY_AUTO_PRINT_PRODUCT_CONFIG_KEY, DISPLAY_ALLOW_PRINTER_CHANGE_CONFIG_KEY, DEVICE_ALERT_SOUND_ENABLED_KEY,
|
|
11
|
+
DEVICE_ALERT_SOUND_URL_KEY, DEVICE_ORDER_VISIBILITY_COMPANY, DEVICE_ORDER_VISIBILITY_DEVICE, DEVICE_ORDER_VISIBILITY_KEY,
|
|
12
|
+
DEVICE_RUNTIME_DEBUG_INFO_ENABLED_KEY, isPosAutoPrintEnabled, isPosCashRegisterOpen, isTruthyValue, parseConfigsObject,
|
|
13
|
+
POS_AUTO_PRINT_ENABLED_CONFIG_KEY, POS_CASH_MANAGEMENT_MODE_CASH_REGISTER, POS_CASH_MANAGEMENT_MODE_CONFIG_KEY,
|
|
14
|
+
POS_CASH_MANAGEMENT_MODE_DAILY, POS_CHECK_ORDER_MANAGEMENT_MODE_CONFIG_KEY, POS_CHECK_ORDER_MANAGEMENT_MODE_EXISTING_ONLY,
|
|
15
|
+
POS_CHECK_ORDER_MANAGEMENT_MODE_MANAGE, POS_CHECK_ORDER_TYPE_CONFIG_KEY, POS_CHECK_ORDER_TYPE_NONE, POS_CHECK_ORDER_TYPE_TAB,
|
|
16
|
+
POS_CHECK_ORDER_TYPE_TABLE, POS_CHECK_ORDER_TYPE_STAMP, POS_DELIVERY_ENABLED_CONFIG_KEY, POS_OPERATION_MODE_COUNTER,
|
|
17
|
+
POS_OPERATION_MODE_CONFIG_KEY, POS_OPERATION_MODE_OPTIONS, POS_PRODUCT_SHOWCASE_CONFIG_KEY, POS_PRINT_MODE_FORM,
|
|
18
|
+
POS_PRINT_MODE_ORDER, getPosOperationModeOption, isAndroidKioskEnabled, isAndroidLauncherEnabled, isPosDeliveryEnabled,
|
|
19
|
+
resolvePosCheckOrderManagementMode, resolvePosCheckOrderType, resolvePosCheckOrderTypeForShop, resolveDeviceOrderVisibility,
|
|
20
|
+
resolvePosCashManagementMode, resolvePosOperationMode, resolvePosPrintMode,
|
|
21
|
+
} from '@controleonline/ui-common/src/react/config/deviceConfigBootstrap';
|
|
22
|
+
import {
|
|
23
|
+
filterDeviceConfigsByCompany, getCompanyPaymentDeviceOptions, getPaymentGatewayFromConfigs, getPaymentGatewayLabel,
|
|
24
|
+
isPaymentCapableDeviceConfig, isPdvPrinterEnabled, normalizeDeviceId, normalizeEntityId, PAYMENT_TYPE_IDS_CONFIG_KEY,
|
|
25
|
+
PAYMENT_GATEWAY_CIELO, PDV_PRINTER_ENABLED_CONFIG_KEY, ORDER_PAYMENT_DEVICE_CONFIG_KEY, POS_GATEWAY_CONFIG_KEY,
|
|
26
|
+
} from '@controleonline/ui-common/src/react/utils/paymentDevices';
|
|
27
|
+
import { normalizeBooleanConfig, SHOP_LOYALTY_COUPONS_ENABLED_CONFIG_KEY } from '@controleonline/ui-common/src/react/utils/shopConfig';
|
|
28
|
+
import { getPrinterOptionValue, getDeviceTypeLabel, getPrinterLabel, getPrinterOptions } from '@controleonline/ui-common/src/react/utils/printerDevices';
|
|
29
|
+
import { hex, DISPLAY_DEVICE_TYPE, PDV_DEVICE_TYPE, DISPLAY_DEVICE_LINK_CONFIG_KEY, DISPLAY_DEVICE_PRINTER_CONFIG_KEY,
|
|
30
|
+
PDV_TAB_OPERATION, PDV_TAB_ORDERS, PDV_TAB_DEVICE, PDV_TAB_PAYMENT_TYPES, PDV_TAB_MOVEMENT, PDV_DETAIL_TABS, tt,
|
|
31
|
+
} from './deviceDetailConstants';
|
|
32
|
+
import { paymentIcon, formatApiError, getDisplayLabel, getProductShowcaseLabel, getIsOpen, confirm } from './deviceDetailHelpers';
|
|
33
|
+
import { api } from '@controleonline/ui-common/src/api';
|
|
34
|
+
import { buildDeviceAliasStoreUpdates } from '@controleonline/ui-common/src/react/utils/deviceAliasSync';
|
|
35
|
+
import { createDeviceDetailRenderers } from './DeviceDetailRenderers';
|
|
36
|
+
import { Alert, Platform } from 'react-native';
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export default function useDeviceDetailLoaders(deps) {
|
|
40
|
+
const {
|
|
41
|
+
navigation, deviceId, deviceConfigStore, messageApi, websocketActions, runtimeCompanyConfigs, showSystemError, loyaltyCouponsEnabled, currentDevice, currentDeviceConfig, deviceString, deviceType,
|
|
42
|
+
normalizedInitialConfigs, initialAlias, isDisplayDevice, isPdvDevice, actionsRef, stampAutoDisableSignatureRef, brandColors, products, setProducts, productShowcases, setProductShowcases, companyDeviceConfigs,
|
|
43
|
+
setCompanyDeviceConfigs, inflowData, setInflowData, configs, setConfigs, loadingConfigData, setLoadingConfigData, loadingCompanyDeviceConfigs, setLoadingCompanyDeviceConfigs, loadingMovementData, setLoadingMovementData, actionLoading,
|
|
44
|
+
setActionLoading, activePdvTab, setActivePdvTab, savingPaymentTarget, setSavingPaymentTarget, savingPdvSettings, setSavingPdvSettings, savingPaymentTypes, setSavingPaymentTypes, savingPosOperationMode, setSavingPosOperationMode, savingProductShowcase,
|
|
45
|
+
setSavingProductShowcase, savingLauncherMode, setSavingLauncherMode, savingAlertSound, setSavingAlertSound, savingOrderVisibility, setSavingOrderVisibility, savingDeviceDeliverySettings, setSavingDeviceDeliverySettings, savingRuntimeDebugInfo, setSavingRuntimeDebugInfo, sendingCatalogRefresh,
|
|
46
|
+
setSendingCatalogRefresh, loadingProductShowcases, setLoadingProductShowcases, search, setSearch, devicePaymentTarget, setDevicePaymentTarget, pdvGateway, setPdvGateway, pdvPrinterEnabled, setPdvPrinterEnabled, posOperationMode,
|
|
47
|
+
setPosOperationMode, productShowcaseId, setProductShowcaseId, androidKioskEnabled, setAndroidKioskEnabled, androidLauncherEnabled, setAndroidLauncherEnabled, counterAutoPrintEnabled, setCounterAutoPrintEnabled, counterPrintMode, setCounterPrintMode, counterCashManagementMode,
|
|
48
|
+
setCounterCashManagementMode, checkOrderType, setCheckOrderType, checkOrderManagementMode, setCheckOrderManagementMode, deviceOrderVisibility, setDeviceOrderVisibility, deviceDeliveryEnabled, setDeviceDeliveryEnabled, deviceAlertSoundEnabled, setDeviceAlertSoundEnabled, deviceAlertSoundUrl,
|
|
49
|
+
setDeviceAlertSoundUrl, deviceRuntimeDebugInfoEnabled, setDeviceRuntimeDebugInfoEnabled, linkedDisplayId, setLinkedDisplayId, displayPrinterId, setDisplayPrinterId, displayAllowPrinterChange, setDisplayAllowPrinterChange, displayAutoPrintProductEnabled, setDisplayAutoPrintProductEnabled, savingDisplayPrintingConfig,
|
|
50
|
+
setSavingDisplayPrintingConfig, hasLoadedCurrentConfig, setHasLoadedCurrentConfig, hasLoadedCompanyConfigs, setHasLoadedCompanyConfigs, hasLoadedMovementData, setHasLoadedMovementData, hasLoadedCurrentConfigRef, hasLoadedCompanyConfigsRef, hasLoadedMovementDataRef, hasInitializedPdvTabRef, alias,
|
|
51
|
+
setAlias, editingAlias, setEditingAlias, aliasInput, setAliasInput, savingAlias, setSavingAlias, removingDevice, setRemovingDevice, aliasInputRef, skipAliasSyncFromStoreRef, isOpen,
|
|
52
|
+
hasLocalPaymentGateway, paymentDeviceOptions, displayOptions, printerOptions, selectedPosOperationModeOption, pickerMode, packageVersion, appVersion, runtimeDeviceId, runtimeDeviceType, isEditingRuntimeDevice, resolveDeviceContext,
|
|
53
|
+
} = deps;
|
|
54
|
+
const loadMovementData = useCallback(async () => {
|
|
55
|
+
if (!isPdvDevice) {
|
|
56
|
+
setProducts([]);
|
|
57
|
+
setInflowData(null);
|
|
58
|
+
setHasLoadedMovementData(false);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!currentCompany?.id) return;
|
|
63
|
+
const resolvedContext = await resolveDeviceContext();
|
|
64
|
+
const nextDeviceString = resolvedContext?.deviceString || deviceString;
|
|
65
|
+
if (!nextDeviceString) return;
|
|
66
|
+
setLoadingMovementData(true);
|
|
67
|
+
try {
|
|
68
|
+
const [cashData, inflowRaw] = await Promise.all([
|
|
69
|
+
actionsRef.current.invoiceActions.getCashRegister({
|
|
70
|
+
device: nextDeviceString,
|
|
71
|
+
provider: currentCompany.id,
|
|
72
|
+
}),
|
|
73
|
+
actionsRef.current.invoiceActions.getInflow({
|
|
74
|
+
'device.device': nextDeviceString,
|
|
75
|
+
receiver: currentCompany.id,
|
|
76
|
+
}),
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
setProducts(Array.isArray(cashData) ? cashData : []);
|
|
80
|
+
|
|
81
|
+
// getInflow retorna data['member'] = [{ payments: {...} }]
|
|
82
|
+
const member = Array.isArray(inflowRaw) ? inflowRaw : [];
|
|
83
|
+
setInflowData(member[0]?.payments || null);
|
|
84
|
+
} catch {
|
|
85
|
+
setProducts([]);
|
|
86
|
+
setInflowData(null);
|
|
87
|
+
} finally {
|
|
88
|
+
setLoadingMovementData(false);
|
|
89
|
+
setHasLoadedMovementData(true);
|
|
90
|
+
}
|
|
91
|
+
}, [currentCompany?.id, deviceString, isPdvDevice, resolveDeviceContext]);
|
|
92
|
+
|
|
93
|
+
const refreshCurrentConfig = useCallback(async () => {
|
|
94
|
+
if (!currentCompany?.id) return;
|
|
95
|
+
setLoadingConfigData(true);
|
|
96
|
+
try {
|
|
97
|
+
const resolvedContext = await resolveDeviceContext();
|
|
98
|
+
const nextDeviceString = resolvedContext?.deviceString || deviceString;
|
|
99
|
+
const nextDeviceType = resolvedContext?.deviceType || deviceType;
|
|
100
|
+
if (!nextDeviceString || !nextDeviceType) {
|
|
101
|
+
applyCurrentDeviceConfig([], {
|
|
102
|
+
deviceId,
|
|
103
|
+
deviceString: nextDeviceString,
|
|
104
|
+
deviceType: nextDeviceType,
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const items = await actionsRef.current.deviceConfigActions.getItems({
|
|
110
|
+
'device.device': nextDeviceString,
|
|
111
|
+
people: `/people/${currentCompany.id}`,
|
|
112
|
+
type: nextDeviceType,
|
|
113
|
+
});
|
|
114
|
+
const scopedItems = filterDeviceConfigsByCompany(items, currentCompany?.id);
|
|
115
|
+
const selectedDeviceConfig = scopedItems.find(d => {
|
|
116
|
+
const currentConfigType = String(d?.type || d?.device?.type || '')
|
|
117
|
+
.trim()
|
|
118
|
+
.toUpperCase();
|
|
119
|
+
const nextDeviceId = normalizeEntityId(
|
|
120
|
+
d?.device?.id ||
|
|
121
|
+
d?.device?.['@id'] ||
|
|
122
|
+
d?.deviceId ||
|
|
123
|
+
d?.device?.deviceId,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
(deviceId && nextDeviceId === deviceId) ||
|
|
128
|
+
(d?.device?.device === nextDeviceString &&
|
|
129
|
+
currentConfigType === nextDeviceType)
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (selectedDeviceConfig) {
|
|
134
|
+
actionsRef.current.deviceConfigActions.setItem({
|
|
135
|
+
...selectedDeviceConfig,
|
|
136
|
+
configs: parseConfigsObject(selectedDeviceConfig.configs),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
applyCurrentDeviceConfig(
|
|
141
|
+
selectedDeviceConfig ? [selectedDeviceConfig] : scopedItems,
|
|
142
|
+
{
|
|
143
|
+
deviceId,
|
|
144
|
+
deviceString: nextDeviceString,
|
|
145
|
+
deviceType: nextDeviceType,
|
|
146
|
+
},
|
|
147
|
+
);
|
|
148
|
+
} catch {
|
|
149
|
+
applyCurrentDeviceConfig([], {deviceId});
|
|
150
|
+
} finally {
|
|
151
|
+
setLoadingConfigData(false);
|
|
152
|
+
setHasLoadedCurrentConfig(true);
|
|
153
|
+
}
|
|
154
|
+
}, [
|
|
155
|
+
applyCurrentDeviceConfig,
|
|
156
|
+
currentCompany?.id,
|
|
157
|
+
deviceString,
|
|
158
|
+
deviceType,
|
|
159
|
+
deviceId,
|
|
160
|
+
resolveDeviceContext,
|
|
161
|
+
]);
|
|
162
|
+
|
|
163
|
+
const loadCompanyConfigs = useCallback(async () => {
|
|
164
|
+
if (!currentCompany?.id) return;
|
|
165
|
+
|
|
166
|
+
setLoadingCompanyDeviceConfigs(true);
|
|
167
|
+
try {
|
|
168
|
+
const items = await actionsRef.current.deviceConfigActions.getItems({
|
|
169
|
+
people: `/people/${currentCompany.id}`,
|
|
170
|
+
});
|
|
171
|
+
const scopedItems = filterDeviceConfigsByCompany(items, currentCompany?.id);
|
|
172
|
+
setCompanyDeviceConfigs(Array.isArray(scopedItems) ? scopedItems : []);
|
|
173
|
+
} catch {
|
|
174
|
+
setCompanyDeviceConfigs([]);
|
|
175
|
+
} finally {
|
|
176
|
+
setLoadingCompanyDeviceConfigs(false);
|
|
177
|
+
setHasLoadedCompanyConfigs(true);
|
|
178
|
+
}
|
|
179
|
+
}, [currentCompany?.id]);
|
|
180
|
+
|
|
181
|
+
const loadProductShowcases = useCallback(async () => {
|
|
182
|
+
if (!currentCompany?.id || !isPdvDevice) {
|
|
183
|
+
setProductShowcases([]);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
setLoadingProductShowcases(true);
|
|
188
|
+
try {
|
|
189
|
+
const response = await api.fetch('/product_showcases', {
|
|
190
|
+
params: {
|
|
191
|
+
company: `/people/${currentCompany.id}`,
|
|
192
|
+
integrationKey: 'pos',
|
|
193
|
+
active: 1,
|
|
194
|
+
'order[name]': 'ASC',
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
const items =
|
|
198
|
+
response?.member ||
|
|
199
|
+
response?.['hydra:member'] ||
|
|
200
|
+
response?.items ||
|
|
201
|
+
response;
|
|
202
|
+
setProductShowcases(Array.isArray(items) ? items : []);
|
|
203
|
+
} catch {
|
|
204
|
+
setProductShowcases([]);
|
|
205
|
+
} finally {
|
|
206
|
+
setLoadingProductShowcases(false);
|
|
207
|
+
}
|
|
208
|
+
}, [currentCompany?.id, isPdvDevice]);
|
|
209
|
+
|
|
210
|
+
const ensureActiveTabData = useCallback(async ({ force = false } = {}) => {
|
|
211
|
+
if (!currentCompany?.id) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!isPdvDevice) {
|
|
216
|
+
await Promise.all([
|
|
217
|
+
refreshCurrentConfig(),
|
|
218
|
+
loadCompanyConfigs(),
|
|
219
|
+
]);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (activePdvTab === PDV_TAB_MOVEMENT) {
|
|
224
|
+
if (!force && hasLoadedMovementDataRef.current) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
await loadMovementData();
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (activePdvTab === PDV_TAB_ORDERS) {
|
|
232
|
+
const pendingLoads = [];
|
|
233
|
+
if (force || !hasLoadedCurrentConfigRef.current) {
|
|
234
|
+
pendingLoads.push(refreshCurrentConfig());
|
|
235
|
+
}
|
|
236
|
+
if (force || !hasLoadedCompanyConfigsRef.current) {
|
|
237
|
+
pendingLoads.push(loadCompanyConfigs());
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (pendingLoads.length > 0) {
|
|
241
|
+
await Promise.all(pendingLoads);
|
|
242
|
+
}
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (force || !hasLoadedCurrentConfig) {
|
|
247
|
+
await refreshCurrentConfig();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (activePdvTab === PDV_TAB_OPERATION) {
|
|
251
|
+
await loadProductShowcases();
|
|
252
|
+
}
|
|
253
|
+
}, [
|
|
254
|
+
activePdvTab,
|
|
255
|
+
currentCompany?.id,
|
|
256
|
+
isPdvDevice,
|
|
257
|
+
loadCompanyConfigs,
|
|
258
|
+
loadMovementData,
|
|
259
|
+
loadProductShowcases,
|
|
260
|
+
refreshCurrentConfig,
|
|
261
|
+
]);
|
|
262
|
+
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
setHasLoadedCurrentConfig(false);
|
|
265
|
+
setHasLoadedCompanyConfigs(false);
|
|
266
|
+
setHasLoadedMovementData(false);
|
|
267
|
+
hasInitializedPdvTabRef.current = false;
|
|
268
|
+
setProducts([]);
|
|
269
|
+
setInflowData(null);
|
|
270
|
+
setCompanyDeviceConfigs([]);
|
|
271
|
+
}, [currentCompany?.id, deviceString, deviceType]);
|
|
272
|
+
|
|
273
|
+
const ensureActiveTabDataRef = useRef(ensureActiveTabData);
|
|
274
|
+
useEffect(() => {
|
|
275
|
+
ensureActiveTabDataRef.current = ensureActiveTabData;
|
|
276
|
+
}, [ensureActiveTabData]);
|
|
277
|
+
|
|
278
|
+
useFocusEffect(
|
|
279
|
+
useCallback(() => {
|
|
280
|
+
ensureActiveTabDataRef.current({ force: true });
|
|
281
|
+
}, []),
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
if (!isPdvDevice) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (!hasInitializedPdvTabRef.current) {
|
|
290
|
+
hasInitializedPdvTabRef.current = true;
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
ensureActiveTabDataRef.current();
|
|
295
|
+
}, [activePdvTab, isPdvDevice]);
|
|
296
|
+
|
|
297
|
+
useFocusEffect(
|
|
298
|
+
useCallback(() => {
|
|
299
|
+
if (!isDisplayDevice || !currentCompany?.id) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
displayStore.actions
|
|
304
|
+
.getItems({
|
|
305
|
+
company: currentCompany.id,
|
|
306
|
+
})
|
|
307
|
+
.catch(() => {});
|
|
308
|
+
printerStore.actions
|
|
309
|
+
.getPrinters({people: currentCompany.id})
|
|
310
|
+
.catch(() => {});
|
|
311
|
+
}, [
|
|
312
|
+
currentCompany?.id,
|
|
313
|
+
displayStore.actions,
|
|
314
|
+
isDisplayDevice,
|
|
315
|
+
printerStore.actions,
|
|
316
|
+
]),
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
return {
|
|
320
|
+
loadMovementData,
|
|
321
|
+
refreshCurrentConfig,
|
|
322
|
+
loadCompanyConfigs,
|
|
323
|
+
loadProductShowcases,
|
|
324
|
+
ensureActiveTabData,
|
|
325
|
+
ensureActiveTabDataRef,
|
|
326
|
+
};
|
|
327
|
+
}
|