@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,314 @@
|
|
|
1
|
+
import React, {useCallback, useEffect, useRef} from 'react';
|
|
2
|
+
import {Platform} from 'react-native';
|
|
3
|
+
import * as Notifications from 'expo-notifications';
|
|
4
|
+
import {env as APP_ENV} from '@env';
|
|
5
|
+
import {useStore} from '@store';
|
|
6
|
+
import {ensureManagerOrderNotificationPermission} from '@controleonline/ui-common/src/react/utils/managerOrderNotifications';
|
|
7
|
+
import {queueNotificationNavigation} from '@controleonline/ui-common/src/react/utils/notificationNavigation';
|
|
8
|
+
|
|
9
|
+
const normalizeText = value => String(value || '').trim();
|
|
10
|
+
|
|
11
|
+
const isDeliveryRuntimeAppType = appType =>
|
|
12
|
+
normalizeText(appType).toUpperCase() === 'DELIVERY';
|
|
13
|
+
|
|
14
|
+
const extractOrderIdFromResponse = response => {
|
|
15
|
+
const data = response?.notification?.request?.content?.data || {};
|
|
16
|
+
const candidate =
|
|
17
|
+
data?.orderId ||
|
|
18
|
+
data?.order_id ||
|
|
19
|
+
data?.order ||
|
|
20
|
+
data?.id ||
|
|
21
|
+
data?.orderDetailsId ||
|
|
22
|
+
'';
|
|
23
|
+
|
|
24
|
+
return normalizeText(candidate).replace(/\D+/g, '');
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const extractDeliveryPushToken = metadata =>
|
|
28
|
+
normalizeText(metadata?.pushTokens?.delivery?.android?.deviceToken || '');
|
|
29
|
+
|
|
30
|
+
const resolvePersistableDeviceEntityId = deviceInfo =>
|
|
31
|
+
normalizeText(deviceInfo?.entityId || deviceInfo?.apiId || deviceInfo?.['@id']).replace(/\D+/g, '');
|
|
32
|
+
|
|
33
|
+
const mergeDeliveryPushTokenMetadata = (metadata, deviceToken) => {
|
|
34
|
+
const normalizedMetadata = metadata && typeof metadata === 'object' && !Array.isArray(metadata)
|
|
35
|
+
? metadata
|
|
36
|
+
: {};
|
|
37
|
+
const nextMetadata = {
|
|
38
|
+
...normalizedMetadata,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const pushTokens = normalizedMetadata.pushTokens && typeof normalizedMetadata.pushTokens === 'object' && !Array.isArray(normalizedMetadata.pushTokens)
|
|
42
|
+
? {...normalizedMetadata.pushTokens}
|
|
43
|
+
: {};
|
|
44
|
+
const deliveryTokens = pushTokens.delivery && typeof pushTokens.delivery === 'object' && !Array.isArray(pushTokens.delivery)
|
|
45
|
+
? {...pushTokens.delivery}
|
|
46
|
+
: {};
|
|
47
|
+
const androidTokens = deliveryTokens.android && typeof deliveryTokens.android === 'object' && !Array.isArray(deliveryTokens.android)
|
|
48
|
+
? {...deliveryTokens.android}
|
|
49
|
+
: {};
|
|
50
|
+
|
|
51
|
+
if (normalizeText(deviceToken)) {
|
|
52
|
+
androidTokens.deviceToken = normalizeText(deviceToken);
|
|
53
|
+
deliveryTokens.android = androidTokens;
|
|
54
|
+
pushTokens.delivery = deliveryTokens;
|
|
55
|
+
nextMetadata.pushTokens = pushTokens;
|
|
56
|
+
return nextMetadata;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
delete androidTokens.deviceToken;
|
|
60
|
+
if (Object.keys(androidTokens).length > 0) {
|
|
61
|
+
deliveryTokens.android = androidTokens;
|
|
62
|
+
} else {
|
|
63
|
+
delete deliveryTokens.android;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (Object.keys(deliveryTokens).length > 0) {
|
|
67
|
+
pushTokens.delivery = deliveryTokens;
|
|
68
|
+
} else {
|
|
69
|
+
delete pushTokens.delivery;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (Object.keys(pushTokens).length > 0) {
|
|
73
|
+
nextMetadata.pushTokens = pushTokens;
|
|
74
|
+
} else {
|
|
75
|
+
delete nextMetadata.pushTokens;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return nextMetadata;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const DeliveryPushBridge = ({device, setDevice}) => {
|
|
82
|
+
const authStore = useStore('auth');
|
|
83
|
+
const deviceStore = useStore('device');
|
|
84
|
+
|
|
85
|
+
const authGetters = authStore.getters;
|
|
86
|
+
const deviceActions = deviceStore.actions;
|
|
87
|
+
|
|
88
|
+
const {isLogged, sessionChecked} = authGetters;
|
|
89
|
+
const isDeliveryRuntime = isDeliveryRuntimeAppType(APP_ENV?.APP_TYPE);
|
|
90
|
+
|
|
91
|
+
const currentDeviceRef = useRef(device || {});
|
|
92
|
+
const pushTokenListenerRef = useRef(null);
|
|
93
|
+
const notificationResponseListenerRef = useRef(null);
|
|
94
|
+
|
|
95
|
+
const persistLocalDevice = useCallback(
|
|
96
|
+
nextDevice => {
|
|
97
|
+
if (!nextDevice?.id) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const currentSerializedDevice = JSON.stringify(
|
|
102
|
+
currentDeviceRef.current || {},
|
|
103
|
+
);
|
|
104
|
+
const nextSerializedDevice = JSON.stringify(nextDevice || {});
|
|
105
|
+
if (currentSerializedDevice === nextSerializedDevice) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
currentDeviceRef.current = nextDevice;
|
|
110
|
+
setDevice(nextDevice);
|
|
111
|
+
localStorage.setItem('device', JSON.stringify(nextDevice));
|
|
112
|
+
deviceActions.setItem(nextDevice);
|
|
113
|
+
},
|
|
114
|
+
[deviceActions, setDevice],
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const applyDeliveryPushToken = useCallback(
|
|
118
|
+
async (deviceToken, {persistImmediately = false} = {}) => {
|
|
119
|
+
const currentDevice = currentDeviceRef.current || {};
|
|
120
|
+
if (!currentDevice?.id) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const normalizedToken = normalizeText(deviceToken);
|
|
125
|
+
const currentToken = extractDeliveryPushToken(currentDevice?.metadata);
|
|
126
|
+
|
|
127
|
+
if (
|
|
128
|
+
!persistImmediately &&
|
|
129
|
+
normalizedToken &&
|
|
130
|
+
currentToken === normalizedToken
|
|
131
|
+
) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!persistImmediately && !normalizedToken && !currentToken) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (persistImmediately && !normalizedToken && !currentToken) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const nextMetadata = mergeDeliveryPushTokenMetadata(
|
|
144
|
+
currentDevice?.metadata,
|
|
145
|
+
normalizedToken,
|
|
146
|
+
);
|
|
147
|
+
const nextDevice = {
|
|
148
|
+
...currentDevice,
|
|
149
|
+
metadata: nextMetadata,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
persistLocalDevice(nextDevice);
|
|
153
|
+
|
|
154
|
+
if (!persistImmediately) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const entityId = resolvePersistableDeviceEntityId(currentDevice);
|
|
159
|
+
if (!entityId) {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
await deviceActions.save({
|
|
165
|
+
id: entityId,
|
|
166
|
+
device: currentDevice.device || currentDevice.id,
|
|
167
|
+
alias: currentDevice.alias,
|
|
168
|
+
metadata: nextMetadata,
|
|
169
|
+
});
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.warn('Erro ao salvar push token de Delivery no logout', error);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return true;
|
|
175
|
+
},
|
|
176
|
+
[deviceActions, persistLocalDevice],
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
currentDeviceRef.current = device || {};
|
|
181
|
+
}, [device]);
|
|
182
|
+
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
if (Platform.OS !== 'android' || !isDeliveryRuntime) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
global.clearDeliveryPushTokenOnLogout = () =>
|
|
189
|
+
applyDeliveryPushToken('', {persistImmediately: true});
|
|
190
|
+
|
|
191
|
+
return () => {
|
|
192
|
+
if (global.clearDeliveryPushTokenOnLogout) {
|
|
193
|
+
delete global.clearDeliveryPushTokenOnLogout;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}, [applyDeliveryPushToken, isDeliveryRuntime]);
|
|
197
|
+
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
if (
|
|
200
|
+
Platform.OS !== 'android' ||
|
|
201
|
+
!isDeliveryRuntime ||
|
|
202
|
+
!sessionChecked ||
|
|
203
|
+
!currentDeviceRef.current?.id
|
|
204
|
+
) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
let cancelled = false;
|
|
209
|
+
|
|
210
|
+
const configurePushSupport = async () => {
|
|
211
|
+
if (!isLogged) {
|
|
212
|
+
const currentToken = extractDeliveryPushToken(
|
|
213
|
+
currentDeviceRef.current?.metadata,
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
if (currentToken) {
|
|
217
|
+
await applyDeliveryPushToken('', {persistImmediately: true});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const permissionStatus = await ensureManagerOrderNotificationPermission();
|
|
224
|
+
|
|
225
|
+
if (cancelled) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (permissionStatus !== 'granted') {
|
|
230
|
+
await applyDeliveryPushToken('', {persistImmediately: true});
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const devicePushToken = await Notifications.getDevicePushTokenAsync();
|
|
235
|
+
const nextToken = normalizeText(devicePushToken?.data);
|
|
236
|
+
|
|
237
|
+
if (cancelled) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (!nextToken) {
|
|
242
|
+
await applyDeliveryPushToken('', {persistImmediately: true});
|
|
243
|
+
} else {
|
|
244
|
+
await applyDeliveryPushToken(nextToken, {persistImmediately: true});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (!pushTokenListenerRef.current) {
|
|
248
|
+
pushTokenListenerRef.current = Notifications.addPushTokenListener(
|
|
249
|
+
token => {
|
|
250
|
+
const nextListenerToken = normalizeText(token?.data);
|
|
251
|
+
if (!nextListenerToken) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
void applyDeliveryPushToken(nextListenerToken, {
|
|
256
|
+
persistImmediately: true,
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (!notificationResponseListenerRef.current) {
|
|
263
|
+
notificationResponseListenerRef.current =
|
|
264
|
+
Notifications.addNotificationResponseReceivedListener(response => {
|
|
265
|
+
const orderId = extractOrderIdFromResponse(response);
|
|
266
|
+
if (!orderId) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
queueNotificationNavigation('OrderDetails', {id: orderId});
|
|
271
|
+
|
|
272
|
+
if (typeof Notifications.clearLastNotificationResponseAsync === 'function') {
|
|
273
|
+
Notifications.clearLastNotificationResponseAsync().catch(() => {});
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (typeof Notifications.getLastNotificationResponseAsync === 'function') {
|
|
279
|
+
const lastResponse = await Notifications.getLastNotificationResponseAsync();
|
|
280
|
+
const orderId = extractOrderIdFromResponse(lastResponse);
|
|
281
|
+
|
|
282
|
+
if (!cancelled && orderId) {
|
|
283
|
+
queueNotificationNavigation('OrderDetails', {id: orderId});
|
|
284
|
+
|
|
285
|
+
if (typeof Notifications.clearLastNotificationResponseAsync === 'function') {
|
|
286
|
+
Notifications.clearLastNotificationResponseAsync().catch(() => {});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
configurePushSupport().catch(error => {
|
|
293
|
+
console.warn('Erro ao inicializar push nativo de Delivery', error);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
return () => {
|
|
297
|
+
cancelled = true;
|
|
298
|
+
|
|
299
|
+
if (pushTokenListenerRef.current) {
|
|
300
|
+
pushTokenListenerRef.current.remove();
|
|
301
|
+
pushTokenListenerRef.current = null;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (notificationResponseListenerRef.current) {
|
|
305
|
+
notificationResponseListenerRef.current.remove();
|
|
306
|
+
notificationResponseListenerRef.current = null;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
}, [applyDeliveryPushToken, device?.id, isDeliveryRuntime, isLogged, sessionChecked]);
|
|
310
|
+
|
|
311
|
+
return null;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
export default DeliveryPushBridge;
|