@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,388 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ActivityIndicator,
|
|
4
|
+
ScrollView,
|
|
5
|
+
Text,
|
|
6
|
+
TextInput,
|
|
7
|
+
TouchableOpacity,
|
|
8
|
+
View,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
11
|
+
import { useStore } from '@store';
|
|
12
|
+
import Formatter from '@controleonline/ui-common/src/utils/formatter';
|
|
13
|
+
import { useMessage } from '@controleonline/ui-common/src/react/components/MessageService';
|
|
14
|
+
import {
|
|
15
|
+
addProductsToOrder,
|
|
16
|
+
ensureLinkedOrder,
|
|
17
|
+
fetchLinkedOrder,
|
|
18
|
+
fetchOrderProducts,
|
|
19
|
+
isOpenCommercialOrder,
|
|
20
|
+
normalizeEntityId,
|
|
21
|
+
removeOrderProduct,
|
|
22
|
+
searchCompanyProducts,
|
|
23
|
+
updateOrderProductQuantity,
|
|
24
|
+
} from '@controleonline/ui-common/src/react/utils/commercialDocumentOrders';
|
|
25
|
+
import styles from './LinkedOrderProductsTab.styles';
|
|
26
|
+
|
|
27
|
+
const formatApiError = error => {
|
|
28
|
+
if (!error) return 'Nao foi possivel concluir a operacao.';
|
|
29
|
+
if (typeof error === 'string') return error;
|
|
30
|
+
if (Array.isArray(error?.message)) {
|
|
31
|
+
return error.message
|
|
32
|
+
.map(item => item?.message || item?.title || String(item))
|
|
33
|
+
.filter(Boolean)
|
|
34
|
+
.join('\n');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return error?.message || error?.description || error?.errmsg || 'Nao foi possivel concluir a operacao.';
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const resolveProductLabel = orderProduct => {
|
|
41
|
+
const product = orderProduct?.product;
|
|
42
|
+
return (
|
|
43
|
+
product?.product ||
|
|
44
|
+
product?.name ||
|
|
45
|
+
product?.description ||
|
|
46
|
+
orderProduct?.description ||
|
|
47
|
+
'Produto'
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const resolveProductSku = orderProduct =>
|
|
52
|
+
String(orderProduct?.product?.sku || orderProduct?.sku || '').trim();
|
|
53
|
+
|
|
54
|
+
const resolveQuantity = orderProduct => {
|
|
55
|
+
const parsed = Number(orderProduct?.quantity || 0);
|
|
56
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const LinkedOrderProductsTab = ({
|
|
60
|
+
contract,
|
|
61
|
+
canEdit,
|
|
62
|
+
emptyTitle = 'Nenhum produto adicionado.',
|
|
63
|
+
emptySubtitle = 'Voce pode vincular produtos a este documento quando precisar.',
|
|
64
|
+
searchPlaceholder = 'Buscar produto para adicionar...',
|
|
65
|
+
}) => {
|
|
66
|
+
const peopleStore = useStore('people');
|
|
67
|
+
const { currentCompany } = peopleStore.getters;
|
|
68
|
+
const { showError } = useMessage() || {};
|
|
69
|
+
|
|
70
|
+
const [order, setOrder] = useState(null);
|
|
71
|
+
const [orderProducts, setOrderProducts] = useState([]);
|
|
72
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
73
|
+
const [searchQuery, setSearchQuery] = useState('');
|
|
74
|
+
const [searchResults, setSearchResults] = useState([]);
|
|
75
|
+
const [searchLoading, setSearchLoading] = useState(false);
|
|
76
|
+
const [addingProductId, setAddingProductId] = useState(null);
|
|
77
|
+
const [updatingOrderProductId, setUpdatingOrderProductId] = useState(null);
|
|
78
|
+
|
|
79
|
+
const orderId = useMemo(
|
|
80
|
+
() => normalizeEntityId(order?.id || order?.['@id']),
|
|
81
|
+
[order?.id, order?.['@id']],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const canEditProducts = !!canEdit && !!contract?.['@id'] && (!order || isOpenCommercialOrder(order));
|
|
85
|
+
|
|
86
|
+
const loadLinkedOrderProducts = useCallback(async () => {
|
|
87
|
+
if (!contract?.['@id']) {
|
|
88
|
+
setOrder(null);
|
|
89
|
+
setOrderProducts([]);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setIsLoading(true);
|
|
94
|
+
try {
|
|
95
|
+
const linkedOrder = await fetchLinkedOrder(contract['@id']);
|
|
96
|
+
setOrder(linkedOrder);
|
|
97
|
+
|
|
98
|
+
if (linkedOrder) {
|
|
99
|
+
const items = await fetchOrderProducts(linkedOrder['@id'] || linkedOrder.id);
|
|
100
|
+
setOrderProducts(items);
|
|
101
|
+
} else {
|
|
102
|
+
setOrderProducts([]);
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
showError?.(formatApiError(error));
|
|
106
|
+
} finally {
|
|
107
|
+
setIsLoading(false);
|
|
108
|
+
}
|
|
109
|
+
}, [contract?.['@id'], showError]);
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
loadLinkedOrderProducts();
|
|
113
|
+
}, [loadLinkedOrderProducts]);
|
|
114
|
+
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
const trimmedQuery = String(searchQuery || '').trim();
|
|
117
|
+
|
|
118
|
+
if (!canEditProducts || !currentCompany?.id || !trimmedQuery) {
|
|
119
|
+
setSearchResults([]);
|
|
120
|
+
setSearchLoading(false);
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let cancelled = false;
|
|
125
|
+
const timeoutId = setTimeout(async () => {
|
|
126
|
+
setSearchLoading(true);
|
|
127
|
+
try {
|
|
128
|
+
const results = await searchCompanyProducts({
|
|
129
|
+
companyId: currentCompany.id,
|
|
130
|
+
query: trimmedQuery,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (!cancelled) {
|
|
134
|
+
setSearchResults(results);
|
|
135
|
+
}
|
|
136
|
+
} catch {
|
|
137
|
+
if (!cancelled) {
|
|
138
|
+
setSearchResults([]);
|
|
139
|
+
}
|
|
140
|
+
} finally {
|
|
141
|
+
if (!cancelled) {
|
|
142
|
+
setSearchLoading(false);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}, 250);
|
|
146
|
+
|
|
147
|
+
return () => {
|
|
148
|
+
cancelled = true;
|
|
149
|
+
clearTimeout(timeoutId);
|
|
150
|
+
};
|
|
151
|
+
}, [canEditProducts, currentCompany?.id, searchQuery]);
|
|
152
|
+
|
|
153
|
+
const ensureCurrentOrder = useCallback(async () => {
|
|
154
|
+
if (order) {
|
|
155
|
+
return order;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const createdOrder = await ensureLinkedOrder({
|
|
159
|
+
contractRef: contract?.['@id'],
|
|
160
|
+
provider: contract?.provider,
|
|
161
|
+
client: contract?.client,
|
|
162
|
+
payer: contract?.client,
|
|
163
|
+
app: 'CRM',
|
|
164
|
+
orderType: 'sale',
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
setOrder(createdOrder);
|
|
168
|
+
return createdOrder;
|
|
169
|
+
}, [contract?.['@id'], contract?.client, contract?.provider, order]);
|
|
170
|
+
|
|
171
|
+
const handleAddProduct = useCallback(async product => {
|
|
172
|
+
if (!canEditProducts || addingProductId) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const productId = normalizeEntityId(product);
|
|
177
|
+
if (!productId) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
setAddingProductId(productId);
|
|
182
|
+
try {
|
|
183
|
+
const currentOrder = await ensureCurrentOrder();
|
|
184
|
+
await addProductsToOrder({
|
|
185
|
+
orderId: currentOrder?.id || currentOrder?.['@id'],
|
|
186
|
+
products: [{ product: productId, quantity: 1 }],
|
|
187
|
+
});
|
|
188
|
+
setSearchQuery('');
|
|
189
|
+
setSearchResults([]);
|
|
190
|
+
await loadLinkedOrderProducts();
|
|
191
|
+
} catch (error) {
|
|
192
|
+
showError?.(formatApiError(error));
|
|
193
|
+
} finally {
|
|
194
|
+
setAddingProductId(null);
|
|
195
|
+
}
|
|
196
|
+
}, [addingProductId, canEditProducts, ensureCurrentOrder, loadLinkedOrderProducts, showError]);
|
|
197
|
+
|
|
198
|
+
const handleChangeQuantity = useCallback(async (orderProduct, nextQuantity) => {
|
|
199
|
+
if (updatingOrderProductId) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const orderProductId = normalizeEntityId(orderProduct);
|
|
204
|
+
if (!orderProductId) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
setUpdatingOrderProductId(orderProductId);
|
|
209
|
+
try {
|
|
210
|
+
if (nextQuantity <= 0) {
|
|
211
|
+
await removeOrderProduct(orderProductId);
|
|
212
|
+
} else {
|
|
213
|
+
await updateOrderProductQuantity({
|
|
214
|
+
orderProductId,
|
|
215
|
+
quantity: nextQuantity,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
await loadLinkedOrderProducts();
|
|
220
|
+
} catch (error) {
|
|
221
|
+
showError?.(formatApiError(error));
|
|
222
|
+
} finally {
|
|
223
|
+
setUpdatingOrderProductId(null);
|
|
224
|
+
}
|
|
225
|
+
}, [loadLinkedOrderProducts, showError, updatingOrderProductId]);
|
|
226
|
+
|
|
227
|
+
const visibleSearchResults = useMemo(() => {
|
|
228
|
+
const existingProductIds = new Set(
|
|
229
|
+
(Array.isArray(orderProducts) ? orderProducts : [])
|
|
230
|
+
.map(item => normalizeEntityId(item?.product))
|
|
231
|
+
.filter(Boolean),
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
return (Array.isArray(searchResults) ? searchResults : []).filter(
|
|
235
|
+
product => !existingProductIds.has(normalizeEntityId(product)),
|
|
236
|
+
);
|
|
237
|
+
}, [orderProducts, searchResults]);
|
|
238
|
+
|
|
239
|
+
return (
|
|
240
|
+
<ScrollView
|
|
241
|
+
style={styles.container}
|
|
242
|
+
contentContainerStyle={styles.content}
|
|
243
|
+
keyboardShouldPersistTaps="handled">
|
|
244
|
+
<View style={styles.section}>
|
|
245
|
+
<View style={styles.headerRow}>
|
|
246
|
+
<View>
|
|
247
|
+
<Text style={styles.title}>Produtos</Text>
|
|
248
|
+
<Text style={styles.subtitle}>
|
|
249
|
+
{orderId
|
|
250
|
+
? `Pedido vinculado #${orderId}`
|
|
251
|
+
: 'Os produtos deste documento sao guardados em um pedido vinculado.'}
|
|
252
|
+
</Text>
|
|
253
|
+
</View>
|
|
254
|
+
{isLoading && <ActivityIndicator size="small" color="#2529a1" />}
|
|
255
|
+
</View>
|
|
256
|
+
|
|
257
|
+
{canEditProducts && (
|
|
258
|
+
<View style={styles.searchWrap}>
|
|
259
|
+
<View style={styles.searchInputWrap}>
|
|
260
|
+
<Icon name="search" size={18} color="#64748B" />
|
|
261
|
+
<TextInput
|
|
262
|
+
value={searchQuery}
|
|
263
|
+
onChangeText={setSearchQuery}
|
|
264
|
+
placeholder={searchPlaceholder}
|
|
265
|
+
placeholderTextColor="#94A3B8"
|
|
266
|
+
style={styles.searchInput}
|
|
267
|
+
/>
|
|
268
|
+
{searchLoading && <ActivityIndicator size="small" color="#2529a1" />}
|
|
269
|
+
</View>
|
|
270
|
+
|
|
271
|
+
{String(searchQuery || '').trim().length > 0 && visibleSearchResults.map(product => {
|
|
272
|
+
const productId = normalizeEntityId(product);
|
|
273
|
+
const isAdding = addingProductId === productId;
|
|
274
|
+
return (
|
|
275
|
+
<TouchableOpacity
|
|
276
|
+
key={product?.['@id'] || productId}
|
|
277
|
+
style={styles.searchResultRow}
|
|
278
|
+
onPress={() => handleAddProduct(product)}
|
|
279
|
+
disabled={!!addingProductId}
|
|
280
|
+
activeOpacity={0.75}>
|
|
281
|
+
<View style={styles.searchResultBody}>
|
|
282
|
+
<Text style={styles.searchResultTitle} numberOfLines={1}>
|
|
283
|
+
{product?.product || 'Produto'}
|
|
284
|
+
</Text>
|
|
285
|
+
<Text style={styles.searchResultMeta}>
|
|
286
|
+
{Formatter.formatMoney(Number(product?.price || 0))}
|
|
287
|
+
</Text>
|
|
288
|
+
</View>
|
|
289
|
+
{isAdding ? (
|
|
290
|
+
<ActivityIndicator size="small" color="#2529a1" />
|
|
291
|
+
) : (
|
|
292
|
+
<Icon name="add-circle" size={22} color="#2529a1" />
|
|
293
|
+
)}
|
|
294
|
+
</TouchableOpacity>
|
|
295
|
+
);
|
|
296
|
+
})}
|
|
297
|
+
|
|
298
|
+
{String(searchQuery || '').trim().length > 0 && !searchLoading && visibleSearchResults.length === 0 && (
|
|
299
|
+
<Text style={styles.searchEmptyText}>Nenhum produto encontrado para esta busca.</Text>
|
|
300
|
+
)}
|
|
301
|
+
</View>
|
|
302
|
+
)}
|
|
303
|
+
|
|
304
|
+
{isLoading ? (
|
|
305
|
+
<View style={styles.emptyState}>
|
|
306
|
+
<ActivityIndicator size="large" color="#2529a1" />
|
|
307
|
+
<Text style={styles.emptySubtitle}>Carregando produtos...</Text>
|
|
308
|
+
</View>
|
|
309
|
+
) : orderProducts.length === 0 ? (
|
|
310
|
+
<View style={styles.emptyState}>
|
|
311
|
+
<Icon name="inventory-2" size={44} color="#CBD5E1" />
|
|
312
|
+
<Text style={styles.emptyTitle}>{emptyTitle}</Text>
|
|
313
|
+
<Text style={styles.emptySubtitle}>{emptySubtitle}</Text>
|
|
314
|
+
</View>
|
|
315
|
+
) : (
|
|
316
|
+
<View style={styles.listWrap}>
|
|
317
|
+
{orderProducts.map(orderProduct => {
|
|
318
|
+
const quantity = resolveQuantity(orderProduct);
|
|
319
|
+
const orderProductId = normalizeEntityId(orderProduct);
|
|
320
|
+
const isUpdating = updatingOrderProductId === orderProductId;
|
|
321
|
+
const sku = resolveProductSku(orderProduct);
|
|
322
|
+
|
|
323
|
+
return (
|
|
324
|
+
<View key={orderProduct?.['@id'] || orderProductId} style={styles.productCard}>
|
|
325
|
+
<View style={styles.productHeader}>
|
|
326
|
+
<View style={styles.productBody}>
|
|
327
|
+
<Text style={styles.productName} numberOfLines={2}>
|
|
328
|
+
{resolveProductLabel(orderProduct)}
|
|
329
|
+
</Text>
|
|
330
|
+
<Text style={styles.productMeta}>
|
|
331
|
+
{[sku ? `SKU ${sku}` : null, Formatter.formatMoney(Number(orderProduct?.price || 0))]
|
|
332
|
+
.filter(Boolean)
|
|
333
|
+
.join(' • ')}
|
|
334
|
+
</Text>
|
|
335
|
+
</View>
|
|
336
|
+
<Text style={styles.productTotal}>
|
|
337
|
+
{Formatter.formatMoney(Number(orderProduct?.total || 0))}
|
|
338
|
+
</Text>
|
|
339
|
+
</View>
|
|
340
|
+
|
|
341
|
+
{canEditProducts ? (
|
|
342
|
+
<View style={styles.actionsRow}>
|
|
343
|
+
<View style={styles.quantityWrap}>
|
|
344
|
+
<TouchableOpacity
|
|
345
|
+
style={styles.qtyButton}
|
|
346
|
+
onPress={() => handleChangeQuantity(orderProduct, quantity - 1)}
|
|
347
|
+
disabled={!!updatingOrderProductId}>
|
|
348
|
+
<Icon name="remove" size={18} color="#0F172A" />
|
|
349
|
+
</TouchableOpacity>
|
|
350
|
+
<View style={styles.qtyValueWrap}>
|
|
351
|
+
{isUpdating ? (
|
|
352
|
+
<ActivityIndicator size="small" color="#2529a1" />
|
|
353
|
+
) : (
|
|
354
|
+
<Text style={styles.qtyValue}>{quantity}</Text>
|
|
355
|
+
)}
|
|
356
|
+
</View>
|
|
357
|
+
<TouchableOpacity
|
|
358
|
+
style={styles.qtyButton}
|
|
359
|
+
onPress={() => handleChangeQuantity(orderProduct, quantity + 1)}
|
|
360
|
+
disabled={!!updatingOrderProductId}>
|
|
361
|
+
<Icon name="add" size={18} color="#0F172A" />
|
|
362
|
+
</TouchableOpacity>
|
|
363
|
+
</View>
|
|
364
|
+
|
|
365
|
+
<TouchableOpacity
|
|
366
|
+
style={styles.removeButton}
|
|
367
|
+
onPress={() => handleChangeQuantity(orderProduct, 0)}
|
|
368
|
+
disabled={!!updatingOrderProductId}>
|
|
369
|
+
<Icon name="delete-outline" size={18} color="#DC2626" />
|
|
370
|
+
<Text style={styles.removeButtonText}>Remover</Text>
|
|
371
|
+
</TouchableOpacity>
|
|
372
|
+
</View>
|
|
373
|
+
) : (
|
|
374
|
+
<View style={styles.readonlyMetaWrap}>
|
|
375
|
+
<Text style={styles.readonlyMetaText}>Quantidade: {quantity}</Text>
|
|
376
|
+
</View>
|
|
377
|
+
)}
|
|
378
|
+
</View>
|
|
379
|
+
);
|
|
380
|
+
})}
|
|
381
|
+
</View>
|
|
382
|
+
)}
|
|
383
|
+
</View>
|
|
384
|
+
</ScrollView>
|
|
385
|
+
);
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
export default LinkedOrderProductsTab;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const styles = StyleSheet.create({
|
|
4
|
+
container: {
|
|
5
|
+
flex: 1,
|
|
6
|
+
},
|
|
7
|
+
content: {
|
|
8
|
+
padding: 16,
|
|
9
|
+
paddingBottom: 36,
|
|
10
|
+
},
|
|
11
|
+
section: {
|
|
12
|
+
backgroundColor: '#FFFFFF',
|
|
13
|
+
borderRadius: 14,
|
|
14
|
+
padding: 16,
|
|
15
|
+
},
|
|
16
|
+
headerRow: {
|
|
17
|
+
flexDirection: 'row',
|
|
18
|
+
justifyContent: 'space-between',
|
|
19
|
+
alignItems: 'center',
|
|
20
|
+
marginBottom: 16,
|
|
21
|
+
},
|
|
22
|
+
title: {
|
|
23
|
+
fontSize: 18,
|
|
24
|
+
fontWeight: '700',
|
|
25
|
+
color: '#0F172A',
|
|
26
|
+
},
|
|
27
|
+
subtitle: {
|
|
28
|
+
marginTop: 4,
|
|
29
|
+
fontSize: 13,
|
|
30
|
+
color: '#64748B',
|
|
31
|
+
},
|
|
32
|
+
searchWrap: {
|
|
33
|
+
marginBottom: 16,
|
|
34
|
+
},
|
|
35
|
+
searchInputWrap: {
|
|
36
|
+
flexDirection: 'row',
|
|
37
|
+
alignItems: 'center',
|
|
38
|
+
borderWidth: 1,
|
|
39
|
+
borderColor: '#E2E8F0',
|
|
40
|
+
borderRadius: 12,
|
|
41
|
+
paddingHorizontal: 12,
|
|
42
|
+
backgroundColor: '#F8FAFC',
|
|
43
|
+
},
|
|
44
|
+
searchInput: {
|
|
45
|
+
flex: 1,
|
|
46
|
+
minHeight: 48,
|
|
47
|
+
color: '#0F172A',
|
|
48
|
+
fontSize: 15,
|
|
49
|
+
paddingHorizontal: 10,
|
|
50
|
+
},
|
|
51
|
+
searchResultRow: {
|
|
52
|
+
marginTop: 8,
|
|
53
|
+
padding: 12,
|
|
54
|
+
borderWidth: 1,
|
|
55
|
+
borderColor: '#E2E8F0',
|
|
56
|
+
borderRadius: 12,
|
|
57
|
+
flexDirection: 'row',
|
|
58
|
+
alignItems: 'center',
|
|
59
|
+
backgroundColor: '#FFFFFF',
|
|
60
|
+
},
|
|
61
|
+
searchResultBody: {
|
|
62
|
+
flex: 1,
|
|
63
|
+
},
|
|
64
|
+
searchResultTitle: {
|
|
65
|
+
fontSize: 15,
|
|
66
|
+
fontWeight: '600',
|
|
67
|
+
color: '#0F172A',
|
|
68
|
+
},
|
|
69
|
+
searchResultMeta: {
|
|
70
|
+
marginTop: 2,
|
|
71
|
+
fontSize: 13,
|
|
72
|
+
color: '#64748B',
|
|
73
|
+
},
|
|
74
|
+
searchEmptyText: {
|
|
75
|
+
marginTop: 10,
|
|
76
|
+
fontSize: 13,
|
|
77
|
+
color: '#94A3B8',
|
|
78
|
+
},
|
|
79
|
+
emptyState: {
|
|
80
|
+
alignItems: 'center',
|
|
81
|
+
paddingVertical: 28,
|
|
82
|
+
},
|
|
83
|
+
emptyTitle: {
|
|
84
|
+
marginTop: 12,
|
|
85
|
+
fontSize: 16,
|
|
86
|
+
fontWeight: '700',
|
|
87
|
+
color: '#0F172A',
|
|
88
|
+
textAlign: 'center',
|
|
89
|
+
},
|
|
90
|
+
emptySubtitle: {
|
|
91
|
+
marginTop: 8,
|
|
92
|
+
fontSize: 14,
|
|
93
|
+
lineHeight: 20,
|
|
94
|
+
color: '#64748B',
|
|
95
|
+
textAlign: 'center',
|
|
96
|
+
},
|
|
97
|
+
listWrap: {
|
|
98
|
+
marginTop: 4,
|
|
99
|
+
},
|
|
100
|
+
productCard: {
|
|
101
|
+
borderWidth: 1,
|
|
102
|
+
borderColor: '#E2E8F0',
|
|
103
|
+
borderRadius: 14,
|
|
104
|
+
padding: 14,
|
|
105
|
+
marginBottom: 12,
|
|
106
|
+
backgroundColor: '#FFFFFF',
|
|
107
|
+
},
|
|
108
|
+
productHeader: {
|
|
109
|
+
flexDirection: 'row',
|
|
110
|
+
alignItems: 'flex-start',
|
|
111
|
+
},
|
|
112
|
+
productBody: {
|
|
113
|
+
flex: 1,
|
|
114
|
+
},
|
|
115
|
+
productName: {
|
|
116
|
+
fontSize: 15,
|
|
117
|
+
fontWeight: '700',
|
|
118
|
+
color: '#0F172A',
|
|
119
|
+
},
|
|
120
|
+
productMeta: {
|
|
121
|
+
marginTop: 4,
|
|
122
|
+
fontSize: 13,
|
|
123
|
+
color: '#64748B',
|
|
124
|
+
},
|
|
125
|
+
productTotal: {
|
|
126
|
+
marginLeft: 12,
|
|
127
|
+
fontSize: 15,
|
|
128
|
+
fontWeight: '700',
|
|
129
|
+
color: '#2529a1',
|
|
130
|
+
},
|
|
131
|
+
actionsRow: {
|
|
132
|
+
marginTop: 14,
|
|
133
|
+
flexDirection: 'row',
|
|
134
|
+
justifyContent: 'space-between',
|
|
135
|
+
alignItems: 'center',
|
|
136
|
+
},
|
|
137
|
+
quantityWrap: {
|
|
138
|
+
flexDirection: 'row',
|
|
139
|
+
alignItems: 'center',
|
|
140
|
+
},
|
|
141
|
+
qtyButton: {
|
|
142
|
+
width: 34,
|
|
143
|
+
height: 34,
|
|
144
|
+
borderRadius: 10,
|
|
145
|
+
borderWidth: 1,
|
|
146
|
+
borderColor: '#CBD5E1',
|
|
147
|
+
alignItems: 'center',
|
|
148
|
+
justifyContent: 'center',
|
|
149
|
+
backgroundColor: '#F8FAFC',
|
|
150
|
+
},
|
|
151
|
+
qtyValueWrap: {
|
|
152
|
+
minWidth: 50,
|
|
153
|
+
alignItems: 'center',
|
|
154
|
+
justifyContent: 'center',
|
|
155
|
+
},
|
|
156
|
+
qtyValue: {
|
|
157
|
+
fontSize: 16,
|
|
158
|
+
fontWeight: '700',
|
|
159
|
+
color: '#0F172A',
|
|
160
|
+
},
|
|
161
|
+
removeButton: {
|
|
162
|
+
flexDirection: 'row',
|
|
163
|
+
alignItems: 'center',
|
|
164
|
+
},
|
|
165
|
+
removeButtonText: {
|
|
166
|
+
marginLeft: 4,
|
|
167
|
+
fontSize: 13,
|
|
168
|
+
fontWeight: '600',
|
|
169
|
+
color: '#DC2626',
|
|
170
|
+
},
|
|
171
|
+
readonlyMetaWrap: {
|
|
172
|
+
marginTop: 12,
|
|
173
|
+
},
|
|
174
|
+
readonlyMetaText: {
|
|
175
|
+
fontSize: 14,
|
|
176
|
+
color: '#475569',
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
export default styles;
|