@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,629 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* fluxo: outros | etapa: general-settings-maps
|
|
3
|
+
* wikiPage: https://github.com/ControleOnline/app-community/wiki/Smoke-Test-Flows
|
|
4
|
+
*
|
|
5
|
+
* @agents This section controls map keys, shop primary entry (mapa vs vitrine),
|
|
6
|
+
* franchise-locator enablement, franchise address categories, franchise list
|
|
7
|
+
* with visibility checkboxes and preview map pins for app_type=shop.
|
|
8
|
+
*/
|
|
9
|
+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
10
|
+
import {
|
|
11
|
+
ActivityIndicator,
|
|
12
|
+
Text,
|
|
13
|
+
TextInput,
|
|
14
|
+
TouchableOpacity,
|
|
15
|
+
View,
|
|
16
|
+
} from 'react-native';
|
|
17
|
+
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
18
|
+
import css from '@controleonline/ui-orders/src/react/css/orders';
|
|
19
|
+
|
|
20
|
+
import {useStore} from '@store';
|
|
21
|
+
import {
|
|
22
|
+
useGeneralSettingsPalette,
|
|
23
|
+
useGeneralSettingsStyles,
|
|
24
|
+
} from '../GeneralSettings.styles';
|
|
25
|
+
import GeneralSettingsSection from '../GeneralSettingsSection';
|
|
26
|
+
import {useGeneralSettingsConfig} from '../GeneralSettings.shared';
|
|
27
|
+
import {
|
|
28
|
+
GOOGLE_MAPS_ANDROID_API_KEY_CONFIG_KEY,
|
|
29
|
+
GOOGLE_MAPS_WEB_API_KEY_CONFIG_KEY,
|
|
30
|
+
resolveGoogleMapsSettings,
|
|
31
|
+
} from '@controleonline/ui-common/src/react/utils/googleMapsConfig';
|
|
32
|
+
import {
|
|
33
|
+
getEnabledShopHomeOptions,
|
|
34
|
+
normalizeBooleanConfig,
|
|
35
|
+
normalizeShopEntityId,
|
|
36
|
+
normalizeShopPrimaryEntry,
|
|
37
|
+
resolveShopSettings,
|
|
38
|
+
saveAndUpdateConfigValue,
|
|
39
|
+
SHOP_FRANCHISE_ADDRESS_CATEGORY_CONTEXT,
|
|
40
|
+
SHOP_FRANCHISE_ADDRESS_CATEGORY_IDS_CONFIG_KEY,
|
|
41
|
+
SHOP_FRANCHISE_LOCATOR_ENABLED_CONFIG_KEY,
|
|
42
|
+
SHOP_FRANCHISE_VISIBLE_ADDRESS_IDS_CONFIG_KEY,
|
|
43
|
+
SHOP_FRANCHISE_VISIBLE_COMPANY_IDS_CONFIG_KEY,
|
|
44
|
+
SHOP_HOME_OPTION_FRANCHISE_LOCATOR,
|
|
45
|
+
SHOP_HOME_OPTION_SALES,
|
|
46
|
+
SHOP_PRIMARY_ENTRY_CONFIG_KEY,
|
|
47
|
+
SHOP_SALES_PAGE_ENABLED_CONFIG_KEY,
|
|
48
|
+
} from '@controleonline/ui-common/src/react/utils/shopConfig';
|
|
49
|
+
import {fetchAllShopFranchiseDirectory} from '@controleonline/ui-common/src/react/utils/shopFranchises';
|
|
50
|
+
import ShopFranchiseLocatorSection from './shop/ShopFranchiseLocatorSection';
|
|
51
|
+
import {normalizeVisibleFranchiseIds} from './shop/shopFranchiseVisibility';
|
|
52
|
+
import {
|
|
53
|
+
resolveAddressLabel,
|
|
54
|
+
resolveCompanyLabel,
|
|
55
|
+
} from './shop/shopSettingsShared';
|
|
56
|
+
import {resolveAddressCoords} from './shop/mapsFranchiseMapHelpers';
|
|
57
|
+
import FranchiseMapPreview from './shop/FranchiseMapPreview';
|
|
58
|
+
|
|
59
|
+
const PRIMARY_ENTRY_LABELS = {
|
|
60
|
+
[SHOP_HOME_OPTION_SALES]: 'Vitrine do shop',
|
|
61
|
+
[SHOP_HOME_OPTION_FRANCHISE_LOCATOR]: 'Mapa das franquias',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const MapsSection = () => {
|
|
65
|
+
const {globalStyles} = css();
|
|
66
|
+
const localStyles = useGeneralSettingsStyles();
|
|
67
|
+
const themePalette = useGeneralSettingsPalette();
|
|
68
|
+
const categoriesStore = useStore('categories');
|
|
69
|
+
const categoryActions = categoriesStore.actions;
|
|
70
|
+
const {
|
|
71
|
+
currentCompany,
|
|
72
|
+
mainCompany,
|
|
73
|
+
effectiveCompanyConfigs,
|
|
74
|
+
saveConfig,
|
|
75
|
+
saveConfigs,
|
|
76
|
+
saveMainCompanyConfigs,
|
|
77
|
+
} = useGeneralSettingsConfig();
|
|
78
|
+
|
|
79
|
+
const [webGoogleMapsApiKey, setWebGoogleMapsApiKey] = useState('');
|
|
80
|
+
const [androidGoogleMapsApiKey, setAndroidGoogleMapsApiKey] = useState('');
|
|
81
|
+
const [franchiseAddressCategories, setFranchiseAddressCategories] =
|
|
82
|
+
useState([]);
|
|
83
|
+
const [franchiseAddressCategoryIds, setFranchiseAddressCategoryIds] =
|
|
84
|
+
useState([]);
|
|
85
|
+
const [isLoadingCategories, setIsLoadingCategories] = useState(false);
|
|
86
|
+
const [salesPageEnabled, setSalesPageEnabled] = useState(false);
|
|
87
|
+
const [franchiseLocatorEnabled, setFranchiseLocatorEnabled] = useState(false);
|
|
88
|
+
const [primaryEntry, setPrimaryEntry] = useState('');
|
|
89
|
+
const [franchiseDirectory, setFranchiseDirectory] = useState([]);
|
|
90
|
+
const [isLoadingFranchiseDirectory, setIsLoadingFranchiseDirectory] =
|
|
91
|
+
useState(false);
|
|
92
|
+
const [visibleFranchiseAddressIds, setVisibleFranchiseAddressIds] = useState(
|
|
93
|
+
[],
|
|
94
|
+
);
|
|
95
|
+
const [visibleFranchiseCompanyIds, setVisibleFranchiseCompanyIds] = useState(
|
|
96
|
+
[],
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const mainCompanyId = mainCompany?.id || mainCompany?.['@id'];
|
|
100
|
+
const mainCompanyIri = mainCompanyId
|
|
101
|
+
? '/people/' + mainCompanyId
|
|
102
|
+
: '';
|
|
103
|
+
const currentCompanyId = normalizeShopEntityId(
|
|
104
|
+
currentCompany?.id || currentCompany?.['@id'],
|
|
105
|
+
);
|
|
106
|
+
const shopSettings = useMemo(
|
|
107
|
+
() => resolveShopSettings(effectiveCompanyConfigs),
|
|
108
|
+
[effectiveCompanyConfigs],
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
const nextSettings = resolveGoogleMapsSettings(effectiveCompanyConfigs);
|
|
113
|
+
setWebGoogleMapsApiKey(nextSettings.webGoogleMapsApiKey);
|
|
114
|
+
setAndroidGoogleMapsApiKey(nextSettings.androidGoogleMapsApiKey);
|
|
115
|
+
setFranchiseAddressCategoryIds(
|
|
116
|
+
shopSettings.franchiseAddressCategoryIds || [],
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const nextSales = normalizeBooleanConfig(
|
|
120
|
+
effectiveCompanyConfigs?.[SHOP_SALES_PAGE_ENABLED_CONFIG_KEY],
|
|
121
|
+
);
|
|
122
|
+
const nextLocator = normalizeBooleanConfig(
|
|
123
|
+
effectiveCompanyConfigs?.[SHOP_FRANCHISE_LOCATOR_ENABLED_CONFIG_KEY],
|
|
124
|
+
);
|
|
125
|
+
setSalesPageEnabled(nextSales);
|
|
126
|
+
setFranchiseLocatorEnabled(nextLocator);
|
|
127
|
+
setPrimaryEntry(
|
|
128
|
+
normalizeShopPrimaryEntry(
|
|
129
|
+
effectiveCompanyConfigs?.[SHOP_PRIMARY_ENTRY_CONFIG_KEY],
|
|
130
|
+
{
|
|
131
|
+
salesPageEnabled: nextSales,
|
|
132
|
+
franchiseLocatorEnabled: nextLocator,
|
|
133
|
+
loyaltyCouponsEnabled: false,
|
|
134
|
+
},
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
setVisibleFranchiseCompanyIds(
|
|
138
|
+
normalizeVisibleFranchiseIds(
|
|
139
|
+
effectiveCompanyConfigs?.[SHOP_FRANCHISE_VISIBLE_COMPANY_IDS_CONFIG_KEY],
|
|
140
|
+
),
|
|
141
|
+
);
|
|
142
|
+
setVisibleFranchiseAddressIds(
|
|
143
|
+
normalizeVisibleFranchiseIds(
|
|
144
|
+
effectiveCompanyConfigs?.[SHOP_FRANCHISE_VISIBLE_ADDRESS_IDS_CONFIG_KEY],
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
}, [effectiveCompanyConfigs, shopSettings.franchiseAddressCategoryIds]);
|
|
148
|
+
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (!mainCompanyIri || !categoryActions?.getItems) {
|
|
151
|
+
setFranchiseAddressCategories([]);
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let isMounted = true;
|
|
156
|
+
setIsLoadingCategories(true);
|
|
157
|
+
|
|
158
|
+
categoryActions
|
|
159
|
+
.getItems({
|
|
160
|
+
context: SHOP_FRANCHISE_ADDRESS_CATEGORY_CONTEXT,
|
|
161
|
+
people: mainCompanyIri,
|
|
162
|
+
itemsPerPage: 100,
|
|
163
|
+
})
|
|
164
|
+
.then(result => {
|
|
165
|
+
const items = Array.isArray(result)
|
|
166
|
+
? result
|
|
167
|
+
: result?.member ||
|
|
168
|
+
result?.['hydra:member'] ||
|
|
169
|
+
categoriesStore.getters?.items ||
|
|
170
|
+
[];
|
|
171
|
+
|
|
172
|
+
if (isMounted) {
|
|
173
|
+
setFranchiseAddressCategories(Array.isArray(items) ? items : []);
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
.catch(() => {
|
|
177
|
+
if (isMounted) {
|
|
178
|
+
setFranchiseAddressCategories([]);
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
.finally(() => {
|
|
182
|
+
if (isMounted) {
|
|
183
|
+
setIsLoadingCategories(false);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
return () => {
|
|
188
|
+
isMounted = false;
|
|
189
|
+
};
|
|
190
|
+
}, [categoryActions, categoriesStore.getters, mainCompanyIri]);
|
|
191
|
+
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
if (!franchiseLocatorEnabled || !currentCompanyId) {
|
|
194
|
+
setFranchiseDirectory([]);
|
|
195
|
+
setIsLoadingFranchiseDirectory(false);
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
let cancelled = false;
|
|
199
|
+
setIsLoadingFranchiseDirectory(true);
|
|
200
|
+
fetchAllShopFranchiseDirectory({companyId: currentCompanyId})
|
|
201
|
+
.then(items => {
|
|
202
|
+
if (!cancelled) {
|
|
203
|
+
setFranchiseDirectory(Array.isArray(items) ? items : []);
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
.catch(() => {
|
|
207
|
+
if (!cancelled) {
|
|
208
|
+
setFranchiseDirectory([]);
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
.finally(() => {
|
|
212
|
+
if (!cancelled) {
|
|
213
|
+
setIsLoadingFranchiseDirectory(false);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
return () => {
|
|
217
|
+
cancelled = true;
|
|
218
|
+
};
|
|
219
|
+
}, [currentCompanyId, franchiseLocatorEnabled]);
|
|
220
|
+
|
|
221
|
+
const enabledHomeOptions = useMemo(
|
|
222
|
+
() =>
|
|
223
|
+
getEnabledShopHomeOptions({
|
|
224
|
+
salesPageEnabled,
|
|
225
|
+
franchiseLocatorEnabled,
|
|
226
|
+
loyaltyCouponsEnabled: false,
|
|
227
|
+
}),
|
|
228
|
+
[franchiseLocatorEnabled, salesPageEnabled],
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const primaryEntryOptions = useMemo(
|
|
232
|
+
() =>
|
|
233
|
+
enabledHomeOptions
|
|
234
|
+
.filter(
|
|
235
|
+
option =>
|
|
236
|
+
option === SHOP_HOME_OPTION_SALES ||
|
|
237
|
+
option === SHOP_HOME_OPTION_FRANCHISE_LOCATOR,
|
|
238
|
+
)
|
|
239
|
+
.map(option => ({
|
|
240
|
+
value: option,
|
|
241
|
+
label: PRIMARY_ENTRY_LABELS[option] || option,
|
|
242
|
+
})),
|
|
243
|
+
[enabledHomeOptions],
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
const mapMarkers = useMemo(() => {
|
|
247
|
+
// Exactly one pin per checked franchise (primary address with coordinates).
|
|
248
|
+
const selectedCompanyIds = new Set(
|
|
249
|
+
(visibleFranchiseCompanyIds || [])
|
|
250
|
+
.map(normalizeShopEntityId)
|
|
251
|
+
.filter(Boolean),
|
|
252
|
+
);
|
|
253
|
+
const markers = [];
|
|
254
|
+
const seenCompanies = new Set();
|
|
255
|
+
|
|
256
|
+
(Array.isArray(franchiseDirectory) ? franchiseDirectory : []).forEach(
|
|
257
|
+
company => {
|
|
258
|
+
const companyId = normalizeShopEntityId(company);
|
|
259
|
+
if (!companyId || !selectedCompanyIds.has(companyId)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (seenCompanies.has(companyId)) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const addresses = Array.isArray(company?.shopAddresses)
|
|
267
|
+
? company.shopAddresses
|
|
268
|
+
: [];
|
|
269
|
+
// Prefer first address that has valid lat/long.
|
|
270
|
+
let chosen = null;
|
|
271
|
+
for (const address of addresses) {
|
|
272
|
+
const coords = resolveAddressCoords(address);
|
|
273
|
+
if (coords) {
|
|
274
|
+
chosen = {address, coords};
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (!chosen) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
seenCompanies.add(companyId);
|
|
283
|
+
const addressId = normalizeShopEntityId(chosen.address);
|
|
284
|
+
markers.push({
|
|
285
|
+
...chosen.coords,
|
|
286
|
+
addressId: addressId || `${companyId}-primary`,
|
|
287
|
+
companyId,
|
|
288
|
+
label: resolveAddressLabel(chosen.address),
|
|
289
|
+
companyLabel: resolveCompanyLabel(company),
|
|
290
|
+
});
|
|
291
|
+
},
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
return markers;
|
|
295
|
+
}, [franchiseDirectory, visibleFranchiseCompanyIds]);
|
|
296
|
+
|
|
297
|
+
const saveMapsSettings = useCallback(async () => {
|
|
298
|
+
await saveConfigs({
|
|
299
|
+
[GOOGLE_MAPS_WEB_API_KEY_CONFIG_KEY]: String(
|
|
300
|
+
webGoogleMapsApiKey || '',
|
|
301
|
+
).trim(),
|
|
302
|
+
[GOOGLE_MAPS_ANDROID_API_KEY_CONFIG_KEY]: String(
|
|
303
|
+
androidGoogleMapsApiKey || '',
|
|
304
|
+
).trim(),
|
|
305
|
+
});
|
|
306
|
+
}, [androidGoogleMapsApiKey, saveConfigs, webGoogleMapsApiKey]);
|
|
307
|
+
|
|
308
|
+
const toggleFranchiseAddressCategory = useCallback(
|
|
309
|
+
category => {
|
|
310
|
+
const categoryId = String(category?.id || category?.['@id'] || '')
|
|
311
|
+
.replace(/\D+/g, '')
|
|
312
|
+
.trim();
|
|
313
|
+
if (!categoryId) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const nextIds = franchiseAddressCategoryIds.includes(categoryId)
|
|
317
|
+
? franchiseAddressCategoryIds.filter(id => id !== categoryId)
|
|
318
|
+
: [...franchiseAddressCategoryIds, categoryId];
|
|
319
|
+
setFranchiseAddressCategoryIds(nextIds);
|
|
320
|
+
const saved = saveMainCompanyConfigs?.({
|
|
321
|
+
[SHOP_FRANCHISE_ADDRESS_CATEGORY_IDS_CONFIG_KEY]: nextIds,
|
|
322
|
+
});
|
|
323
|
+
if (!saved) {
|
|
324
|
+
setFranchiseAddressCategoryIds(franchiseAddressCategoryIds);
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
[franchiseAddressCategoryIds, saveMainCompanyConfigs],
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
const toggleSalesPage = useCallback(() => {
|
|
331
|
+
const next = !salesPageEnabled;
|
|
332
|
+
saveAndUpdateConfigValue({
|
|
333
|
+
configKey: SHOP_SALES_PAGE_ENABLED_CONFIG_KEY,
|
|
334
|
+
nextValue: next,
|
|
335
|
+
saveConfig,
|
|
336
|
+
setValue: setSalesPageEnabled,
|
|
337
|
+
});
|
|
338
|
+
}, [salesPageEnabled, saveConfig]);
|
|
339
|
+
|
|
340
|
+
const toggleFranchiseLocator = useCallback(() => {
|
|
341
|
+
const next = !franchiseLocatorEnabled;
|
|
342
|
+
saveAndUpdateConfigValue({
|
|
343
|
+
configKey: SHOP_FRANCHISE_LOCATOR_ENABLED_CONFIG_KEY,
|
|
344
|
+
nextValue: next,
|
|
345
|
+
saveConfig,
|
|
346
|
+
setValue: setFranchiseLocatorEnabled,
|
|
347
|
+
});
|
|
348
|
+
}, [franchiseLocatorEnabled, saveConfig]);
|
|
349
|
+
|
|
350
|
+
const selectPrimaryEntry = useCallback(
|
|
351
|
+
value => {
|
|
352
|
+
if (primaryEntryOptions.length <= 1) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
saveAndUpdateConfigValue({
|
|
356
|
+
configKey: SHOP_PRIMARY_ENTRY_CONFIG_KEY,
|
|
357
|
+
nextValue: value,
|
|
358
|
+
saveConfig,
|
|
359
|
+
setValue: setPrimaryEntry,
|
|
360
|
+
});
|
|
361
|
+
},
|
|
362
|
+
[primaryEntryOptions.length, saveConfig],
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
return (
|
|
366
|
+
<GeneralSettingsSection
|
|
367
|
+
description="Chaves do Google Maps, tela principal do shop (mapa de franquias vs vitrine), localizador e categorias de endereço no mapa."
|
|
368
|
+
icon="map"
|
|
369
|
+
iconBackgroundColor={themePalette.cardIconBackground}
|
|
370
|
+
iconColor={themePalette.cardIconColor}
|
|
371
|
+
title="Mapas">
|
|
372
|
+
<View style={localStyles.fieldBlock} testID="maps-primary-entry-options">
|
|
373
|
+
<Text style={localStyles.fieldLabel}>Chave do Google Maps Web</Text>
|
|
374
|
+
<Text style={localStyles.helperText}>
|
|
375
|
+
Usada no display web e no mapa de franquias do shop.
|
|
376
|
+
</Text>
|
|
377
|
+
<TextInput
|
|
378
|
+
value={webGoogleMapsApiKey}
|
|
379
|
+
onChangeText={setWebGoogleMapsApiKey}
|
|
380
|
+
onBlur={saveMapsSettings}
|
|
381
|
+
autoCapitalize="none"
|
|
382
|
+
autoCorrect={false}
|
|
383
|
+
placeholder="Cole a chave do Google Maps para web"
|
|
384
|
+
placeholderTextColor={themePalette.inputPlaceholderText}
|
|
385
|
+
style={localStyles.input}
|
|
386
|
+
/>
|
|
387
|
+
</View>
|
|
388
|
+
|
|
389
|
+
<View style={localStyles.fieldBlock}>
|
|
390
|
+
<Text style={localStyles.fieldLabel}>Chave do Google Maps Android</Text>
|
|
391
|
+
<Text style={localStyles.helperText}>
|
|
392
|
+
Reserve para fluxos nativos. O display de entregas no Android usa a
|
|
393
|
+
chave web (WebView).
|
|
394
|
+
</Text>
|
|
395
|
+
<TextInput
|
|
396
|
+
value={androidGoogleMapsApiKey}
|
|
397
|
+
onChangeText={setAndroidGoogleMapsApiKey}
|
|
398
|
+
onBlur={saveMapsSettings}
|
|
399
|
+
autoCapitalize="none"
|
|
400
|
+
autoCorrect={false}
|
|
401
|
+
placeholder="Cole a chave do Google Maps para Android"
|
|
402
|
+
placeholderTextColor={themePalette.inputPlaceholderText}
|
|
403
|
+
style={localStyles.input}
|
|
404
|
+
/>
|
|
405
|
+
</View>
|
|
406
|
+
|
|
407
|
+
<View style={localStyles.settingRow}>
|
|
408
|
+
<View style={localStyles.settingCopy}>
|
|
409
|
+
<Text style={localStyles.statusLabel}>Vitrine do shop</Text>
|
|
410
|
+
<Text style={localStyles.settingDescription}>
|
|
411
|
+
Ativa a vitrine principal (categorias/produtos) como entrada do
|
|
412
|
+
app_type=shop.
|
|
413
|
+
</Text>
|
|
414
|
+
</View>
|
|
415
|
+
<TouchableOpacity
|
|
416
|
+
style={[
|
|
417
|
+
localStyles.statusChip,
|
|
418
|
+
salesPageEnabled
|
|
419
|
+
? localStyles.statusChipEnabled
|
|
420
|
+
: localStyles.statusChipDisabled,
|
|
421
|
+
]}
|
|
422
|
+
activeOpacity={0.85}
|
|
423
|
+
onPress={toggleSalesPage}>
|
|
424
|
+
<Icon
|
|
425
|
+
name={salesPageEnabled ? 'check-circle' : 'block'}
|
|
426
|
+
size={16}
|
|
427
|
+
color={
|
|
428
|
+
salesPageEnabled
|
|
429
|
+
? themePalette.badgeSelectedText
|
|
430
|
+
: themePalette.badgeDisabledText
|
|
431
|
+
}
|
|
432
|
+
/>
|
|
433
|
+
<Text
|
|
434
|
+
style={[
|
|
435
|
+
localStyles.statusChipText,
|
|
436
|
+
{
|
|
437
|
+
color: salesPageEnabled
|
|
438
|
+
? themePalette.badgeSelectedText
|
|
439
|
+
: themePalette.badgeDisabledText,
|
|
440
|
+
},
|
|
441
|
+
]}>
|
|
442
|
+
{salesPageEnabled ? 'Ativado' : 'Desativado'}
|
|
443
|
+
</Text>
|
|
444
|
+
</TouchableOpacity>
|
|
445
|
+
</View>
|
|
446
|
+
|
|
447
|
+
<View style={localStyles.settingRow}>
|
|
448
|
+
<View style={localStyles.settingCopy}>
|
|
449
|
+
<Text style={localStyles.statusLabel}>Localizador de franquias</Text>
|
|
450
|
+
<Text style={localStyles.settingDescription}>
|
|
451
|
+
Ativa o mapa das franquias como entrada do app_type=shop.
|
|
452
|
+
</Text>
|
|
453
|
+
</View>
|
|
454
|
+
<TouchableOpacity
|
|
455
|
+
testID="maps-franchise-locator-toggle"
|
|
456
|
+
style={[
|
|
457
|
+
localStyles.statusChip,
|
|
458
|
+
franchiseLocatorEnabled
|
|
459
|
+
? localStyles.statusChipEnabled
|
|
460
|
+
: localStyles.statusChipDisabled,
|
|
461
|
+
]}
|
|
462
|
+
activeOpacity={0.85}
|
|
463
|
+
onPress={toggleFranchiseLocator}>
|
|
464
|
+
<Icon
|
|
465
|
+
name={franchiseLocatorEnabled ? 'check-circle' : 'block'}
|
|
466
|
+
size={16}
|
|
467
|
+
color={
|
|
468
|
+
franchiseLocatorEnabled
|
|
469
|
+
? themePalette.badgeSelectedText
|
|
470
|
+
: themePalette.badgeDisabledText
|
|
471
|
+
}
|
|
472
|
+
/>
|
|
473
|
+
<Text
|
|
474
|
+
style={[
|
|
475
|
+
localStyles.statusChipText,
|
|
476
|
+
{
|
|
477
|
+
color: franchiseLocatorEnabled
|
|
478
|
+
? themePalette.badgeSelectedText
|
|
479
|
+
: themePalette.badgeDisabledText,
|
|
480
|
+
},
|
|
481
|
+
]}>
|
|
482
|
+
{franchiseLocatorEnabled ? 'Ativado' : 'Desativado'}
|
|
483
|
+
</Text>
|
|
484
|
+
</TouchableOpacity>
|
|
485
|
+
</View>
|
|
486
|
+
|
|
487
|
+
<View style={localStyles.fieldBlock}>
|
|
488
|
+
<Text style={localStyles.fieldLabel}>Tela principal do shop</Text>
|
|
489
|
+
<Text style={localStyles.helperText}>
|
|
490
|
+
{primaryEntryOptions.length === 0
|
|
491
|
+
? 'Ative a vitrine e/ou o localizador acima para escolher a entrada principal.'
|
|
492
|
+
: primaryEntryOptions.length === 1
|
|
493
|
+
? 'Apenas uma entrada está ativa — ela é usada automaticamente.'
|
|
494
|
+
: 'Escolha qual entrada o app_type=shop abre primeiro: mapa das franquias ou vitrine.'}
|
|
495
|
+
</Text>
|
|
496
|
+
{primaryEntryOptions.length > 0 && (
|
|
497
|
+
<View
|
|
498
|
+
style={{
|
|
499
|
+
flexDirection: 'row',
|
|
500
|
+
flexWrap: 'wrap',
|
|
501
|
+
gap: 8,
|
|
502
|
+
marginTop: 8,
|
|
503
|
+
}}>
|
|
504
|
+
{primaryEntryOptions.map(option => {
|
|
505
|
+
const selected = primaryEntry === option.value;
|
|
506
|
+
const locked = primaryEntryOptions.length === 1;
|
|
507
|
+
return (
|
|
508
|
+
<TouchableOpacity
|
|
509
|
+
key={option.value}
|
|
510
|
+
style={[
|
|
511
|
+
localStyles.statusChip,
|
|
512
|
+
selected
|
|
513
|
+
? localStyles.statusChipEnabled
|
|
514
|
+
: localStyles.statusChipDisabled,
|
|
515
|
+
]}
|
|
516
|
+
activeOpacity={locked ? 1 : 0.85}
|
|
517
|
+
onPress={() => selectPrimaryEntry(option.value)}
|
|
518
|
+
disabled={locked}>
|
|
519
|
+
<Icon
|
|
520
|
+
name={
|
|
521
|
+
option.value === SHOP_HOME_OPTION_FRANCHISE_LOCATOR
|
|
522
|
+
? 'map'
|
|
523
|
+
: 'storefront'
|
|
524
|
+
}
|
|
525
|
+
size={16}
|
|
526
|
+
color={
|
|
527
|
+
selected
|
|
528
|
+
? themePalette.badgeSelectedText
|
|
529
|
+
: themePalette.badgeDisabledText
|
|
530
|
+
}
|
|
531
|
+
/>
|
|
532
|
+
<Text
|
|
533
|
+
style={[
|
|
534
|
+
localStyles.statusChipText,
|
|
535
|
+
{
|
|
536
|
+
color: selected
|
|
537
|
+
? themePalette.badgeSelectedText
|
|
538
|
+
: themePalette.badgeDisabledText,
|
|
539
|
+
},
|
|
540
|
+
]}>
|
|
541
|
+
{option.label}
|
|
542
|
+
</Text>
|
|
543
|
+
</TouchableOpacity>
|
|
544
|
+
);
|
|
545
|
+
})}
|
|
546
|
+
</View>
|
|
547
|
+
)}
|
|
548
|
+
</View>
|
|
549
|
+
|
|
550
|
+
<View style={localStyles.fieldBlock}>
|
|
551
|
+
<Text style={localStyles.fieldLabel}>
|
|
552
|
+
Categorias de endereços no mapa de franquias
|
|
553
|
+
</Text>
|
|
554
|
+
{isLoadingCategories ? (
|
|
555
|
+
<ActivityIndicator size={22} color={themePalette.primary} />
|
|
556
|
+
) : franchiseAddressCategories.length === 0 ? (
|
|
557
|
+
<Text style={localStyles.helperText}>
|
|
558
|
+
Nenhuma categoria de endereço encontrada.
|
|
559
|
+
</Text>
|
|
560
|
+
) : (
|
|
561
|
+
<View>
|
|
562
|
+
{franchiseAddressCategories.map(category => {
|
|
563
|
+
const categoryId = String(category?.id || category?.['@id'] || '')
|
|
564
|
+
.replace(/\D+/g, '')
|
|
565
|
+
.trim();
|
|
566
|
+
const selected = franchiseAddressCategoryIds.includes(categoryId);
|
|
567
|
+
|
|
568
|
+
return (
|
|
569
|
+
<TouchableOpacity
|
|
570
|
+
activeOpacity={0.85}
|
|
571
|
+
key={category?.['@id'] || category?.id}
|
|
572
|
+
onPress={() => toggleFranchiseAddressCategory(category)}
|
|
573
|
+
style={[
|
|
574
|
+
localStyles.franchiseAddressOption,
|
|
575
|
+
selected && localStyles.franchiseAddressOptionActive,
|
|
576
|
+
]}>
|
|
577
|
+
<View style={localStyles.franchiseAddressOptionCopy}>
|
|
578
|
+
<Text style={localStyles.franchiseAddressName}>
|
|
579
|
+
{category?.name || `Categoria #${categoryId}`}
|
|
580
|
+
</Text>
|
|
581
|
+
</View>
|
|
582
|
+
<Icon
|
|
583
|
+
name={selected ? 'check-box' : 'check-box-outline-blank'}
|
|
584
|
+
size={22}
|
|
585
|
+
color={
|
|
586
|
+
selected ? themePalette.primary : themePalette.textMuted
|
|
587
|
+
}
|
|
588
|
+
/>
|
|
589
|
+
</TouchableOpacity>
|
|
590
|
+
);
|
|
591
|
+
})}
|
|
592
|
+
</View>
|
|
593
|
+
)}
|
|
594
|
+
</View>
|
|
595
|
+
|
|
596
|
+
{franchiseLocatorEnabled ? (
|
|
597
|
+
<>
|
|
598
|
+
<ShopFranchiseLocatorSection
|
|
599
|
+
currentCompanyId={currentCompanyId}
|
|
600
|
+
effectiveCompanyConfigs={effectiveCompanyConfigs}
|
|
601
|
+
localStyles={localStyles}
|
|
602
|
+
saveConfigs={saveConfigs}
|
|
603
|
+
themePalette={themePalette}
|
|
604
|
+
globalStyles={globalStyles}
|
|
605
|
+
onVisibilityChange={(nextCompanyIds, nextAddressIds) => {
|
|
606
|
+
setVisibleFranchiseCompanyIds(
|
|
607
|
+
Array.isArray(nextCompanyIds) ? nextCompanyIds : [],
|
|
608
|
+
);
|
|
609
|
+
setVisibleFranchiseAddressIds(
|
|
610
|
+
Array.isArray(nextAddressIds) ? nextAddressIds : [],
|
|
611
|
+
);
|
|
612
|
+
}}
|
|
613
|
+
/>
|
|
614
|
+
|
|
615
|
+
<FranchiseMapPreview
|
|
616
|
+
isLoading={isLoadingFranchiseDirectory}
|
|
617
|
+
mapMarkers={mapMarkers}
|
|
618
|
+
webGoogleMapsApiKey={webGoogleMapsApiKey}
|
|
619
|
+
localStyles={localStyles}
|
|
620
|
+
themePalette={themePalette}
|
|
621
|
+
visibleFranchiseCompanyIds={visibleFranchiseCompanyIds}
|
|
622
|
+
/>
|
|
623
|
+
</>
|
|
624
|
+
) : null}
|
|
625
|
+
</GeneralSettingsSection>
|
|
626
|
+
);
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
export default MapsSection;
|