@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,426 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Loyalty coupons settings for shop general settings.
|
|
3
|
+
*/
|
|
4
|
+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
5
|
+
import {
|
|
6
|
+
ActivityIndicator,
|
|
7
|
+
Text,
|
|
8
|
+
TextInput,
|
|
9
|
+
TouchableOpacity,
|
|
10
|
+
View,
|
|
11
|
+
} from 'react-native';
|
|
12
|
+
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
13
|
+
import {useStore} from '@store';
|
|
14
|
+
import {
|
|
15
|
+
normalizeBooleanConfig,
|
|
16
|
+
normalizeShopLoyaltyRequiredSales,
|
|
17
|
+
normalizeShopProductId,
|
|
18
|
+
normalizeShopProductIds,
|
|
19
|
+
SHOP_LOYALTY_COUPONS_ENABLED_CONFIG_KEY,
|
|
20
|
+
SHOP_LOYALTY_GIFT_PRODUCT_ID_CONFIG_KEY,
|
|
21
|
+
SHOP_LOYALTY_PRODUCT_IDS_CONFIG_KEY,
|
|
22
|
+
SHOP_LOYALTY_REQUIRED_SALES_CONFIG_KEY,
|
|
23
|
+
saveAndUpdateConfigValue,
|
|
24
|
+
toggleAndSaveBooleanConfig,
|
|
25
|
+
} from '@controleonline/ui-common/src/react/utils/shopConfig';
|
|
26
|
+
import GeneralSettingsSection from '../GeneralSettingsSection';
|
|
27
|
+
import {
|
|
28
|
+
ConfigToggleRow,
|
|
29
|
+
SelectionModal,
|
|
30
|
+
resolveProductLabel,
|
|
31
|
+
resolveProductMeta,
|
|
32
|
+
useShopProductBrowser,
|
|
33
|
+
useShopProductSearch,
|
|
34
|
+
} from './shopSettingsShared';
|
|
35
|
+
|
|
36
|
+
const ShopLoyaltySection = ({
|
|
37
|
+
effectiveCompanyConfigs,
|
|
38
|
+
localStyles,
|
|
39
|
+
saveConfig,
|
|
40
|
+
themePalette,
|
|
41
|
+
globalStyles,
|
|
42
|
+
currentCompanyId,
|
|
43
|
+
loyaltyCouponsEnabled,
|
|
44
|
+
setLoyaltyCouponsEnabled,
|
|
45
|
+
}) => {
|
|
46
|
+
const productActions = useStore('products').actions;
|
|
47
|
+
const [loyaltyRequiredSales, setLoyaltyRequiredSales] = useState('');
|
|
48
|
+
const [loyaltyProductIds, setLoyaltyProductIds] = useState([]);
|
|
49
|
+
const [loyaltyGiftProductId, setLoyaltyGiftProductId] = useState('');
|
|
50
|
+
const [selectedLoyaltyProducts, setSelectedLoyaltyProducts] = useState([]);
|
|
51
|
+
const [selectedGiftProduct, setSelectedGiftProduct] = useState(null);
|
|
52
|
+
const [isHydratingLoyaltyProducts, setIsHydratingLoyaltyProducts] = useState(false);
|
|
53
|
+
const [isHydratingGiftProduct, setIsHydratingGiftProduct] = useState(false);
|
|
54
|
+
const [loyaltySelectorVisible, setLoyaltySelectorVisible] = useState(false);
|
|
55
|
+
const [giftSelectorVisible, setGiftSelectorVisible] = useState(false);
|
|
56
|
+
|
|
57
|
+
const loyaltyBrowser = useShopProductBrowser({
|
|
58
|
+
companyId: currentCompanyId,
|
|
59
|
+
visible: loyaltySelectorVisible,
|
|
60
|
+
});
|
|
61
|
+
const giftBrowser = useShopProductBrowser({
|
|
62
|
+
companyId: currentCompanyId,
|
|
63
|
+
visible: giftSelectorVisible,
|
|
64
|
+
});
|
|
65
|
+
const loyaltySearch = useShopProductSearch(currentCompanyId);
|
|
66
|
+
const giftSearch = useShopProductSearch(currentCompanyId);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
setLoyaltyCouponsEnabled(
|
|
70
|
+
normalizeBooleanConfig(
|
|
71
|
+
effectiveCompanyConfigs?.[SHOP_LOYALTY_COUPONS_ENABLED_CONFIG_KEY],
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
setLoyaltyRequiredSales(
|
|
75
|
+
String(
|
|
76
|
+
normalizeShopLoyaltyRequiredSales(
|
|
77
|
+
effectiveCompanyConfigs?.[SHOP_LOYALTY_REQUIRED_SALES_CONFIG_KEY],
|
|
78
|
+
) || '',
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
setLoyaltyProductIds(
|
|
82
|
+
normalizeShopProductIds(
|
|
83
|
+
effectiveCompanyConfigs?.[SHOP_LOYALTY_PRODUCT_IDS_CONFIG_KEY],
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
setLoyaltyGiftProductId(
|
|
87
|
+
normalizeShopProductId(
|
|
88
|
+
effectiveCompanyConfigs?.[SHOP_LOYALTY_GIFT_PRODUCT_ID_CONFIG_KEY],
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
}, [effectiveCompanyConfigs, setLoyaltyCouponsEnabled]);
|
|
92
|
+
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (loyaltyProductIds.length === 0) {
|
|
95
|
+
setSelectedLoyaltyProducts([]);
|
|
96
|
+
setIsHydratingLoyaltyProducts(false);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
let cancelled = false;
|
|
100
|
+
setIsHydratingLoyaltyProducts(true);
|
|
101
|
+
Promise.all(
|
|
102
|
+
loyaltyProductIds.map(async productId => {
|
|
103
|
+
try {
|
|
104
|
+
return await productActions.get(productId);
|
|
105
|
+
} catch {
|
|
106
|
+
return {id: productId};
|
|
107
|
+
}
|
|
108
|
+
}),
|
|
109
|
+
)
|
|
110
|
+
.then(items => {
|
|
111
|
+
if (cancelled) return;
|
|
112
|
+
setSelectedLoyaltyProducts(
|
|
113
|
+
items.filter(Boolean).sort((left, right) => {
|
|
114
|
+
const leftIndex = loyaltyProductIds.indexOf(
|
|
115
|
+
normalizeShopProductId(left),
|
|
116
|
+
);
|
|
117
|
+
const rightIndex = loyaltyProductIds.indexOf(
|
|
118
|
+
normalizeShopProductId(right),
|
|
119
|
+
);
|
|
120
|
+
return leftIndex - rightIndex;
|
|
121
|
+
}),
|
|
122
|
+
);
|
|
123
|
+
})
|
|
124
|
+
.finally(() => {
|
|
125
|
+
if (!cancelled) setIsHydratingLoyaltyProducts(false);
|
|
126
|
+
});
|
|
127
|
+
return () => {
|
|
128
|
+
cancelled = true;
|
|
129
|
+
};
|
|
130
|
+
}, [loyaltyProductIds, productActions]);
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (!loyaltyGiftProductId) {
|
|
134
|
+
setSelectedGiftProduct(null);
|
|
135
|
+
setIsHydratingGiftProduct(false);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
let cancelled = false;
|
|
139
|
+
setIsHydratingGiftProduct(true);
|
|
140
|
+
productActions
|
|
141
|
+
.get(loyaltyGiftProductId)
|
|
142
|
+
.then(item => {
|
|
143
|
+
if (!cancelled) setSelectedGiftProduct(item || {id: loyaltyGiftProductId});
|
|
144
|
+
})
|
|
145
|
+
.catch(() => {
|
|
146
|
+
if (!cancelled) setSelectedGiftProduct({id: loyaltyGiftProductId});
|
|
147
|
+
})
|
|
148
|
+
.finally(() => {
|
|
149
|
+
if (!cancelled) setIsHydratingGiftProduct(false);
|
|
150
|
+
});
|
|
151
|
+
return () => {
|
|
152
|
+
cancelled = true;
|
|
153
|
+
};
|
|
154
|
+
}, [loyaltyGiftProductId, productActions]);
|
|
155
|
+
|
|
156
|
+
const loyaltySelectedIds = useMemo(
|
|
157
|
+
() => new Set(loyaltyProductIds),
|
|
158
|
+
[loyaltyProductIds],
|
|
159
|
+
);
|
|
160
|
+
const visibleLoyaltyResults = useMemo(
|
|
161
|
+
() =>
|
|
162
|
+
loyaltySearch.results.filter(
|
|
163
|
+
product => !loyaltySelectedIds.has(normalizeShopProductId(product)),
|
|
164
|
+
),
|
|
165
|
+
[loyaltySearch.results, loyaltySelectedIds],
|
|
166
|
+
);
|
|
167
|
+
const visibleGiftResults = useMemo(
|
|
168
|
+
() =>
|
|
169
|
+
giftSearch.results.filter(
|
|
170
|
+
product =>
|
|
171
|
+
normalizeShopProductId(product) !==
|
|
172
|
+
normalizeShopProductId(selectedGiftProduct),
|
|
173
|
+
),
|
|
174
|
+
[giftSearch.results, selectedGiftProduct],
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const toggleLoyaltyProduct = useCallback(
|
|
178
|
+
product => {
|
|
179
|
+
const productId = normalizeShopProductId(product);
|
|
180
|
+
if (!productId) return;
|
|
181
|
+
const nextProductIds = loyaltyProductIds.includes(productId)
|
|
182
|
+
? loyaltyProductIds.filter(item => item !== productId)
|
|
183
|
+
: [...loyaltyProductIds, productId];
|
|
184
|
+
saveAndUpdateConfigValue({
|
|
185
|
+
configKey: SHOP_LOYALTY_PRODUCT_IDS_CONFIG_KEY,
|
|
186
|
+
nextValue: nextProductIds,
|
|
187
|
+
saveConfig,
|
|
188
|
+
setValue: setLoyaltyProductIds,
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
[loyaltyProductIds, saveConfig],
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
const selectGiftProduct = useCallback(
|
|
195
|
+
product => {
|
|
196
|
+
const productId = normalizeShopProductId(product);
|
|
197
|
+
saveAndUpdateConfigValue({
|
|
198
|
+
configKey: SHOP_LOYALTY_GIFT_PRODUCT_ID_CONFIG_KEY,
|
|
199
|
+
nextValue: productId,
|
|
200
|
+
saveConfig,
|
|
201
|
+
setValue: setLoyaltyGiftProductId,
|
|
202
|
+
});
|
|
203
|
+
setGiftSelectorVisible(false);
|
|
204
|
+
},
|
|
205
|
+
[saveConfig],
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const clearGiftProduct = useCallback(() => {
|
|
209
|
+
saveAndUpdateConfigValue({
|
|
210
|
+
configKey: SHOP_LOYALTY_GIFT_PRODUCT_ID_CONFIG_KEY,
|
|
211
|
+
nextValue: '',
|
|
212
|
+
saveConfig,
|
|
213
|
+
setValue: setLoyaltyGiftProductId,
|
|
214
|
+
});
|
|
215
|
+
}, [saveConfig]);
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
<>
|
|
219
|
+
<GeneralSettingsSection
|
|
220
|
+
description="Configure produtos participantes, meta de vendas e brinde do cartao fidelidade."
|
|
221
|
+
icon="card-giftcard"
|
|
222
|
+
iconBackgroundColor={themePalette.cardIconBackground}
|
|
223
|
+
iconColor={themePalette.cardIconColor}
|
|
224
|
+
title="Cupons de fidelidade">
|
|
225
|
+
<ConfigToggleRow
|
|
226
|
+
label="Cupons de fidelidade"
|
|
227
|
+
description="Ativa o programa de fidelidade no shop."
|
|
228
|
+
palette={themePalette}
|
|
229
|
+
styles={localStyles}
|
|
230
|
+
value={loyaltyCouponsEnabled}
|
|
231
|
+
onToggle={() =>
|
|
232
|
+
toggleAndSaveBooleanConfig({
|
|
233
|
+
configKey: SHOP_LOYALTY_COUPONS_ENABLED_CONFIG_KEY,
|
|
234
|
+
nextValue: !loyaltyCouponsEnabled,
|
|
235
|
+
saveConfig,
|
|
236
|
+
setValue: setLoyaltyCouponsEnabled,
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
/>
|
|
240
|
+
<View style={localStyles.fieldBlock}>
|
|
241
|
+
<Text style={localStyles.fieldLabel}>Vendas necessarias</Text>
|
|
242
|
+
<TextInput
|
|
243
|
+
value={loyaltyRequiredSales}
|
|
244
|
+
onChangeText={setLoyaltyRequiredSales}
|
|
245
|
+
onBlur={() =>
|
|
246
|
+
saveAndUpdateConfigValue({
|
|
247
|
+
configKey: SHOP_LOYALTY_REQUIRED_SALES_CONFIG_KEY,
|
|
248
|
+
nextValue: loyaltyRequiredSales,
|
|
249
|
+
saveConfig,
|
|
250
|
+
setValue: setLoyaltyRequiredSales,
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
keyboardType="number-pad"
|
|
254
|
+
placeholder="0"
|
|
255
|
+
placeholderTextColor={themePalette.inputPlaceholderText}
|
|
256
|
+
style={localStyles.input}
|
|
257
|
+
/>
|
|
258
|
+
</View>
|
|
259
|
+
<View style={localStyles.fieldBlock}>
|
|
260
|
+
<Text style={localStyles.fieldLabel}>Produtos participantes</Text>
|
|
261
|
+
<View style={localStyles.selectorRow}>
|
|
262
|
+
<TextInput
|
|
263
|
+
value={loyaltySearch.query}
|
|
264
|
+
onChangeText={loyaltySearch.setQuery}
|
|
265
|
+
placeholder="Buscar produto participante..."
|
|
266
|
+
placeholderTextColor={themePalette.inputPlaceholderText}
|
|
267
|
+
style={[localStyles.input, localStyles.selectorInput]}
|
|
268
|
+
/>
|
|
269
|
+
<TouchableOpacity
|
|
270
|
+
style={localStyles.selectorListButton}
|
|
271
|
+
activeOpacity={0.85}
|
|
272
|
+
onPress={() => setLoyaltySelectorVisible(true)}>
|
|
273
|
+
<Icon name="view-list" size={18} color={themePalette.buttonIcon} />
|
|
274
|
+
<Text style={localStyles.selectorListButtonText}>Lista</Text>
|
|
275
|
+
</TouchableOpacity>
|
|
276
|
+
</View>
|
|
277
|
+
{isHydratingLoyaltyProducts || loyaltySearch.isLoading ? (
|
|
278
|
+
<ActivityIndicator
|
|
279
|
+
size="small"
|
|
280
|
+
color={themePalette.loadingSpinner}
|
|
281
|
+
style={localStyles.sectionLoader}
|
|
282
|
+
/>
|
|
283
|
+
) : null}
|
|
284
|
+
<View style={localStyles.printerList}>
|
|
285
|
+
{selectedLoyaltyProducts.map(product => {
|
|
286
|
+
const productId = normalizeShopProductId(product);
|
|
287
|
+
return (
|
|
288
|
+
<TouchableOpacity
|
|
289
|
+
key={`shop-loyalty-selected-${productId}`}
|
|
290
|
+
style={[localStyles.printerItem, localStyles.printerItemActive]}
|
|
291
|
+
activeOpacity={0.85}
|
|
292
|
+
onPress={() => toggleLoyaltyProduct(product)}>
|
|
293
|
+
<Icon name="remove-circle-outline" size={20} color={themePalette.iconDanger} />
|
|
294
|
+
<View style={localStyles.printerCopy}>
|
|
295
|
+
<Text style={localStyles.printerName}>{resolveProductLabel(product)}</Text>
|
|
296
|
+
<Text style={localStyles.printerDevice}>
|
|
297
|
+
{resolveProductMeta(product) || 'Toque para remover'}
|
|
298
|
+
</Text>
|
|
299
|
+
</View>
|
|
300
|
+
</TouchableOpacity>
|
|
301
|
+
);
|
|
302
|
+
})}
|
|
303
|
+
{visibleLoyaltyResults.map(product => {
|
|
304
|
+
const productId = normalizeShopProductId(product);
|
|
305
|
+
return (
|
|
306
|
+
<TouchableOpacity
|
|
307
|
+
key={`shop-loyalty-search-${productId}`}
|
|
308
|
+
style={localStyles.printerItem}
|
|
309
|
+
activeOpacity={0.85}
|
|
310
|
+
onPress={() => toggleLoyaltyProduct(product)}>
|
|
311
|
+
<Icon name="inventory-2" size={20} color={themePalette.cardIconColor} />
|
|
312
|
+
<View style={localStyles.printerCopy}>
|
|
313
|
+
<Text style={localStyles.printerName}>{resolveProductLabel(product)}</Text>
|
|
314
|
+
<Text style={localStyles.printerDevice}>
|
|
315
|
+
{resolveProductMeta(product) || 'Toque para incluir'}
|
|
316
|
+
</Text>
|
|
317
|
+
</View>
|
|
318
|
+
</TouchableOpacity>
|
|
319
|
+
);
|
|
320
|
+
})}
|
|
321
|
+
</View>
|
|
322
|
+
</View>
|
|
323
|
+
<View style={localStyles.fieldBlock}>
|
|
324
|
+
<Text style={localStyles.fieldLabel}>Produto brinde</Text>
|
|
325
|
+
<View style={localStyles.selectorRow}>
|
|
326
|
+
<TextInput
|
|
327
|
+
value={giftSearch.query}
|
|
328
|
+
onChangeText={giftSearch.setQuery}
|
|
329
|
+
placeholder="Buscar produto brinde..."
|
|
330
|
+
placeholderTextColor={themePalette.inputPlaceholderText}
|
|
331
|
+
style={[localStyles.input, localStyles.selectorInput]}
|
|
332
|
+
/>
|
|
333
|
+
<TouchableOpacity
|
|
334
|
+
style={localStyles.selectorListButton}
|
|
335
|
+
activeOpacity={0.85}
|
|
336
|
+
onPress={() => setGiftSelectorVisible(true)}>
|
|
337
|
+
<Icon name="view-list" size={18} color={themePalette.buttonIcon} />
|
|
338
|
+
<Text style={localStyles.selectorListButtonText}>Lista</Text>
|
|
339
|
+
</TouchableOpacity>
|
|
340
|
+
</View>
|
|
341
|
+
{isHydratingGiftProduct ? (
|
|
342
|
+
<ActivityIndicator
|
|
343
|
+
size="small"
|
|
344
|
+
color={themePalette.loadingSpinner}
|
|
345
|
+
style={localStyles.sectionLoader}
|
|
346
|
+
/>
|
|
347
|
+
) : selectedGiftProduct ? (
|
|
348
|
+
<TouchableOpacity
|
|
349
|
+
style={[localStyles.printerItem, localStyles.printerItemActive]}
|
|
350
|
+
activeOpacity={0.85}
|
|
351
|
+
onPress={clearGiftProduct}>
|
|
352
|
+
<Icon name="remove-circle-outline" size={20} color={themePalette.iconDanger} />
|
|
353
|
+
<View style={localStyles.printerCopy}>
|
|
354
|
+
<Text style={localStyles.printerName}>
|
|
355
|
+
{resolveProductLabel(selectedGiftProduct)}
|
|
356
|
+
</Text>
|
|
357
|
+
<Text style={localStyles.printerDevice}>Toque para limpar</Text>
|
|
358
|
+
</View>
|
|
359
|
+
</TouchableOpacity>
|
|
360
|
+
) : null}
|
|
361
|
+
<View style={localStyles.printerList}>
|
|
362
|
+
{visibleGiftResults.map(product => {
|
|
363
|
+
const productId = normalizeShopProductId(product);
|
|
364
|
+
return (
|
|
365
|
+
<TouchableOpacity
|
|
366
|
+
key={`shop-gift-search-${productId}`}
|
|
367
|
+
style={localStyles.printerItem}
|
|
368
|
+
activeOpacity={0.85}
|
|
369
|
+
onPress={() => selectGiftProduct(product)}>
|
|
370
|
+
<Icon name="card-giftcard" size={20} color={themePalette.cardIconColor} />
|
|
371
|
+
<View style={localStyles.printerCopy}>
|
|
372
|
+
<Text style={localStyles.printerName}>{resolveProductLabel(product)}</Text>
|
|
373
|
+
<Text style={localStyles.printerDevice}>Toque para selecionar</Text>
|
|
374
|
+
</View>
|
|
375
|
+
</TouchableOpacity>
|
|
376
|
+
);
|
|
377
|
+
})}
|
|
378
|
+
</View>
|
|
379
|
+
</View>
|
|
380
|
+
</GeneralSettingsSection>
|
|
381
|
+
|
|
382
|
+
<SelectionModal
|
|
383
|
+
visible={loyaltySelectorVisible}
|
|
384
|
+
title="Selecionar produtos participantes"
|
|
385
|
+
helperText="Toque nos produtos que contam para a fidelidade."
|
|
386
|
+
browser={loyaltyBrowser}
|
|
387
|
+
globalStyles={globalStyles}
|
|
388
|
+
onClose={() => setLoyaltySelectorVisible(false)}
|
|
389
|
+
onSelect={toggleLoyaltyProduct}
|
|
390
|
+
selectedIds={new Set(loyaltyProductIds)}
|
|
391
|
+
emptyIconName="inventory-2"
|
|
392
|
+
emptyTitle="Nenhum produto encontrado"
|
|
393
|
+
emptyText="Tente outro termo para localizar um produto existente."
|
|
394
|
+
resolveItemId={normalizeShopProductId}
|
|
395
|
+
resolveItemLabel={resolveProductLabel}
|
|
396
|
+
resolveItemMeta={product => resolveProductMeta(product) || 'Toque para selecionar'}
|
|
397
|
+
palette={themePalette}
|
|
398
|
+
searchPlaceholder="Pesquisar produto..."
|
|
399
|
+
selectionMeta={() => 'Participa da fidelidade'}
|
|
400
|
+
styles={localStyles}
|
|
401
|
+
/>
|
|
402
|
+
<SelectionModal
|
|
403
|
+
visible={giftSelectorVisible}
|
|
404
|
+
title="Selecionar produto brinde"
|
|
405
|
+
helperText="Toque em um produto existente para defini-lo como brinde."
|
|
406
|
+
browser={giftBrowser}
|
|
407
|
+
globalStyles={globalStyles}
|
|
408
|
+
onClose={() => setGiftSelectorVisible(false)}
|
|
409
|
+
onSelect={selectGiftProduct}
|
|
410
|
+
selectedItemId={loyaltyGiftProductId}
|
|
411
|
+
emptyIconName="inventory-2"
|
|
412
|
+
emptyTitle="Nenhum produto encontrado"
|
|
413
|
+
emptyText="Tente outro termo para localizar um produto existente."
|
|
414
|
+
resolveItemId={normalizeShopProductId}
|
|
415
|
+
resolveItemLabel={resolveProductLabel}
|
|
416
|
+
resolveItemMeta={product => resolveProductMeta(product) || 'Toque para selecionar'}
|
|
417
|
+
palette={themePalette}
|
|
418
|
+
searchPlaceholder="Pesquisar produto..."
|
|
419
|
+
selectionMeta={() => 'Selecionado como brinde'}
|
|
420
|
+
styles={localStyles}
|
|
421
|
+
/>
|
|
422
|
+
</>
|
|
423
|
+
);
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
export default ShopLoyaltySection;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Shop settings are domain-first and must not include loyalty settings.
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
import ShopDomainShowcasesSection from './ShopDomainShowcasesSection';
|
|
7
|
+
|
|
8
|
+
const ShopSettingsSection = () => <ShopDomainShowcasesSection />;
|
|
9
|
+
|
|
10
|
+
export default ShopSettingsSection;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* fluxo: outros | etapa: general-settings-mapas-map-preview
|
|
3
|
+
* https://github.com/ControleOnline/app-community/wiki/Smoke-Test-Flows
|
|
4
|
+
* Static / Leaflet map URL helpers for franchise locator preview (MapsSection).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// JSON is valid JavaScript, but a literal `</script>` still closes the parent
|
|
8
|
+
// srcDoc script element before the browser can evaluate the string safely.
|
|
9
|
+
const serializeScriptString = value =>
|
|
10
|
+
JSON.stringify(value).replace(/</g, '\\u003c');
|
|
11
|
+
|
|
12
|
+
const parseCoord = value => {
|
|
13
|
+
if (value === null || value === undefined || value === '') {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const n = Number(value);
|
|
17
|
+
if (!Number.isFinite(n) || Math.abs(n) < 0.000001) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return n;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const resolveAddressCoords = address => {
|
|
24
|
+
const lat = parseCoord(
|
|
25
|
+
address?.latitude ??
|
|
26
|
+
address?.lat ??
|
|
27
|
+
address?.map?.latitude ??
|
|
28
|
+
address?.map?.lat ??
|
|
29
|
+
address?.geo?.latitude,
|
|
30
|
+
);
|
|
31
|
+
const lng = parseCoord(
|
|
32
|
+
address?.longitude ??
|
|
33
|
+
address?.lng ??
|
|
34
|
+
address?.lon ??
|
|
35
|
+
address?.map?.longitude ??
|
|
36
|
+
address?.map?.lng ??
|
|
37
|
+
address?.map?.lon ??
|
|
38
|
+
address?.geo?.longitude,
|
|
39
|
+
);
|
|
40
|
+
if (lat === null || lng === null) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return {lat, lng};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const buildStaticMapUrl = ({apiKey, markers, size = '640x320'}) => {
|
|
47
|
+
if (!apiKey || !Array.isArray(markers) || markers.length === 0) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const markerParams = markers
|
|
51
|
+
.slice(0, 40)
|
|
52
|
+
.map(
|
|
53
|
+
m =>
|
|
54
|
+
`markers=color:red%7C${encodeURIComponent(`${m.lat},${m.lng}`)}`,
|
|
55
|
+
)
|
|
56
|
+
.join('&');
|
|
57
|
+
const center = markers[0];
|
|
58
|
+
return `https://maps.googleapis.com/maps/api/staticmap?size=${size}&maptype=roadmap¢er=${center.lat},${center.lng}&zoom=${markers.length === 1 ? 14 : 11}&${markerParams}&key=${encodeURIComponent(apiKey)}`;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Fallback without Google key — OpenStreetMap static (multi-marker). */
|
|
62
|
+
const buildOsmStaticMapUrl = (markers, size = '640x320') => {
|
|
63
|
+
if (!Array.isArray(markers) || markers.length === 0) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const center = markers[0];
|
|
67
|
+
const zoom = markers.length === 1 ? 14 : 11;
|
|
68
|
+
const markerParams = markers
|
|
69
|
+
.slice(0, 40)
|
|
70
|
+
.map(m => `markers=${m.lat},${m.lng},red-pushpin`)
|
|
71
|
+
.join('&');
|
|
72
|
+
return `https://staticmap.openstreetmap.de/staticmap.php?center=${center.lat},${center.lng}&zoom=${zoom}&size=${size}&maptype=mapnik&${markerParams}`;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** Interactive Leaflet map HTML for web iframe (no API key).
|
|
76
|
+
* Pass explicit width/height (px) so the map fills the iframe — % height
|
|
77
|
+
* often resolves to 0/wrong size inside srcDoc iframes.
|
|
78
|
+
*/
|
|
79
|
+
const buildLeafletMapHtml = (markers, {width = 0, height = 360} = {}) => {
|
|
80
|
+
if (!Array.isArray(markers) || markers.length === 0) {
|
|
81
|
+
return '';
|
|
82
|
+
}
|
|
83
|
+
const points = markers.slice(0, 40).map(m => ({
|
|
84
|
+
lat: Number(m.lat),
|
|
85
|
+
lng: Number(m.lng),
|
|
86
|
+
label: String(m.companyLabel || m.label || 'Franquia'),
|
|
87
|
+
}));
|
|
88
|
+
const center = points[0];
|
|
89
|
+
const w = width > 0 ? Math.round(width) : 0;
|
|
90
|
+
const h = height > 0 ? Math.round(height) : 360;
|
|
91
|
+
const sizeCss =
|
|
92
|
+
w > 0
|
|
93
|
+
? `html,body,#map{margin:0;padding:0;width:${w}px;height:${h}px;overflow:hidden;}`
|
|
94
|
+
: `html,body{margin:0;padding:0;width:100%;height:100%;overflow:hidden;}#map{position:absolute;inset:0;width:100%;height:100%;}`;
|
|
95
|
+
const markersJs = points
|
|
96
|
+
.map(
|
|
97
|
+
p =>
|
|
98
|
+
`L.marker([${p.lat}, ${p.lng}]).addTo(map).bindPopup(${serializeScriptString(
|
|
99
|
+
p.label,
|
|
100
|
+
)});`,
|
|
101
|
+
)
|
|
102
|
+
.join('\n');
|
|
103
|
+
const fitJs =
|
|
104
|
+
points.length > 1
|
|
105
|
+
? `map.fitBounds([${points
|
|
106
|
+
.map(p => `[${p.lat}, ${p.lng}]`)
|
|
107
|
+
.join(', ')}], {padding: [28, 28]});`
|
|
108
|
+
: '';
|
|
109
|
+
return `<!DOCTYPE html>
|
|
110
|
+
<html>
|
|
111
|
+
<head>
|
|
112
|
+
<meta charset="utf-8"/>
|
|
113
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
|
|
114
|
+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
|
|
115
|
+
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
|
116
|
+
<style>
|
|
117
|
+
${sizeCss}
|
|
118
|
+
.leaflet-container{width:100%!important;height:100%!important;font:12px/1.4 system-ui,sans-serif;}
|
|
119
|
+
</style>
|
|
120
|
+
</head>
|
|
121
|
+
<body>
|
|
122
|
+
<div id="map"></div>
|
|
123
|
+
<script>
|
|
124
|
+
var map = L.map('map', {preferCanvas: false}).setView([${center.lat}, ${center.lng}], ${points.length === 1 ? 14 : 11});
|
|
125
|
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
126
|
+
maxZoom: 19,
|
|
127
|
+
attribution: '© OpenStreetMap'
|
|
128
|
+
}).addTo(map);
|
|
129
|
+
${markersJs}
|
|
130
|
+
${fitJs}
|
|
131
|
+
function resizeMap(){
|
|
132
|
+
try {
|
|
133
|
+
var el = document.getElementById('map');
|
|
134
|
+
if (el && ${w} > 0) {
|
|
135
|
+
el.style.width = '${w}px';
|
|
136
|
+
el.style.height = '${h}px';
|
|
137
|
+
}
|
|
138
|
+
map.invalidateSize(true);
|
|
139
|
+
} catch (e) {}
|
|
140
|
+
}
|
|
141
|
+
setTimeout(resizeMap, 0);
|
|
142
|
+
setTimeout(resizeMap, 50);
|
|
143
|
+
setTimeout(resizeMap, 200);
|
|
144
|
+
setTimeout(resizeMap, 500);
|
|
145
|
+
window.addEventListener('resize', resizeMap);
|
|
146
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
147
|
+
new ResizeObserver(resizeMap).observe(document.body);
|
|
148
|
+
}
|
|
149
|
+
</script>
|
|
150
|
+
</body>
|
|
151
|
+
</html>`;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
export {
|
|
157
|
+
parseCoord,
|
|
158
|
+
resolveAddressCoords,
|
|
159
|
+
buildStaticMapUrl,
|
|
160
|
+
buildOsmStaticMapUrl,
|
|
161
|
+
buildLeafletMapHtml,
|
|
162
|
+
serializeScriptString,
|
|
163
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export const SHOP_DOMAIN_TYPE = 'SHOP';
|
|
2
|
+
|
|
3
|
+
export const normalizeEntityId = value =>
|
|
4
|
+
String(value?.id ?? value?.['@id'] ?? value ?? '').replace(/\D+/g, '');
|
|
5
|
+
|
|
6
|
+
export const resolveDomainId = domain => normalizeEntityId(domain);
|
|
7
|
+
|
|
8
|
+
export const resolveShowcaseDomainId = showcase =>
|
|
9
|
+
normalizeEntityId(showcase?.peopleDomain);
|
|
10
|
+
|
|
11
|
+
export const normalizeDomainType = value =>
|
|
12
|
+
String(value ?? '')
|
|
13
|
+
.trim()
|
|
14
|
+
.toUpperCase();
|
|
15
|
+
|
|
16
|
+
export const isShopDomain = domain =>
|
|
17
|
+
normalizeDomainType(domain?.domainType ?? domain?.domain_type) ===
|
|
18
|
+
SHOP_DOMAIN_TYPE;
|
|
19
|
+
|
|
20
|
+
const sortByDomain = (left, right) =>
|
|
21
|
+
String(left?.domain || '').localeCompare(String(right?.domain || ''));
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Builds domain rows for the Shop settings tab.
|
|
25
|
+
* Only domains with domainType SHOP are included (defensive client filter;
|
|
26
|
+
* the store query also requests domainType=SHOP).
|
|
27
|
+
*/
|
|
28
|
+
export const buildDomainRows = ({domains, showcases}) => {
|
|
29
|
+
const showcasesByDomainId = new Map();
|
|
30
|
+
const domainList = Array.isArray(domains) ? domains : [];
|
|
31
|
+
const showcaseList = Array.isArray(showcases) ? showcases : [];
|
|
32
|
+
|
|
33
|
+
showcaseList.forEach(showcase => {
|
|
34
|
+
const domainId = resolveShowcaseDomainId(showcase);
|
|
35
|
+
if (domainId) {
|
|
36
|
+
showcasesByDomainId.set(domainId, showcase);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return domainList
|
|
41
|
+
.filter(isShopDomain)
|
|
42
|
+
.sort(sortByDomain)
|
|
43
|
+
.map(domain => {
|
|
44
|
+
const domainId = resolveDomainId(domain);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
domain,
|
|
48
|
+
domainId,
|
|
49
|
+
showcase: showcasesByDomainId.get(domainId) || null,
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const buildShowcasePayload = ({companyId, row, patch = {}}) => {
|
|
55
|
+
const showcase = row?.showcase || {};
|
|
56
|
+
const domainId = row?.domainId || resolveShowcaseDomainId(showcase);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
active: showcase.active !== false,
|
|
60
|
+
company: `/people/${companyId}`,
|
|
61
|
+
id: showcase.id,
|
|
62
|
+
integrationKey: showcase.integrationKey || 'shop',
|
|
63
|
+
name: showcase.name || row?.domain?.domain,
|
|
64
|
+
peopleDomain: `/people_domains/${domainId}`,
|
|
65
|
+
settings: showcase.settings || {},
|
|
66
|
+
...patch,
|
|
67
|
+
};
|
|
68
|
+
};
|