@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,451 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Loyalty (Fidelidade) tab in General Settings.
|
|
3
|
+
* Product multi-select (participants) and single-select (gift).
|
|
4
|
+
* refs: ControleOnline/ui-manager#12
|
|
5
|
+
*/
|
|
6
|
+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
7
|
+
import {
|
|
8
|
+
ActivityIndicator,
|
|
9
|
+
Text,
|
|
10
|
+
TextInput,
|
|
11
|
+
TouchableOpacity,
|
|
12
|
+
View,
|
|
13
|
+
} from 'react-native';
|
|
14
|
+
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
15
|
+
import css from '@controleonline/ui-orders/src/react/css/orders';
|
|
16
|
+
import {useStore} from '@store';
|
|
17
|
+
import {
|
|
18
|
+
SHOP_LOYALTY_COUPONS_ENABLED_CONFIG_KEY,
|
|
19
|
+
SHOP_LOYALTY_GIFT_PRODUCT_ID_CONFIG_KEY,
|
|
20
|
+
SHOP_LOYALTY_PRODUCT_IDS_CONFIG_KEY,
|
|
21
|
+
SHOP_LOYALTY_REQUIRED_SALES_CONFIG_KEY,
|
|
22
|
+
normalizeBooleanConfig,
|
|
23
|
+
normalizeShopEntityId,
|
|
24
|
+
normalizeShopEntityIds,
|
|
25
|
+
normalizeShopLoyaltyRequiredSales,
|
|
26
|
+
normalizeShopProductId,
|
|
27
|
+
saveAndUpdateConfigValue,
|
|
28
|
+
} from '@controleonline/ui-common/src/react/utils/shopConfig';
|
|
29
|
+
|
|
30
|
+
import {
|
|
31
|
+
useGeneralSettingsPalette,
|
|
32
|
+
useGeneralSettingsStyles,
|
|
33
|
+
} from '../GeneralSettings.styles';
|
|
34
|
+
import GeneralSettingsSection from '../GeneralSettingsSection';
|
|
35
|
+
import {useGeneralSettingsConfig} from '../GeneralSettings.shared';
|
|
36
|
+
import {
|
|
37
|
+
ProductSelectionModal,
|
|
38
|
+
resolveProductLabel,
|
|
39
|
+
resolveProductMeta,
|
|
40
|
+
useProductBrowser,
|
|
41
|
+
} from './LoyaltyProductPicker';
|
|
42
|
+
|
|
43
|
+
const t = (type, key) => global.t?.t?.('configs', type, key);
|
|
44
|
+
|
|
45
|
+
const LoyaltySection = () => {
|
|
46
|
+
const {globalStyles} = css();
|
|
47
|
+
const palette = useGeneralSettingsPalette();
|
|
48
|
+
const styles = useGeneralSettingsStyles();
|
|
49
|
+
const {currentCompany, effectiveCompanyConfigs, saveConfig} =
|
|
50
|
+
useGeneralSettingsConfig();
|
|
51
|
+
const productActions = useStore('products').actions;
|
|
52
|
+
|
|
53
|
+
const [enabled, setEnabled] = useState(false);
|
|
54
|
+
const [requiredSales, setRequiredSales] = useState('');
|
|
55
|
+
const [productIds, setProductIds] = useState([]);
|
|
56
|
+
const [giftProductId, setGiftProductId] = useState('');
|
|
57
|
+
const [selectedProducts, setSelectedProducts] = useState([]);
|
|
58
|
+
const [selectedGiftProduct, setSelectedGiftProduct] = useState(null);
|
|
59
|
+
const [isHydratingProducts, setIsHydratingProducts] = useState(false);
|
|
60
|
+
const [isHydratingGift, setIsHydratingGift] = useState(false);
|
|
61
|
+
const [participantsVisible, setParticipantsVisible] = useState(false);
|
|
62
|
+
const [giftVisible, setGiftVisible] = useState(false);
|
|
63
|
+
|
|
64
|
+
const participantsBrowser = useProductBrowser({
|
|
65
|
+
companyId: currentCompany?.id,
|
|
66
|
+
visible: participantsVisible,
|
|
67
|
+
});
|
|
68
|
+
const giftBrowser = useProductBrowser({
|
|
69
|
+
companyId: currentCompany?.id,
|
|
70
|
+
visible: giftVisible,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
setEnabled(
|
|
75
|
+
normalizeBooleanConfig(
|
|
76
|
+
effectiveCompanyConfigs[SHOP_LOYALTY_COUPONS_ENABLED_CONFIG_KEY],
|
|
77
|
+
),
|
|
78
|
+
);
|
|
79
|
+
setRequiredSales(
|
|
80
|
+
String(
|
|
81
|
+
normalizeShopLoyaltyRequiredSales(
|
|
82
|
+
effectiveCompanyConfigs[SHOP_LOYALTY_REQUIRED_SALES_CONFIG_KEY],
|
|
83
|
+
),
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
setProductIds(
|
|
87
|
+
normalizeShopEntityIds(
|
|
88
|
+
effectiveCompanyConfigs[SHOP_LOYALTY_PRODUCT_IDS_CONFIG_KEY],
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
setGiftProductId(
|
|
92
|
+
normalizeShopEntityId(
|
|
93
|
+
effectiveCompanyConfigs[SHOP_LOYALTY_GIFT_PRODUCT_ID_CONFIG_KEY],
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
}, [effectiveCompanyConfigs]);
|
|
97
|
+
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (productIds.length === 0) {
|
|
100
|
+
setSelectedProducts([]);
|
|
101
|
+
setIsHydratingProducts(false);
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let cancelled = false;
|
|
106
|
+
setIsHydratingProducts(true);
|
|
107
|
+
|
|
108
|
+
Promise.all(
|
|
109
|
+
productIds.map(async productId => {
|
|
110
|
+
try {
|
|
111
|
+
const product = await productActions.get(productId);
|
|
112
|
+
return product || {id: productId};
|
|
113
|
+
} catch {
|
|
114
|
+
return {id: productId};
|
|
115
|
+
}
|
|
116
|
+
}),
|
|
117
|
+
)
|
|
118
|
+
.then(items => {
|
|
119
|
+
if (!cancelled) {
|
|
120
|
+
setSelectedProducts(
|
|
121
|
+
items.filter(Boolean).sort((left, right) => {
|
|
122
|
+
const leftIndex = productIds.indexOf(normalizeShopProductId(left));
|
|
123
|
+
const rightIndex = productIds.indexOf(
|
|
124
|
+
normalizeShopProductId(right),
|
|
125
|
+
);
|
|
126
|
+
return leftIndex - rightIndex;
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
.finally(() => {
|
|
132
|
+
if (!cancelled) {
|
|
133
|
+
setIsHydratingProducts(false);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
return () => {
|
|
138
|
+
cancelled = true;
|
|
139
|
+
};
|
|
140
|
+
}, [productIds, productActions]);
|
|
141
|
+
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (!giftProductId) {
|
|
144
|
+
setSelectedGiftProduct(null);
|
|
145
|
+
setIsHydratingGift(false);
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let cancelled = false;
|
|
150
|
+
setIsHydratingGift(true);
|
|
151
|
+
|
|
152
|
+
productActions
|
|
153
|
+
.get(giftProductId)
|
|
154
|
+
.then(product => {
|
|
155
|
+
if (!cancelled) {
|
|
156
|
+
setSelectedGiftProduct(product || {id: giftProductId});
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
.catch(() => {
|
|
160
|
+
if (!cancelled) {
|
|
161
|
+
setSelectedGiftProduct({id: giftProductId});
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
.finally(() => {
|
|
165
|
+
if (!cancelled) {
|
|
166
|
+
setIsHydratingGift(false);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return () => {
|
|
171
|
+
cancelled = true;
|
|
172
|
+
};
|
|
173
|
+
}, [giftProductId, productActions]);
|
|
174
|
+
|
|
175
|
+
const selectedIdSet = useMemo(() => new Set(productIds), [productIds]);
|
|
176
|
+
|
|
177
|
+
const toggleEnabled = () => {
|
|
178
|
+
const nextValue = !enabled;
|
|
179
|
+
setEnabled(nextValue);
|
|
180
|
+
saveConfig(
|
|
181
|
+
SHOP_LOYALTY_COUPONS_ENABLED_CONFIG_KEY,
|
|
182
|
+
nextValue ? '1' : '0',
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const saveRequiredSales = value => {
|
|
187
|
+
const normalizedValue = String(normalizeShopLoyaltyRequiredSales(value));
|
|
188
|
+
setRequiredSales(normalizedValue);
|
|
189
|
+
saveConfig(SHOP_LOYALTY_REQUIRED_SALES_CONFIG_KEY, normalizedValue);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const toggleParticipant = useCallback(
|
|
193
|
+
product => {
|
|
194
|
+
const productId = normalizeShopProductId(product);
|
|
195
|
+
if (!productId) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const nextProductIds = productIds.includes(productId)
|
|
200
|
+
? productIds.filter(item => item !== productId)
|
|
201
|
+
: [...productIds, productId];
|
|
202
|
+
|
|
203
|
+
saveAndUpdateConfigValue({
|
|
204
|
+
configKey: SHOP_LOYALTY_PRODUCT_IDS_CONFIG_KEY,
|
|
205
|
+
nextValue: nextProductIds,
|
|
206
|
+
saveConfig,
|
|
207
|
+
setValue: setProductIds,
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
[productIds, saveConfig],
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
const selectGift = useCallback(
|
|
214
|
+
product => {
|
|
215
|
+
const productId = normalizeShopProductId(product);
|
|
216
|
+
saveAndUpdateConfigValue({
|
|
217
|
+
configKey: SHOP_LOYALTY_GIFT_PRODUCT_ID_CONFIG_KEY,
|
|
218
|
+
nextValue: productId,
|
|
219
|
+
saveConfig,
|
|
220
|
+
setValue: setGiftProductId,
|
|
221
|
+
});
|
|
222
|
+
setGiftVisible(false);
|
|
223
|
+
},
|
|
224
|
+
[saveConfig],
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
const clearGift = useCallback(() => {
|
|
228
|
+
saveAndUpdateConfigValue({
|
|
229
|
+
configKey: SHOP_LOYALTY_GIFT_PRODUCT_ID_CONFIG_KEY,
|
|
230
|
+
nextValue: '',
|
|
231
|
+
saveConfig,
|
|
232
|
+
setValue: setGiftProductId,
|
|
233
|
+
});
|
|
234
|
+
}, [saveConfig]);
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<>
|
|
238
|
+
<GeneralSettingsSection
|
|
239
|
+
description={t('description', 'loyalty')}
|
|
240
|
+
icon="loyalty"
|
|
241
|
+
iconBackgroundColor={palette.cardIconBackground}
|
|
242
|
+
iconColor={palette.cardIconColor}
|
|
243
|
+
title={t('title', 'loyalty')}>
|
|
244
|
+
<View style={styles.settingRow}>
|
|
245
|
+
<View style={{flex: 1}}>
|
|
246
|
+
<Text style={styles.statusLabel}>
|
|
247
|
+
{t('label', 'loyaltyEnabled')}
|
|
248
|
+
</Text>
|
|
249
|
+
<Text style={styles.helperText}>
|
|
250
|
+
{t('description', 'loyaltyEnabled')}
|
|
251
|
+
</Text>
|
|
252
|
+
</View>
|
|
253
|
+
<TouchableOpacity
|
|
254
|
+
onPress={toggleEnabled}
|
|
255
|
+
activeOpacity={0.85}
|
|
256
|
+
style={[
|
|
257
|
+
styles.statusChip,
|
|
258
|
+
enabled ? styles.statusChipActive : styles.statusChipDisabled,
|
|
259
|
+
]}>
|
|
260
|
+
<Icon
|
|
261
|
+
name={enabled ? 'check-circle' : 'block'}
|
|
262
|
+
size={16}
|
|
263
|
+
color={
|
|
264
|
+
enabled ? palette.badgeSelectedText : palette.badgeDisabledText
|
|
265
|
+
}
|
|
266
|
+
/>
|
|
267
|
+
<Text
|
|
268
|
+
style={[
|
|
269
|
+
styles.statusChipText,
|
|
270
|
+
{
|
|
271
|
+
color: enabled
|
|
272
|
+
? palette.badgeSelectedText
|
|
273
|
+
: palette.badgeDisabledText,
|
|
274
|
+
},
|
|
275
|
+
]}>
|
|
276
|
+
{enabled ? t('status', 'active') : t('status', 'inactive')}
|
|
277
|
+
</Text>
|
|
278
|
+
</TouchableOpacity>
|
|
279
|
+
</View>
|
|
280
|
+
|
|
281
|
+
<Text style={styles.statusLabel}>
|
|
282
|
+
{t('label', 'loyaltyRequiredSales')}
|
|
283
|
+
</Text>
|
|
284
|
+
<TextInput
|
|
285
|
+
keyboardType="numeric"
|
|
286
|
+
onBlur={() => saveRequiredSales(requiredSales)}
|
|
287
|
+
onChangeText={setRequiredSales}
|
|
288
|
+
style={styles.selectionSearchInput}
|
|
289
|
+
value={requiredSales}
|
|
290
|
+
/>
|
|
291
|
+
|
|
292
|
+
<View style={[styles.fieldBlock, {marginTop: 14}]}>
|
|
293
|
+
<Text style={styles.fieldLabel}>
|
|
294
|
+
{t('label', 'loyaltyProducts') || 'Produtos participantes'}
|
|
295
|
+
</Text>
|
|
296
|
+
<Text style={styles.helperText}>
|
|
297
|
+
{t('message', 'loyaltyProductsSummary') || 'Resumo:'}{' '}
|
|
298
|
+
{productIds.length}
|
|
299
|
+
</Text>
|
|
300
|
+
<TouchableOpacity
|
|
301
|
+
style={[
|
|
302
|
+
styles.selectorListButton,
|
|
303
|
+
{marginTop: 8, alignSelf: 'flex-start'},
|
|
304
|
+
]}
|
|
305
|
+
activeOpacity={0.85}
|
|
306
|
+
onPress={() => setParticipantsVisible(true)}>
|
|
307
|
+
<Icon name="view-list" size={18} color={palette.buttonIcon} />
|
|
308
|
+
<Text style={styles.selectorListButtonText}>
|
|
309
|
+
Selecionar produtos
|
|
310
|
+
</Text>
|
|
311
|
+
</TouchableOpacity>
|
|
312
|
+
|
|
313
|
+
{isHydratingProducts ? (
|
|
314
|
+
<ActivityIndicator
|
|
315
|
+
size="small"
|
|
316
|
+
color={palette.loadingSpinner}
|
|
317
|
+
style={styles.sectionLoader}
|
|
318
|
+
/>
|
|
319
|
+
) : selectedProducts.length === 0 ? (
|
|
320
|
+
<View style={[styles.emptyBox, {marginTop: 10}]}>
|
|
321
|
+
<Text style={styles.emptyTitle}>Lista de participantes vazia</Text>
|
|
322
|
+
<Text style={styles.emptyText}>
|
|
323
|
+
Os produtos escolhidos aparecerão aqui para remoção rápida.
|
|
324
|
+
</Text>
|
|
325
|
+
</View>
|
|
326
|
+
) : (
|
|
327
|
+
<View style={[styles.printerList, {marginTop: 10}]}>
|
|
328
|
+
{selectedProducts.map(product => {
|
|
329
|
+
const productId = normalizeShopProductId(product);
|
|
330
|
+
return (
|
|
331
|
+
<TouchableOpacity
|
|
332
|
+
key={`loyalty-selected-${productId}`}
|
|
333
|
+
style={[styles.printerItem, styles.printerItemActive]}
|
|
334
|
+
activeOpacity={0.85}
|
|
335
|
+
onPress={() => toggleParticipant(product)}>
|
|
336
|
+
<Icon
|
|
337
|
+
name="remove-circle-outline"
|
|
338
|
+
size={20}
|
|
339
|
+
color={palette.iconDanger}
|
|
340
|
+
/>
|
|
341
|
+
<View style={styles.printerCopy}>
|
|
342
|
+
<Text style={styles.printerName}>
|
|
343
|
+
{resolveProductLabel(product)}
|
|
344
|
+
</Text>
|
|
345
|
+
<Text style={styles.printerDevice}>
|
|
346
|
+
{resolveProductMeta(product) || 'Toque para remover'}
|
|
347
|
+
</Text>
|
|
348
|
+
</View>
|
|
349
|
+
</TouchableOpacity>
|
|
350
|
+
);
|
|
351
|
+
})}
|
|
352
|
+
</View>
|
|
353
|
+
)}
|
|
354
|
+
</View>
|
|
355
|
+
|
|
356
|
+
<View style={[styles.fieldBlock, {marginTop: 14}]}>
|
|
357
|
+
<Text style={styles.fieldLabel}>
|
|
358
|
+
{t('message', 'loyaltyGiftProduct') || 'Produto brinde'}
|
|
359
|
+
</Text>
|
|
360
|
+
<Text style={styles.helperText}>
|
|
361
|
+
Escolha o produto entregue ao atingir a meta de vendas.
|
|
362
|
+
</Text>
|
|
363
|
+
<View style={[styles.selectorRow, {marginTop: 8}]}>
|
|
364
|
+
<TouchableOpacity
|
|
365
|
+
style={[styles.selectorListButton, {alignSelf: 'flex-start'}]}
|
|
366
|
+
activeOpacity={0.85}
|
|
367
|
+
onPress={() => setGiftVisible(true)}>
|
|
368
|
+
<Icon name="view-list" size={18} color={palette.buttonIcon} />
|
|
369
|
+
<Text style={styles.selectorListButtonText}>
|
|
370
|
+
Selecionar brinde
|
|
371
|
+
</Text>
|
|
372
|
+
</TouchableOpacity>
|
|
373
|
+
{giftProductId ? (
|
|
374
|
+
<TouchableOpacity
|
|
375
|
+
style={[styles.selectorListButton, {marginLeft: 8}]}
|
|
376
|
+
activeOpacity={0.85}
|
|
377
|
+
onPress={clearGift}>
|
|
378
|
+
<Icon name="clear" size={18} color={palette.iconDanger} />
|
|
379
|
+
<Text style={styles.selectorListButtonText}>Limpar</Text>
|
|
380
|
+
</TouchableOpacity>
|
|
381
|
+
) : null}
|
|
382
|
+
</View>
|
|
383
|
+
|
|
384
|
+
{isHydratingGift ? (
|
|
385
|
+
<ActivityIndicator
|
|
386
|
+
size="small"
|
|
387
|
+
color={palette.loadingSpinner}
|
|
388
|
+
style={styles.sectionLoader}
|
|
389
|
+
/>
|
|
390
|
+
) : selectedGiftProduct ? (
|
|
391
|
+
<View style={[styles.printerList, {marginTop: 10}]}>
|
|
392
|
+
<View style={[styles.printerItem, styles.printerItemActive]}>
|
|
393
|
+
<Icon
|
|
394
|
+
name="card-giftcard"
|
|
395
|
+
size={20}
|
|
396
|
+
color={palette.iconActive}
|
|
397
|
+
/>
|
|
398
|
+
<View style={styles.printerCopy}>
|
|
399
|
+
<Text style={styles.printerName}>
|
|
400
|
+
{resolveProductLabel(selectedGiftProduct)}
|
|
401
|
+
</Text>
|
|
402
|
+
<Text style={styles.printerDevice}>
|
|
403
|
+
{resolveProductMeta(selectedGiftProduct) ||
|
|
404
|
+
`ID ${giftProductId}`}
|
|
405
|
+
</Text>
|
|
406
|
+
</View>
|
|
407
|
+
</View>
|
|
408
|
+
</View>
|
|
409
|
+
) : (
|
|
410
|
+
<View style={[styles.emptyBox, {marginTop: 10}]}>
|
|
411
|
+
<Text style={styles.emptyTitle}>Nenhum brinde definido</Text>
|
|
412
|
+
<Text style={styles.emptyText}>
|
|
413
|
+
{t('message', 'loyaltyGiftProduct')} -
|
|
414
|
+
</Text>
|
|
415
|
+
</View>
|
|
416
|
+
)}
|
|
417
|
+
</View>
|
|
418
|
+
</GeneralSettingsSection>
|
|
419
|
+
|
|
420
|
+
<ProductSelectionModal
|
|
421
|
+
visible={participantsVisible}
|
|
422
|
+
title="Selecionar produtos participantes"
|
|
423
|
+
helperText="Toque nos produtos para adicionar ou remover da regra de fidelidade."
|
|
424
|
+
browser={participantsBrowser}
|
|
425
|
+
onClose={() => setParticipantsVisible(false)}
|
|
426
|
+
onSelect={toggleParticipant}
|
|
427
|
+
selectedIds={selectedIdSet}
|
|
428
|
+
multiSelect
|
|
429
|
+
palette={palette}
|
|
430
|
+
styles={styles}
|
|
431
|
+
globalStyles={globalStyles}
|
|
432
|
+
/>
|
|
433
|
+
|
|
434
|
+
<ProductSelectionModal
|
|
435
|
+
visible={giftVisible}
|
|
436
|
+
title="Selecionar produto brinde"
|
|
437
|
+
helperText="Toque em um produto existente para defini-lo como brinde."
|
|
438
|
+
browser={giftBrowser}
|
|
439
|
+
onClose={() => setGiftVisible(false)}
|
|
440
|
+
onSelect={selectGift}
|
|
441
|
+
selectedItemId={giftProductId}
|
|
442
|
+
multiSelect={false}
|
|
443
|
+
palette={palette}
|
|
444
|
+
styles={styles}
|
|
445
|
+
globalStyles={globalStyles}
|
|
446
|
+
/>
|
|
447
|
+
</>
|
|
448
|
+
);
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
export default LoyaltySection;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents This section owns the maintenance settings for the CRM page.
|
|
3
|
+
* Keep the actions and toggles wired to the shared config layer instead of local-only state.
|
|
4
|
+
*/
|
|
5
|
+
import React, {useCallback, useEffect, useState} from 'react';
|
|
6
|
+
import {Switch, Text, TextInput, View} from 'react-native';
|
|
7
|
+
|
|
8
|
+
import useToastMessage from '@controleonline/ui-crm/src/react/hooks/useToastMessage';
|
|
9
|
+
import {
|
|
10
|
+
isLikelyCronExpression,
|
|
11
|
+
MAINTENANCE_ROUTINES_CONFIG_KEY,
|
|
12
|
+
MAINTENANCE_ROUTINE_ITEMS,
|
|
13
|
+
normalizeMaintenanceRoutines,
|
|
14
|
+
} from '@controleonline/ui-common/src/react/utils/maintenanceSettings';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
getGeneralSettingsSwitchProps,
|
|
18
|
+
useGeneralSettingsPalette,
|
|
19
|
+
useGeneralSettingsStyles,
|
|
20
|
+
} from '../GeneralSettings.styles';
|
|
21
|
+
import GeneralSettingsSection from '../GeneralSettingsSection';
|
|
22
|
+
import {useGeneralSettingsConfig} from '../GeneralSettings.shared';
|
|
23
|
+
|
|
24
|
+
const MaintenanceSection = () => {
|
|
25
|
+
const localStyles = useGeneralSettingsStyles();
|
|
26
|
+
const themePalette = useGeneralSettingsPalette();
|
|
27
|
+
const {showError, showSuccess} = useToastMessage();
|
|
28
|
+
const {
|
|
29
|
+
mainCompany,
|
|
30
|
+
mainCompanyLabel,
|
|
31
|
+
hasMainCompanyAccess,
|
|
32
|
+
isMainCompanySelected,
|
|
33
|
+
isSaving,
|
|
34
|
+
peopleActions,
|
|
35
|
+
saveConfigs,
|
|
36
|
+
} = useGeneralSettingsConfig();
|
|
37
|
+
const [routines, setRoutines] = useState(
|
|
38
|
+
normalizeMaintenanceRoutines(mainCompany?.configs?.[
|
|
39
|
+
MAINTENANCE_ROUTINES_CONFIG_KEY
|
|
40
|
+
]),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
setRoutines(
|
|
45
|
+
normalizeMaintenanceRoutines(
|
|
46
|
+
mainCompany?.configs?.[MAINTENANCE_ROUTINES_CONFIG_KEY],
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
}, [mainCompany?.configs]);
|
|
50
|
+
|
|
51
|
+
const editable =
|
|
52
|
+
hasMainCompanyAccess &&
|
|
53
|
+
!!mainCompany?.id &&
|
|
54
|
+
isMainCompanySelected &&
|
|
55
|
+
!isSaving;
|
|
56
|
+
|
|
57
|
+
const saveRoutines = useCallback(
|
|
58
|
+
async (nextRoutines = routines) => {
|
|
59
|
+
if (!hasMainCompanyAccess || !mainCompany?.id || !isMainCompanySelected) {
|
|
60
|
+
showError(
|
|
61
|
+
`Abra a empresa principal (${mainCompanyLabel}) para editar as rotinas.`,
|
|
62
|
+
);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const invalidRoutine = MAINTENANCE_ROUTINE_ITEMS.find(item => {
|
|
67
|
+
const cronExpression = String(
|
|
68
|
+
nextRoutines?.[item.key]?.cronExpression || '',
|
|
69
|
+
).trim();
|
|
70
|
+
|
|
71
|
+
return !isLikelyCronExpression(cronExpression);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (invalidRoutine) {
|
|
75
|
+
showError(
|
|
76
|
+
`A rotina "${invalidRoutine.title}" precisa de uma expressao cron com 5 campos.`,
|
|
77
|
+
);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const success = await saveConfigs({
|
|
82
|
+
[MAINTENANCE_ROUTINES_CONFIG_KEY]: nextRoutines,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (!success) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
await peopleActions.mainCompany();
|
|
91
|
+
} catch {}
|
|
92
|
+
|
|
93
|
+
showSuccess('Rotinas de manutencao salvas com sucesso.');
|
|
94
|
+
return true;
|
|
95
|
+
},
|
|
96
|
+
[
|
|
97
|
+
mainCompany?.id,
|
|
98
|
+
mainCompanyLabel,
|
|
99
|
+
hasMainCompanyAccess,
|
|
100
|
+
isMainCompanySelected,
|
|
101
|
+
peopleActions,
|
|
102
|
+
routines,
|
|
103
|
+
saveConfigs,
|
|
104
|
+
showError,
|
|
105
|
+
showSuccess,
|
|
106
|
+
],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const updateRoutine = useCallback(
|
|
110
|
+
(routineKey, patch, shouldSave = false) => {
|
|
111
|
+
const nextRoutines = {
|
|
112
|
+
...routines,
|
|
113
|
+
[routineKey]: {
|
|
114
|
+
...(routines[routineKey] || {}),
|
|
115
|
+
...patch,
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
setRoutines(nextRoutines);
|
|
120
|
+
|
|
121
|
+
if (shouldSave) {
|
|
122
|
+
saveRoutines(nextRoutines);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
[routines, saveRoutines],
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<GeneralSettingsSection
|
|
130
|
+
description="Centraliza as rotinas tecnicas executadas pelo cron geral de manutencao."
|
|
131
|
+
icon="schedule"
|
|
132
|
+
iconBackgroundColor={themePalette.cardIconBackground}
|
|
133
|
+
iconColor={themePalette.cardIconColor}
|
|
134
|
+
title="Rotinas de manutencao">
|
|
135
|
+
<Text style={localStyles.helperText}>
|
|
136
|
+
{`Essas rotinas ficam gravadas na empresa principal (${mainCompanyLabel}) e o cron geral tenta executa-las a cada minuto.`}
|
|
137
|
+
</Text>
|
|
138
|
+
|
|
139
|
+
{!isMainCompanySelected && hasMainCompanyAccess && (
|
|
140
|
+
<Text style={localStyles.helperText}>
|
|
141
|
+
Abra a empresa principal para editar a agenda. Fora dela esta tela
|
|
142
|
+
fica somente para consulta.
|
|
143
|
+
</Text>
|
|
144
|
+
)}
|
|
145
|
+
|
|
146
|
+
{MAINTENANCE_ROUTINE_ITEMS.map(item => {
|
|
147
|
+
const routine = routines?.[item.key] || {
|
|
148
|
+
enabled: item.defaultEnabled,
|
|
149
|
+
cronExpression: item.defaultCronExpression,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<View key={item.key} style={localStyles.logPolicyCard}>
|
|
154
|
+
<View style={localStyles.settingRow}>
|
|
155
|
+
<View style={localStyles.settingCopy}>
|
|
156
|
+
<Text style={localStyles.statusLabel}>{item.title}</Text>
|
|
157
|
+
<Text style={localStyles.settingDescription}>
|
|
158
|
+
{item.description}
|
|
159
|
+
</Text>
|
|
160
|
+
</View>
|
|
161
|
+
<Switch
|
|
162
|
+
value={!!routine.enabled}
|
|
163
|
+
onValueChange={value =>
|
|
164
|
+
updateRoutine(item.key, {enabled: value}, true)
|
|
165
|
+
}
|
|
166
|
+
disabled={!editable}
|
|
167
|
+
{...getGeneralSettingsSwitchProps({
|
|
168
|
+
disabled: !editable,
|
|
169
|
+
palette: themePalette,
|
|
170
|
+
value: !!routine.enabled,
|
|
171
|
+
})}
|
|
172
|
+
/>
|
|
173
|
+
</View>
|
|
174
|
+
|
|
175
|
+
<View style={localStyles.fieldBlock}>
|
|
176
|
+
<Text style={localStyles.fieldLabel}>Expressao cron</Text>
|
|
177
|
+
<TextInput
|
|
178
|
+
style={[
|
|
179
|
+
localStyles.input,
|
|
180
|
+
!editable && localStyles.inputDisabled,
|
|
181
|
+
]}
|
|
182
|
+
value={String(routine.cronExpression || '')}
|
|
183
|
+
onChangeText={value =>
|
|
184
|
+
updateRoutine(item.key, {cronExpression: value})
|
|
185
|
+
}
|
|
186
|
+
onBlur={() => saveRoutines()}
|
|
187
|
+
editable={editable}
|
|
188
|
+
autoCapitalize="none"
|
|
189
|
+
autoCorrect={false}
|
|
190
|
+
placeholder={item.defaultCronExpression}
|
|
191
|
+
/>
|
|
192
|
+
<Text style={localStyles.helperText}>
|
|
193
|
+
Use 5 campos no formato minuto hora dia mes semana. Exemplo:
|
|
194
|
+
`* * * * *`.
|
|
195
|
+
</Text>
|
|
196
|
+
</View>
|
|
197
|
+
</View>
|
|
198
|
+
);
|
|
199
|
+
})}
|
|
200
|
+
|
|
201
|
+
</GeneralSettingsSection>
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export default MaintenanceSection;
|