@controleonline/ui-crm 1.0.42
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/actions/workers/manager/action.yml +147 -0
- package/.github/actions/workers/qa/action.yml +44 -0
- package/.github/actions/workers/security/action.yml +44 -0
- package/.github/actions/workers/technical-documenter/action.yml +51 -0
- package/.github/workflows/manager-worker.yml +167 -0
- package/.github/workflows/publish-npm.yml +40 -0
- package/.github/workflows/pull-request-checks.yml +29 -0
- package/.scrutinizer.yml +24 -0
- package/AGENTS.md +56 -0
- package/FUNDING.yml +1 -0
- package/docs/technical/Cliente-Vendedor-Vinculo-e-Permissoes.md +121 -0
- package/docs/technical/Income-Statements-Demonstrativo.md +38 -0
- package/docs/technical/Oportunidades-Ordenacao-por-Data-de-Retorno.md +134 -0
- package/docs/technical/Propostas-Filtro-de-Status.md +147 -0
- package/docs/technical/Royalties-a-pagar-Franqueado.md +51 -0
- package/docs/technical/Visao-Vendedor-Comissoes.md +58 -0
- package/docs/wiki.md +1 -0
- package/package.json +43 -0
- package/scripts/validate-wiki-pointer.cjs +13 -0
- package/src/react/components/AnimatedModal.js +149 -0
- package/src/react/components/AnimatedModal.styles.js +21 -0
- package/src/react/components/CreateContractModal.js +151 -0
- package/src/react/components/CreateContractModal.styles.js +43 -0
- package/src/react/hooks/useToastMessage.js +59 -0
- package/src/react/index.js +4 -0
- package/src/react/pages/ModelTemplatesPage.js +1461 -0
- package/src/react/pages/ModelTemplatesPage.styles.js +441 -0
- package/src/react/pages/comissions/IncomeStatementDetailsModal.js +102 -0
- package/src/react/pages/comissions/IncomeStatementsFilters.js +120 -0
- package/src/react/pages/comissions/SellerCommissionsPage.js +368 -0
- package/src/react/pages/comissions/SellerCommissionsPage.styles.js +219 -0
- package/src/react/pages/comissions/incomeStatementsHelpers.js +233 -0
- package/src/react/pages/comissions/index.js +309 -0
- package/src/react/pages/comissions/index.styles.js +381 -0
- package/src/react/pages/comissions/sellerCommissionsHelpers.js +222 -0
- package/src/react/pages/crm/components/CrmHeader.js +117 -0
- package/src/react/pages/crm/components/MarketingEventsSection.js +142 -0
- package/src/react/pages/crm/components/MarketingEventsSection.styles.js +105 -0
- package/src/react/pages/crm/components/OpportunityCard.js +138 -0
- package/src/react/pages/crm/components/OpportunityFormModal.js +279 -0
- package/src/react/pages/crm/components/OpportunityList.js +113 -0
- package/src/react/pages/crm/components/OpportunitySkeletons.js +53 -0
- package/src/react/pages/crm/components/ProviderSelectModal.js +166 -0
- package/src/react/pages/crm/components/SelectModal.js +178 -0
- package/src/react/pages/crm/conversation.js +342 -0
- package/src/react/pages/crm/conversation.styles.js +206 -0
- package/src/react/pages/crm/hooks/useCrmData.js +494 -0
- package/src/react/pages/crm/hooks/useOpportunityForms.js +306 -0
- package/src/react/pages/crm/index.js +262 -0
- package/src/react/pages/crm/index.styles.js +13 -0
- package/src/react/pages/crm/marketingEventsHelpers.js +41 -0
- package/src/react/pages/crm/styles/card.styles.js +178 -0
- package/src/react/pages/crm/styles/layout.styles.js +184 -0
- package/src/react/pages/crm/styles/modal.styles.js +347 -0
- package/src/react/pages/home/index.js +559 -0
- package/src/react/pages/home/index.styles.js +268 -0
- package/src/react/pages/proposals/CreateProposalsModal.js +466 -0
- package/src/react/pages/proposals/CreateProposalsModal.styles.js +344 -0
- package/src/react/pages/proposals/CreateProposalsPickers.js +187 -0
- package/src/react/pages/proposals/CreateProposalsProductSection.js +117 -0
- package/src/react/pages/proposals/ProposalCard.js +112 -0
- package/src/react/pages/proposals/ProposalDetails.js +263 -0
- package/src/react/pages/proposals/ProposalDetails.styles.js +195 -0
- package/src/react/pages/proposals/index.js +488 -0
- package/src/react/pages/proposals/index.styles.js +248 -0
- package/src/react/pages/proposals/proposalListHelpers.js +216 -0
- package/src/react/pages/proposals/proposalNavigation.js +26 -0
- package/src/react/pages/royalties/ReceivablePage.js +233 -0
- package/src/react/pages/royalties/RoyaltiesPayablePage.js +260 -0
- package/src/react/pages/royalties/index.js +2 -0
- package/src/react/pages/royalties/royaltiesReceivableHelpers.js +68 -0
- package/src/react/pages/settings/GeneralSettings.js +317 -0
- package/src/react/pages/settings/GeneralSettings.shared.js +490 -0
- package/src/react/pages/settings/GeneralSettings.styles.js +746 -0
- package/src/react/pages/settings/GeneralSettingsSection.js +57 -0
- package/src/react/pages/settings/generalSettingsActiveTab.js +85 -0
- package/src/react/pages/settings/sections/CrmSection.js +281 -0
- package/src/react/pages/settings/sections/DeviceRuntimeFooterSection.js +128 -0
- package/src/react/pages/settings/sections/DisplayPreparationSection.js +155 -0
- package/src/react/pages/settings/sections/IntegrationsSection.js +392 -0
- package/src/react/pages/settings/sections/LogSection.js +322 -0
- package/src/react/pages/settings/sections/LoginSection.js +137 -0
- package/src/react/pages/settings/sections/LoyaltyProductPicker.js +230 -0
- package/src/react/pages/settings/sections/LoyaltySection.js +451 -0
- package/src/react/pages/settings/sections/MaintenanceSection.js +205 -0
- package/src/react/pages/settings/sections/MapsSection.js +629 -0
- package/src/react/pages/settings/sections/MenuCatalogSection.js +405 -0
- package/src/react/pages/settings/sections/OperationsSection.js +303 -0
- package/src/react/pages/settings/sections/OrderPaymentSection.js +379 -0
- package/src/react/pages/settings/sections/OrderPrintSection.js +308 -0
- package/src/react/pages/settings/sections/ShopSection.js +490 -0
- package/src/react/pages/settings/sections/shop/FranchiseMapPreview.js +124 -0
- package/src/react/pages/settings/sections/shop/ShopDomainCreateForm.js +57 -0
- package/src/react/pages/settings/sections/shop/ShopDomainPanel.js +184 -0
- package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.js +237 -0
- package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.styles.js +256 -0
- package/src/react/pages/settings/sections/shop/ShopDomainTabs.js +61 -0
- package/src/react/pages/settings/sections/shop/ShopFranchiseLocatorSection.js +526 -0
- package/src/react/pages/settings/sections/shop/ShopLoyaltySection.js +426 -0
- package/src/react/pages/settings/sections/shop/ShopSettingsSection.js +10 -0
- package/src/react/pages/settings/sections/shop/mapsFranchiseMapHelpers.js +163 -0
- package/src/react/pages/settings/sections/shop/shopDomainShowcasesUtils.js +68 -0
- package/src/react/pages/settings/sections/shop/shopFranchiseVisibility.js +158 -0
- package/src/react/pages/settings/sections/shop/shopSettingsShared.js +427 -0
- package/src/react/router/routes.js +135 -0
- package/src/react/utils/opportunityDate.js +82 -0
- package/src/react/utils/opportunityEditorReferences.js +76 -0
- package/src/react/utils/opportunityEmptyState.js +20 -0
- package/src/react/utils/opportunityPeople.js +111 -0
- package/src/react/utils/opportunityPhone.js +82 -0
- package/src/react/utils/opportunityStage.js +30 -0
- package/src/react/utils/opportunityStatusFilter.js +54 -0
- package/src/react/utils/proposalCreateHelpers.js +61 -0
- package/src/react/utils/proposalProductSelection.js +71 -0
- package/src/react/utils/royaltiesPayableParams.js +37 -0
- package/src/react/utils/translateWithFallback.js +42 -0
- package/src/store/crm/index.js +2 -0
- package/src/store/model/index.js +104 -0
- package/src/tests/browser/crm/create-proposal-product-category-filter.spec.js +149 -0
- package/src/tests/browser/crm/crm-index-status-filter.spec.js +263 -0
- package/src/tests/browser/crm/crm-opportunity-category-editor.spec.js +269 -0
- package/src/tests/browser/crm/royalties-payable.spec.js +122 -0
- package/src/tests/browser/crm/royalties-receivable.spec.js +121 -0
- package/src/tests/browser/crm/seller-commissions.spec.js +214 -0
- package/src/tests/browser/manager/general-settings-maps.spec.js +400 -0
- package/src/tests/react/pages/comissions/incomeStatementsHelpers.test.js +181 -0
- package/src/tests/react/pages/comissions/sellerCommissionsHelpers.test.js +132 -0
- package/src/tests/react/pages/crm/marketingEventsHelpers.test.cjs +53 -0
- package/src/tests/react/pages/crm/opportunitySearchParams.test.cjs +44 -0
- package/src/tests/react/pages/proposals/navigation.test.js +71 -0
- package/src/tests/react/pages/proposals/proposalListHelpers.test.js +42 -0
- package/src/tests/react/pages/royalties/royaltiesReceivableHelpers.test.js +60 -0
- package/src/tests/react/pages/settings/generalSettings.shared.test.js +102 -0
- package/src/tests/react/pages/settings/sections/shop/shopDomainShowcasesUtils.test.js +60 -0
- package/src/tests/react/pages/settings/sections/shop/shopFranchiseVisibility.test.js +80 -0
- package/src/tests/react/utils/opportunityEditorReferences.test.js +70 -0
- package/src/tests/react/utils/opportunityEmptyState.test.js +39 -0
- package/src/tests/react/utils/opportunityStatusFilter.test.cjs +81 -0
- package/src/tests/react/utils/proposalCreateHelpers.test.js +25 -0
- package/src/tests/react/utils/proposalProductSelection.test.js +76 -0
- package/src/tests/react/utils/royaltiesPayableParams.test.js +44 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents This section controls remote payment routing and terminal ordering.
|
|
3
|
+
* Keep the visible list and save behavior tied to the shared device config store.
|
|
4
|
+
*/
|
|
5
|
+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
6
|
+
import {
|
|
7
|
+
ActivityIndicator,
|
|
8
|
+
Alert,
|
|
9
|
+
Text,
|
|
10
|
+
TouchableOpacity,
|
|
11
|
+
View,
|
|
12
|
+
} from 'react-native';
|
|
13
|
+
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
filterDeviceConfigsByCompany,
|
|
17
|
+
getCompanyPaymentDeviceOptions,
|
|
18
|
+
isOrderChargeOnDeliveryEnabled,
|
|
19
|
+
isOrderPaymentDeviceChangeAllowed,
|
|
20
|
+
ORDER_CHARGE_ON_DELIVERY_ENABLED_CONFIG_KEY,
|
|
21
|
+
ORDER_PAYMENT_DEVICE_CHANGE_ALLOWED_CONFIG_KEY,
|
|
22
|
+
ORDER_PAYMENT_DEVICES_CONFIG_KEY,
|
|
23
|
+
normalizeDeviceIds,
|
|
24
|
+
} from '@controleonline/ui-common/src/react/utils/paymentDevices';
|
|
25
|
+
import {useStore} from '@store';
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
useGeneralSettingsPalette,
|
|
29
|
+
useGeneralSettingsStyles,
|
|
30
|
+
} from '../GeneralSettings.styles';
|
|
31
|
+
import GeneralSettingsSection from '../GeneralSettingsSection';
|
|
32
|
+
import {useGeneralSettingsConfig} from '../GeneralSettings.shared';
|
|
33
|
+
|
|
34
|
+
const OrderPaymentSection = () => {
|
|
35
|
+
const localStyles = useGeneralSettingsStyles();
|
|
36
|
+
const themePalette = useGeneralSettingsPalette();
|
|
37
|
+
const {currentCompany, effectiveCompanyConfigs, saveConfigs} =
|
|
38
|
+
useGeneralSettingsConfig();
|
|
39
|
+
|
|
40
|
+
const deviceConfigStore = useStore('device_config');
|
|
41
|
+
const {
|
|
42
|
+
items: companyDeviceConfigs = [],
|
|
43
|
+
isLoading: isLoadingDeviceConfigs,
|
|
44
|
+
} = deviceConfigStore.getters;
|
|
45
|
+
const deviceConfigActions = deviceConfigStore.actions;
|
|
46
|
+
|
|
47
|
+
const [orderPaymentEnabled, setOrderPaymentEnabled] = useState(false);
|
|
48
|
+
const [orderPaymentDevices, setOrderPaymentDevices] = useState([]);
|
|
49
|
+
const [chargeOnDeliveryEnabled, setChargeOnDeliveryEnabled] = useState(false);
|
|
50
|
+
const [allowPaymentDeviceChange, setAllowPaymentDeviceChange] =
|
|
51
|
+
useState(false);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const nextOrderPaymentDevices = normalizeDeviceIds(
|
|
55
|
+
effectiveCompanyConfigs[ORDER_PAYMENT_DEVICES_CONFIG_KEY],
|
|
56
|
+
);
|
|
57
|
+
setOrderPaymentDevices(nextOrderPaymentDevices);
|
|
58
|
+
setOrderPaymentEnabled(nextOrderPaymentDevices.length > 0);
|
|
59
|
+
setChargeOnDeliveryEnabled(
|
|
60
|
+
isOrderChargeOnDeliveryEnabled(effectiveCompanyConfigs),
|
|
61
|
+
);
|
|
62
|
+
setAllowPaymentDeviceChange(
|
|
63
|
+
isOrderPaymentDeviceChangeAllowed(effectiveCompanyConfigs),
|
|
64
|
+
);
|
|
65
|
+
}, [effectiveCompanyConfigs]);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!currentCompany?.id) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
deviceConfigActions
|
|
73
|
+
.getItems({people: '/people/' + currentCompany.id})
|
|
74
|
+
.catch(() => {});
|
|
75
|
+
}, [currentCompany?.id, deviceConfigActions]);
|
|
76
|
+
|
|
77
|
+
const scopedCompanyDeviceConfigs = useMemo(
|
|
78
|
+
() =>
|
|
79
|
+
filterDeviceConfigsByCompany(companyDeviceConfigs, currentCompany?.id),
|
|
80
|
+
[companyDeviceConfigs, currentCompany?.id],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const paymentDevices = useMemo(
|
|
84
|
+
() => getCompanyPaymentDeviceOptions(scopedCompanyDeviceConfigs),
|
|
85
|
+
[scopedCompanyDeviceConfigs],
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const selectedPaymentDeviceCount = orderPaymentDevices.length;
|
|
89
|
+
|
|
90
|
+
const saveOrderPaymentSettings = useCallback(
|
|
91
|
+
async ({
|
|
92
|
+
nextAllowPaymentDeviceChange = allowPaymentDeviceChange,
|
|
93
|
+
nextChargeOnDeliveryEnabled = chargeOnDeliveryEnabled,
|
|
94
|
+
nextOrderPaymentDevices = orderPaymentDevices,
|
|
95
|
+
nextOrderPaymentEnabled = orderPaymentEnabled,
|
|
96
|
+
} = {}) => {
|
|
97
|
+
const normalizedDevices = nextOrderPaymentDevices
|
|
98
|
+
.map(item => String(item || '').trim())
|
|
99
|
+
.filter(Boolean);
|
|
100
|
+
|
|
101
|
+
if (nextOrderPaymentEnabled && normalizedDevices.length === 0) {
|
|
102
|
+
Alert.alert(
|
|
103
|
+
'Pagamento remoto',
|
|
104
|
+
'Selecione pelo menos um device para ativar o pagamento remoto de pedidos.',
|
|
105
|
+
);
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
await saveConfigs({
|
|
110
|
+
[ORDER_PAYMENT_DEVICES_CONFIG_KEY]: nextOrderPaymentEnabled
|
|
111
|
+
? normalizedDevices
|
|
112
|
+
: [],
|
|
113
|
+
[ORDER_PAYMENT_DEVICE_CHANGE_ALLOWED_CONFIG_KEY]:
|
|
114
|
+
nextAllowPaymentDeviceChange,
|
|
115
|
+
[ORDER_CHARGE_ON_DELIVERY_ENABLED_CONFIG_KEY]:
|
|
116
|
+
nextChargeOnDeliveryEnabled,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return true;
|
|
120
|
+
},
|
|
121
|
+
[
|
|
122
|
+
allowPaymentDeviceChange,
|
|
123
|
+
chargeOnDeliveryEnabled,
|
|
124
|
+
orderPaymentDevices,
|
|
125
|
+
orderPaymentEnabled,
|
|
126
|
+
saveConfigs,
|
|
127
|
+
],
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const toggleOrderPaymentEnabled = useCallback(() => {
|
|
131
|
+
const nextEnabled = !orderPaymentEnabled;
|
|
132
|
+
|
|
133
|
+
if (!nextEnabled) {
|
|
134
|
+
setOrderPaymentEnabled(false);
|
|
135
|
+
setOrderPaymentDevices([]);
|
|
136
|
+
saveOrderPaymentSettings({
|
|
137
|
+
nextOrderPaymentDevices: [],
|
|
138
|
+
nextOrderPaymentEnabled: false,
|
|
139
|
+
});
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (orderPaymentDevices.length === 0) {
|
|
144
|
+
Alert.alert(
|
|
145
|
+
'Pagamento remoto',
|
|
146
|
+
'Selecione pelo menos um device para ativar o pagamento remoto de pedidos.',
|
|
147
|
+
);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
setOrderPaymentEnabled(true);
|
|
152
|
+
saveOrderPaymentSettings({
|
|
153
|
+
nextOrderPaymentEnabled: true,
|
|
154
|
+
});
|
|
155
|
+
}, [orderPaymentDevices.length, orderPaymentEnabled, saveOrderPaymentSettings]);
|
|
156
|
+
|
|
157
|
+
const toggleOrderPaymentDevice = useCallback(
|
|
158
|
+
deviceId => {
|
|
159
|
+
if (!deviceId) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const nextOrderPaymentDevices = orderPaymentDevices.includes(deviceId)
|
|
164
|
+
? orderPaymentDevices.filter(item => item !== deviceId)
|
|
165
|
+
: [...orderPaymentDevices, deviceId];
|
|
166
|
+
const nextOrderPaymentEnabled = nextOrderPaymentDevices.length > 0;
|
|
167
|
+
|
|
168
|
+
setOrderPaymentDevices(nextOrderPaymentDevices);
|
|
169
|
+
setOrderPaymentEnabled(nextOrderPaymentEnabled);
|
|
170
|
+
saveOrderPaymentSettings({
|
|
171
|
+
nextOrderPaymentDevices,
|
|
172
|
+
nextOrderPaymentEnabled,
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
[orderPaymentDevices, saveOrderPaymentSettings],
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<GeneralSettingsSection
|
|
180
|
+
description="Define a ordem padrao dos terminais com gateway local que podem receber cobrancas remotas. Esse destino atende manager web, celulares e tambem PDVs Android quando o operador escolhe cobrar em outro terminal pela barra unica."
|
|
181
|
+
icon="credit-card"
|
|
182
|
+
iconBackgroundColor={themePalette.cardIconBackground}
|
|
183
|
+
iconColor={themePalette.cardIconColor}
|
|
184
|
+
title="Pagamento remoto de pedidos">
|
|
185
|
+
<View style={localStyles.statusRow}>
|
|
186
|
+
<Text style={localStyles.statusLabel}>Pagamento padrao</Text>
|
|
187
|
+
<TouchableOpacity
|
|
188
|
+
style={[
|
|
189
|
+
localStyles.statusChip,
|
|
190
|
+
orderPaymentEnabled
|
|
191
|
+
? localStyles.statusChipEnabled
|
|
192
|
+
: localStyles.statusChipDisabled,
|
|
193
|
+
]}
|
|
194
|
+
activeOpacity={0.85}
|
|
195
|
+
onPress={toggleOrderPaymentEnabled}>
|
|
196
|
+
<Icon
|
|
197
|
+
name={orderPaymentEnabled ? 'check-circle' : 'block'}
|
|
198
|
+
size={16}
|
|
199
|
+
color={
|
|
200
|
+
orderPaymentEnabled
|
|
201
|
+
? themePalette.badgeSelectedText
|
|
202
|
+
: themePalette.badgeDisabledText
|
|
203
|
+
}
|
|
204
|
+
/>
|
|
205
|
+
<Text
|
|
206
|
+
style={[
|
|
207
|
+
localStyles.statusChipText,
|
|
208
|
+
{
|
|
209
|
+
color: orderPaymentEnabled
|
|
210
|
+
? themePalette.badgeSelectedText
|
|
211
|
+
: themePalette.badgeDisabledText,
|
|
212
|
+
},
|
|
213
|
+
]}>
|
|
214
|
+
{orderPaymentEnabled ? 'Ativado' : 'Desativado'}
|
|
215
|
+
</Text>
|
|
216
|
+
</TouchableOpacity>
|
|
217
|
+
</View>
|
|
218
|
+
|
|
219
|
+
<Text style={localStyles.helperText}>
|
|
220
|
+
{orderPaymentEnabled
|
|
221
|
+
? `${selectedPaymentDeviceCount} device(s) configurado(s). O primeiro vira o equipamento padrao do pagamento remoto.`
|
|
222
|
+
: 'Quando desativado, a barra unica nao oferece destino remoto padrao para manager, celulares e PDVs Android.'}
|
|
223
|
+
</Text>
|
|
224
|
+
|
|
225
|
+
<View style={localStyles.settingRow}>
|
|
226
|
+
<View style={localStyles.settingCopy}>
|
|
227
|
+
<Text style={localStyles.statusLabel}>
|
|
228
|
+
Pode trocar de equipamento no pagamento?
|
|
229
|
+
</Text>
|
|
230
|
+
<Text style={localStyles.settingDescription}>
|
|
231
|
+
Quando desativado, o checkout remoto usa sempre o primeiro device
|
|
232
|
+
configurado acima. Quando ativado, o operador pode trocar o
|
|
233
|
+
equipamento na hora do pagamento.
|
|
234
|
+
</Text>
|
|
235
|
+
</View>
|
|
236
|
+
<TouchableOpacity
|
|
237
|
+
style={[
|
|
238
|
+
localStyles.statusChip,
|
|
239
|
+
allowPaymentDeviceChange
|
|
240
|
+
? localStyles.statusChipEnabled
|
|
241
|
+
: localStyles.statusChipDisabled,
|
|
242
|
+
]}
|
|
243
|
+
activeOpacity={0.85}
|
|
244
|
+
onPress={() => {
|
|
245
|
+
const nextValue = !allowPaymentDeviceChange;
|
|
246
|
+
setAllowPaymentDeviceChange(nextValue);
|
|
247
|
+
saveOrderPaymentSettings({
|
|
248
|
+
nextAllowPaymentDeviceChange: nextValue,
|
|
249
|
+
});
|
|
250
|
+
}}>
|
|
251
|
+
<Icon
|
|
252
|
+
name={allowPaymentDeviceChange ? 'check-circle' : 'block'}
|
|
253
|
+
size={16}
|
|
254
|
+
color={
|
|
255
|
+
allowPaymentDeviceChange
|
|
256
|
+
? themePalette.badgeSelectedText
|
|
257
|
+
: themePalette.badgeDisabledText
|
|
258
|
+
}
|
|
259
|
+
/>
|
|
260
|
+
<Text
|
|
261
|
+
style={[
|
|
262
|
+
localStyles.statusChipText,
|
|
263
|
+
{
|
|
264
|
+
color: allowPaymentDeviceChange
|
|
265
|
+
? themePalette.badgeSelectedText
|
|
266
|
+
: themePalette.badgeDisabledText,
|
|
267
|
+
},
|
|
268
|
+
]}>
|
|
269
|
+
{allowPaymentDeviceChange ? 'Ativado' : 'Desativado'}
|
|
270
|
+
</Text>
|
|
271
|
+
</TouchableOpacity>
|
|
272
|
+
</View>
|
|
273
|
+
|
|
274
|
+
<View style={localStyles.settingRow}>
|
|
275
|
+
<View style={localStyles.settingCopy}>
|
|
276
|
+
<Text style={localStyles.statusLabel}>Cobrar na entrega</Text>
|
|
277
|
+
<Text style={localStyles.settingDescription}>
|
|
278
|
+
Libera na barra unica de pagamentos a opcao de registrar o pedido
|
|
279
|
+
para cobrar manualmente na entrega.
|
|
280
|
+
</Text>
|
|
281
|
+
</View>
|
|
282
|
+
<TouchableOpacity
|
|
283
|
+
style={[
|
|
284
|
+
localStyles.statusChip,
|
|
285
|
+
chargeOnDeliveryEnabled
|
|
286
|
+
? localStyles.statusChipEnabled
|
|
287
|
+
: localStyles.statusChipDisabled,
|
|
288
|
+
]}
|
|
289
|
+
activeOpacity={0.85}
|
|
290
|
+
onPress={() => {
|
|
291
|
+
const nextValue = !chargeOnDeliveryEnabled;
|
|
292
|
+
setChargeOnDeliveryEnabled(nextValue);
|
|
293
|
+
saveOrderPaymentSettings({
|
|
294
|
+
nextChargeOnDeliveryEnabled: nextValue,
|
|
295
|
+
});
|
|
296
|
+
}}>
|
|
297
|
+
<Icon
|
|
298
|
+
name={chargeOnDeliveryEnabled ? 'check-circle' : 'block'}
|
|
299
|
+
size={16}
|
|
300
|
+
color={
|
|
301
|
+
chargeOnDeliveryEnabled
|
|
302
|
+
? themePalette.badgeSelectedText
|
|
303
|
+
: themePalette.badgeDisabledText
|
|
304
|
+
}
|
|
305
|
+
/>
|
|
306
|
+
<Text
|
|
307
|
+
style={[
|
|
308
|
+
localStyles.statusChipText,
|
|
309
|
+
{
|
|
310
|
+
color: chargeOnDeliveryEnabled
|
|
311
|
+
? themePalette.badgeSelectedText
|
|
312
|
+
: themePalette.badgeDisabledText,
|
|
313
|
+
},
|
|
314
|
+
]}>
|
|
315
|
+
{chargeOnDeliveryEnabled ? 'Ativado' : 'Desativado'}
|
|
316
|
+
</Text>
|
|
317
|
+
</TouchableOpacity>
|
|
318
|
+
</View>
|
|
319
|
+
|
|
320
|
+
{isLoadingDeviceConfigs ? (
|
|
321
|
+
<ActivityIndicator
|
|
322
|
+
size="small"
|
|
323
|
+
style={localStyles.sectionLoader}
|
|
324
|
+
color={themePalette.loadingSpinner}
|
|
325
|
+
/>
|
|
326
|
+
) : paymentDevices.length === 0 ? (
|
|
327
|
+
<View style={localStyles.emptyBox}>
|
|
328
|
+
<Text style={localStyles.emptyTitle}>
|
|
329
|
+
Nenhum device com pagamento remoto disponivel
|
|
330
|
+
</Text>
|
|
331
|
+
<Text style={localStyles.emptyText}>
|
|
332
|
+
Configure ao menos um PDV da empresa com gateway Cielo ou
|
|
333
|
+
Infinite Pay para receber o fallback remoto.
|
|
334
|
+
</Text>
|
|
335
|
+
</View>
|
|
336
|
+
) : (
|
|
337
|
+
<View style={localStyles.printerList}>
|
|
338
|
+
{paymentDevices.map(paymentDevice => {
|
|
339
|
+
const deviceId = String(paymentDevice.deviceId || '').trim();
|
|
340
|
+
const active =
|
|
341
|
+
deviceId !== '' && orderPaymentDevices.includes(deviceId);
|
|
342
|
+
|
|
343
|
+
return (
|
|
344
|
+
<TouchableOpacity
|
|
345
|
+
key={deviceId}
|
|
346
|
+
style={[
|
|
347
|
+
localStyles.printerItem,
|
|
348
|
+
active && localStyles.printerItemActive,
|
|
349
|
+
]}
|
|
350
|
+
activeOpacity={0.85}
|
|
351
|
+
onPress={() => toggleOrderPaymentDevice(deviceId)}>
|
|
352
|
+
<Icon
|
|
353
|
+
name={active ? 'check-circle' : 'radio-button-unchecked'}
|
|
354
|
+
size={20}
|
|
355
|
+
color={
|
|
356
|
+
active
|
|
357
|
+
? themePalette.iconActive
|
|
358
|
+
: themePalette.iconDisabled
|
|
359
|
+
}
|
|
360
|
+
/>
|
|
361
|
+
<View style={localStyles.printerCopy}>
|
|
362
|
+
<Text style={localStyles.printerName}>
|
|
363
|
+
{paymentDevice.alias}
|
|
364
|
+
</Text>
|
|
365
|
+
<Text style={localStyles.printerDevice}>
|
|
366
|
+
{paymentDevice.gatewayLabel} • {deviceId}
|
|
367
|
+
</Text>
|
|
368
|
+
</View>
|
|
369
|
+
</TouchableOpacity>
|
|
370
|
+
);
|
|
371
|
+
})}
|
|
372
|
+
</View>
|
|
373
|
+
)}
|
|
374
|
+
|
|
375
|
+
</GeneralSettingsSection>
|
|
376
|
+
);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
export default OrderPaymentSection;
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents This section controls the order printing targets and footer text.
|
|
3
|
+
* Keep printer selection and config persistence in sync with the shared settings hook.
|
|
4
|
+
*/
|
|
5
|
+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
6
|
+
import {
|
|
7
|
+
ActivityIndicator,
|
|
8
|
+
Alert,
|
|
9
|
+
Text,
|
|
10
|
+
TextInput,
|
|
11
|
+
TouchableOpacity,
|
|
12
|
+
View,
|
|
13
|
+
} from 'react-native';
|
|
14
|
+
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
filterDeviceConfigsByCompany,
|
|
18
|
+
normalizeDeviceIds,
|
|
19
|
+
} from '@controleonline/ui-common/src/react/utils/paymentDevices';
|
|
20
|
+
import {
|
|
21
|
+
getDeviceTypeLabel,
|
|
22
|
+
getPrinterOptionValue,
|
|
23
|
+
getPrinterLabel,
|
|
24
|
+
getPrinterOptions,
|
|
25
|
+
} from '@controleonline/ui-common/src/react/utils/printerDevices';
|
|
26
|
+
import {useStore} from '@store';
|
|
27
|
+
|
|
28
|
+
import {
|
|
29
|
+
useGeneralSettingsPalette,
|
|
30
|
+
useGeneralSettingsStyles,
|
|
31
|
+
} from '../GeneralSettings.styles';
|
|
32
|
+
import GeneralSettingsSection from '../GeneralSettingsSection';
|
|
33
|
+
import {
|
|
34
|
+
normalizeTextConfigValue,
|
|
35
|
+
ORDER_PRINT_DEVICES_CONFIG_KEY,
|
|
36
|
+
ORDER_PRINT_FOOTER_TEXT_CONFIG_KEY,
|
|
37
|
+
useGeneralSettingsConfig,
|
|
38
|
+
} from '../GeneralSettings.shared';
|
|
39
|
+
|
|
40
|
+
const OrderPrintSection = () => {
|
|
41
|
+
const localStyles = useGeneralSettingsStyles();
|
|
42
|
+
const themePalette = useGeneralSettingsPalette();
|
|
43
|
+
const {currentCompany, effectiveCompanyConfigs, saveConfigs} =
|
|
44
|
+
useGeneralSettingsConfig();
|
|
45
|
+
|
|
46
|
+
const printerStore = useStore('printer');
|
|
47
|
+
const {
|
|
48
|
+
items: printers = [],
|
|
49
|
+
isLoading: isLoadingPrinters,
|
|
50
|
+
} = printerStore.getters;
|
|
51
|
+
const printerActions = printerStore.actions;
|
|
52
|
+
|
|
53
|
+
const deviceConfigStore = useStore('device_config');
|
|
54
|
+
const {
|
|
55
|
+
items: companyDeviceConfigs = [],
|
|
56
|
+
isLoading: isLoadingDeviceConfigs,
|
|
57
|
+
} = deviceConfigStore.getters;
|
|
58
|
+
const deviceConfigActions = deviceConfigStore.actions;
|
|
59
|
+
|
|
60
|
+
const [orderPrintEnabled, setOrderPrintEnabled] = useState(false);
|
|
61
|
+
const [orderPrintDevices, setOrderPrintDevices] = useState([]);
|
|
62
|
+
const [orderPrintFooterText, setOrderPrintFooterText] = useState('');
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const nextOrderPrintDevices = normalizeDeviceIds(
|
|
66
|
+
effectiveCompanyConfigs[ORDER_PRINT_DEVICES_CONFIG_KEY],
|
|
67
|
+
);
|
|
68
|
+
setOrderPrintDevices(nextOrderPrintDevices);
|
|
69
|
+
setOrderPrintEnabled(nextOrderPrintDevices.length > 0);
|
|
70
|
+
setOrderPrintFooterText(
|
|
71
|
+
normalizeTextConfigValue(
|
|
72
|
+
effectiveCompanyConfigs[ORDER_PRINT_FOOTER_TEXT_CONFIG_KEY],
|
|
73
|
+
),
|
|
74
|
+
);
|
|
75
|
+
}, [effectiveCompanyConfigs]);
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (!currentCompany?.id) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
printerActions.getPrinters({people: currentCompany.id}).catch(() => {});
|
|
83
|
+
deviceConfigActions
|
|
84
|
+
.getItems({people: '/people/' + currentCompany.id})
|
|
85
|
+
.catch(() => {});
|
|
86
|
+
}, [currentCompany?.id, deviceConfigActions, printerActions]);
|
|
87
|
+
|
|
88
|
+
const scopedCompanyDeviceConfigs = useMemo(
|
|
89
|
+
() =>
|
|
90
|
+
filterDeviceConfigsByCompany(companyDeviceConfigs, currentCompany?.id),
|
|
91
|
+
[companyDeviceConfigs, currentCompany?.id],
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const printerOptions = useMemo(
|
|
95
|
+
() =>
|
|
96
|
+
getPrinterOptions({
|
|
97
|
+
printers,
|
|
98
|
+
deviceConfigs: scopedCompanyDeviceConfigs,
|
|
99
|
+
companyId: currentCompany?.id,
|
|
100
|
+
}),
|
|
101
|
+
[currentCompany?.id, printers, scopedCompanyDeviceConfigs],
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const selectedPrinterCount = orderPrintDevices.length;
|
|
105
|
+
|
|
106
|
+
const saveOrderPrintDevices = useCallback(
|
|
107
|
+
async ({
|
|
108
|
+
nextEnabled = orderPrintEnabled,
|
|
109
|
+
nextDevices = orderPrintDevices,
|
|
110
|
+
nextFooterText = orderPrintFooterText,
|
|
111
|
+
} = {}) => {
|
|
112
|
+
const normalizedDevices = Array.from(
|
|
113
|
+
new Set(
|
|
114
|
+
nextDevices
|
|
115
|
+
.map(item => String(item || '').trim())
|
|
116
|
+
.filter(Boolean),
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
if (nextEnabled && normalizedDevices.length === 0) {
|
|
121
|
+
Alert.alert(
|
|
122
|
+
'Impressora padrao',
|
|
123
|
+
'Selecione pelo menos um device para ativar a impressao remota de pedidos.',
|
|
124
|
+
);
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
await saveConfigs({
|
|
129
|
+
[ORDER_PRINT_DEVICES_CONFIG_KEY]: nextEnabled ? normalizedDevices : [],
|
|
130
|
+
[ORDER_PRINT_FOOTER_TEXT_CONFIG_KEY]: nextFooterText,
|
|
131
|
+
});
|
|
132
|
+
return true;
|
|
133
|
+
},
|
|
134
|
+
[orderPrintDevices, orderPrintEnabled, orderPrintFooterText, saveConfigs],
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const toggleOrderPrintEnabled = useCallback(() => {
|
|
138
|
+
const nextEnabled = !orderPrintEnabled;
|
|
139
|
+
|
|
140
|
+
if (!nextEnabled) {
|
|
141
|
+
setOrderPrintEnabled(false);
|
|
142
|
+
setOrderPrintDevices([]);
|
|
143
|
+
saveOrderPrintDevices({
|
|
144
|
+
nextDevices: [],
|
|
145
|
+
nextEnabled: false,
|
|
146
|
+
});
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (orderPrintDevices.length === 0) {
|
|
151
|
+
Alert.alert(
|
|
152
|
+
'Impressora padrao',
|
|
153
|
+
'Selecione pelo menos um device para ativar a impressao remota de pedidos.',
|
|
154
|
+
);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setOrderPrintEnabled(true);
|
|
159
|
+
saveOrderPrintDevices({
|
|
160
|
+
nextEnabled: true,
|
|
161
|
+
});
|
|
162
|
+
}, [orderPrintDevices.length, orderPrintEnabled, saveOrderPrintDevices]);
|
|
163
|
+
|
|
164
|
+
const toggleOrderPrintDevice = useCallback(
|
|
165
|
+
deviceId => {
|
|
166
|
+
if (!deviceId) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const nextDevices = orderPrintDevices.includes(deviceId)
|
|
171
|
+
? orderPrintDevices.filter(item => item !== deviceId)
|
|
172
|
+
: [...orderPrintDevices, deviceId];
|
|
173
|
+
const nextEnabled = nextDevices.length > 0;
|
|
174
|
+
|
|
175
|
+
setOrderPrintDevices(nextDevices);
|
|
176
|
+
setOrderPrintEnabled(nextEnabled);
|
|
177
|
+
saveOrderPrintDevices({
|
|
178
|
+
nextDevices,
|
|
179
|
+
nextEnabled,
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
[orderPrintDevices, saveOrderPrintDevices],
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<GeneralSettingsSection
|
|
187
|
+
description="Define quais devices da empresa recebem a cópia completa do pedido para conferência e qual texto livre sai no rodapé usando as configs `order-print-devices` e `order-print-footer-text`."
|
|
188
|
+
icon="print"
|
|
189
|
+
iconBackgroundColor={themePalette.cardIconBackground}
|
|
190
|
+
iconColor={themePalette.cardIconColor}
|
|
191
|
+
title="Impressão de conferência">
|
|
192
|
+
<View style={localStyles.statusRow}>
|
|
193
|
+
<Text style={localStyles.statusLabel}>Impressão padrão</Text>
|
|
194
|
+
<TouchableOpacity
|
|
195
|
+
style={[
|
|
196
|
+
localStyles.statusChip,
|
|
197
|
+
orderPrintEnabled
|
|
198
|
+
? localStyles.statusChipEnabled
|
|
199
|
+
: localStyles.statusChipDisabled,
|
|
200
|
+
]}
|
|
201
|
+
activeOpacity={0.85}
|
|
202
|
+
onPress={toggleOrderPrintEnabled}>
|
|
203
|
+
<Icon
|
|
204
|
+
name={orderPrintEnabled ? 'check-circle' : 'block'}
|
|
205
|
+
size={16}
|
|
206
|
+
color={
|
|
207
|
+
orderPrintEnabled
|
|
208
|
+
? themePalette.badgeSelectedText
|
|
209
|
+
: themePalette.badgeDisabledText
|
|
210
|
+
}
|
|
211
|
+
/>
|
|
212
|
+
<Text
|
|
213
|
+
style={[
|
|
214
|
+
localStyles.statusChipText,
|
|
215
|
+
{
|
|
216
|
+
color: orderPrintEnabled
|
|
217
|
+
? themePalette.badgeSelectedText
|
|
218
|
+
: themePalette.badgeDisabledText,
|
|
219
|
+
},
|
|
220
|
+
]}>
|
|
221
|
+
{orderPrintEnabled ? 'Ativada' : 'Desativada'}
|
|
222
|
+
</Text>
|
|
223
|
+
</TouchableOpacity>
|
|
224
|
+
</View>
|
|
225
|
+
|
|
226
|
+
<Text style={localStyles.helperText}>
|
|
227
|
+
{orderPrintEnabled
|
|
228
|
+
? `${selectedPrinterCount} device(s) selecionado(s).`
|
|
229
|
+
: 'Quando desativada, o backend nao usa impressoras padrao da empresa.'}
|
|
230
|
+
</Text>
|
|
231
|
+
|
|
232
|
+
{isLoadingPrinters || isLoadingDeviceConfigs ? (
|
|
233
|
+
<ActivityIndicator
|
|
234
|
+
size="small"
|
|
235
|
+
style={localStyles.sectionLoader}
|
|
236
|
+
color={themePalette.loadingSpinner}
|
|
237
|
+
/>
|
|
238
|
+
) : printerOptions.length === 0 ? (
|
|
239
|
+
<View style={localStyles.emptyBox}>
|
|
240
|
+
<Text style={localStyles.emptyTitle}>
|
|
241
|
+
Nenhum device com impressão disponível
|
|
242
|
+
</Text>
|
|
243
|
+
<Text style={localStyles.emptyText}>
|
|
244
|
+
Cadastre e configure um equipamento com suporte a impressão, como
|
|
245
|
+
uma Cielo, para a empresa ativa.
|
|
246
|
+
</Text>
|
|
247
|
+
</View>
|
|
248
|
+
) : (
|
|
249
|
+
<View style={localStyles.printerList}>
|
|
250
|
+
{printerOptions.map(printer => {
|
|
251
|
+
const deviceId = String(printer?.device || '').trim();
|
|
252
|
+
const printerValue = getPrinterOptionValue(printer);
|
|
253
|
+
const active =
|
|
254
|
+
printerValue !== '' && orderPrintDevices.includes(printerValue);
|
|
255
|
+
|
|
256
|
+
return (
|
|
257
|
+
<TouchableOpacity
|
|
258
|
+
key={printerValue || deviceId}
|
|
259
|
+
style={[
|
|
260
|
+
localStyles.printerItem,
|
|
261
|
+
active && localStyles.printerItemActive,
|
|
262
|
+
]}
|
|
263
|
+
activeOpacity={0.85}
|
|
264
|
+
onPress={() => toggleOrderPrintDevice(printerValue)}>
|
|
265
|
+
<Icon
|
|
266
|
+
name={active ? 'check-circle' : 'radio-button-unchecked'}
|
|
267
|
+
size={20}
|
|
268
|
+
color={
|
|
269
|
+
active
|
|
270
|
+
? themePalette.iconActive
|
|
271
|
+
: themePalette.iconDisabled
|
|
272
|
+
}
|
|
273
|
+
/>
|
|
274
|
+
<View style={localStyles.printerCopy}>
|
|
275
|
+
<Text style={localStyles.printerName}>
|
|
276
|
+
{getPrinterLabel(printer)}
|
|
277
|
+
</Text>
|
|
278
|
+
<Text style={localStyles.printerDevice}>
|
|
279
|
+
{`${getDeviceTypeLabel(printer?.type)} • ${deviceId}`}
|
|
280
|
+
</Text>
|
|
281
|
+
</View>
|
|
282
|
+
</TouchableOpacity>
|
|
283
|
+
);
|
|
284
|
+
})}
|
|
285
|
+
</View>
|
|
286
|
+
)}
|
|
287
|
+
|
|
288
|
+
<View style={localStyles.fieldBlock}>
|
|
289
|
+
<Text style={localStyles.fieldLabel}>Texto livre do rodape</Text>
|
|
290
|
+
<TextInput
|
|
291
|
+
style={[localStyles.input, localStyles.multilineInput]}
|
|
292
|
+
value={orderPrintFooterText}
|
|
293
|
+
multiline
|
|
294
|
+
numberOfLines={4}
|
|
295
|
+
onChangeText={setOrderPrintFooterText}
|
|
296
|
+
onBlur={() => saveOrderPrintDevices()}
|
|
297
|
+
placeholder="Mensagem exibida no rodapé da impressão"
|
|
298
|
+
/>
|
|
299
|
+
<Text style={localStyles.helperText}>
|
|
300
|
+
Esse conteúdo é salvo na config da empresa e sai no rodapé de todas as
|
|
301
|
+
impressões de pedido.
|
|
302
|
+
</Text>
|
|
303
|
+
</View>
|
|
304
|
+
</GeneralSettingsSection>
|
|
305
|
+
);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
export default OrderPrintSection;
|