@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,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {ScrollView, Text, TouchableOpacity, View} from 'react-native';
|
|
3
|
+
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
4
|
+
|
|
5
|
+
import useShopDomainShowcasesStyles from './ShopDomainShowcasesSection.styles';
|
|
6
|
+
|
|
7
|
+
const t = (type, key) => global.t?.t?.('configs', type, key);
|
|
8
|
+
|
|
9
|
+
const ShopDomainTabs = ({
|
|
10
|
+
onCreatePress,
|
|
11
|
+
onSelect,
|
|
12
|
+
rows,
|
|
13
|
+
selectedDomainId,
|
|
14
|
+
palette,
|
|
15
|
+
}) => {
|
|
16
|
+
const styles = useShopDomainShowcasesStyles();
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<View style={styles.tabsBlock}>
|
|
20
|
+
<ScrollView
|
|
21
|
+
horizontal
|
|
22
|
+
showsHorizontalScrollIndicator={false}
|
|
23
|
+
contentContainerStyle={styles.tabsRow}>
|
|
24
|
+
{rows.map(row => {
|
|
25
|
+
const selected = String(row.domainId) === String(selectedDomainId);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<TouchableOpacity
|
|
29
|
+
key={`shop-domain-tab-${row.domainId}`}
|
|
30
|
+
activeOpacity={0.85}
|
|
31
|
+
onPress={() => onSelect(row.domainId)}
|
|
32
|
+
style={[styles.tabButton, selected && styles.tabButtonActive]}>
|
|
33
|
+
<Icon
|
|
34
|
+
name="language"
|
|
35
|
+
size={14}
|
|
36
|
+
color={selected ? palette.buttonText : palette.listItemText}
|
|
37
|
+
/>
|
|
38
|
+
<Text
|
|
39
|
+
numberOfLines={1}
|
|
40
|
+
style={[
|
|
41
|
+
styles.tabText,
|
|
42
|
+
selected && {color: palette.buttonText},
|
|
43
|
+
]}>
|
|
44
|
+
{row.domain.domain}
|
|
45
|
+
</Text>
|
|
46
|
+
</TouchableOpacity>
|
|
47
|
+
);
|
|
48
|
+
})}
|
|
49
|
+
<TouchableOpacity
|
|
50
|
+
activeOpacity={0.85}
|
|
51
|
+
onPress={onCreatePress}
|
|
52
|
+
style={styles.addTabButton}>
|
|
53
|
+
<Icon name="add" size={16} color={palette.buttonText} />
|
|
54
|
+
<Text style={styles.addTabText}>{t('button', 'addShopDomain')}</Text>
|
|
55
|
+
</TouchableOpacity>
|
|
56
|
+
</ScrollView>
|
|
57
|
+
</View>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default ShopDomainTabs;
|
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Franchise locator visibility (companies + addresses) for shop general settings.
|
|
3
|
+
* Persist only on explicit user toggles — never auto-save prunes after refresh.
|
|
4
|
+
*/
|
|
5
|
+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
6
|
+
import {useNavigation} from '@react-navigation/native';
|
|
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 {
|
|
16
|
+
fetchAllShopFranchiseDirectory,
|
|
17
|
+
resolveFranchiseAddressCoords,
|
|
18
|
+
} from '@controleonline/ui-common/src/react/utils/shopFranchises';
|
|
19
|
+
import {
|
|
20
|
+
normalizeShopEntityId,
|
|
21
|
+
SHOP_FRANCHISE_VISIBLE_ADDRESS_IDS_CONFIG_KEY,
|
|
22
|
+
SHOP_FRANCHISE_VISIBLE_COMPANY_IDS_CONFIG_KEY,
|
|
23
|
+
} from '@controleonline/ui-common/src/react/utils/shopConfig';
|
|
24
|
+
import {
|
|
25
|
+
buildFranchiseAddressesById,
|
|
26
|
+
buildFranchiseCompaniesById,
|
|
27
|
+
normalizeVisibleFranchiseIds,
|
|
28
|
+
pruneFranchiseAddressIds,
|
|
29
|
+
resolveFranchiseMapAddress,
|
|
30
|
+
resolveSelectedFranchiseCompanies,
|
|
31
|
+
} from './shopFranchiseVisibility';
|
|
32
|
+
import {
|
|
33
|
+
SelectionModal,
|
|
34
|
+
buildNormalizedSearchText,
|
|
35
|
+
filterSelectableItems,
|
|
36
|
+
resolveAddressDetail,
|
|
37
|
+
resolveAddressLabel,
|
|
38
|
+
resolveCompanyLabel,
|
|
39
|
+
resolveCompanyMeta,
|
|
40
|
+
useLocalSelectionBrowser,
|
|
41
|
+
} from './shopSettingsShared';
|
|
42
|
+
|
|
43
|
+
const ShopFranchiseLocatorSection = ({
|
|
44
|
+
currentCompanyId,
|
|
45
|
+
effectiveCompanyConfigs,
|
|
46
|
+
localStyles,
|
|
47
|
+
saveConfigs,
|
|
48
|
+
themePalette,
|
|
49
|
+
globalStyles,
|
|
50
|
+
onVisibilityChange,
|
|
51
|
+
}) => {
|
|
52
|
+
const navigation = useNavigation();
|
|
53
|
+
const [visibleFranchiseCompanyIds, setVisibleFranchiseCompanyIds] = useState([]);
|
|
54
|
+
const [visibleFranchiseAddressIds, setVisibleFranchiseAddressIds] = useState([]);
|
|
55
|
+
const [franchiseCompanySearch, setFranchiseCompanySearch] = useState('');
|
|
56
|
+
const [franchiseDirectory, setFranchiseDirectory] = useState([]);
|
|
57
|
+
const [isLoadingFranchiseDirectory, setIsLoadingFranchiseDirectory] = useState(false);
|
|
58
|
+
const [franchiseCompanySelectorVisible, setFranchiseCompanySelectorVisible] = useState(false);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
setVisibleFranchiseCompanyIds(
|
|
62
|
+
normalizeVisibleFranchiseIds(
|
|
63
|
+
effectiveCompanyConfigs?.[SHOP_FRANCHISE_VISIBLE_COMPANY_IDS_CONFIG_KEY],
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
setVisibleFranchiseAddressIds(
|
|
67
|
+
normalizeVisibleFranchiseIds(
|
|
68
|
+
effectiveCompanyConfigs?.[SHOP_FRANCHISE_VISIBLE_ADDRESS_IDS_CONFIG_KEY],
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
}, [effectiveCompanyConfigs]);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (!currentCompanyId) {
|
|
75
|
+
setFranchiseDirectory([]);
|
|
76
|
+
setIsLoadingFranchiseDirectory(false);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
let cancelled = false;
|
|
80
|
+
setIsLoadingFranchiseDirectory(true);
|
|
81
|
+
fetchAllShopFranchiseDirectory({companyId: currentCompanyId})
|
|
82
|
+
.then(items => {
|
|
83
|
+
if (!cancelled) setFranchiseDirectory(Array.isArray(items) ? items : []);
|
|
84
|
+
})
|
|
85
|
+
.catch(() => {
|
|
86
|
+
if (!cancelled) setFranchiseDirectory([]);
|
|
87
|
+
})
|
|
88
|
+
.finally(() => {
|
|
89
|
+
if (!cancelled) setIsLoadingFranchiseDirectory(false);
|
|
90
|
+
});
|
|
91
|
+
return () => {
|
|
92
|
+
cancelled = true;
|
|
93
|
+
};
|
|
94
|
+
}, [currentCompanyId]);
|
|
95
|
+
|
|
96
|
+
const availableFranchiseCompanies = useMemo(
|
|
97
|
+
() => franchiseDirectory.filter(Boolean),
|
|
98
|
+
[franchiseDirectory],
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const franchiseCompanyBrowser = useLocalSelectionBrowser({
|
|
102
|
+
items: availableFranchiseCompanies,
|
|
103
|
+
visible: franchiseCompanySelectorVisible,
|
|
104
|
+
resolveSearchText: company =>
|
|
105
|
+
buildNormalizedSearchText(
|
|
106
|
+
resolveCompanyLabel(company),
|
|
107
|
+
resolveCompanyMeta(company),
|
|
108
|
+
),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const franchiseCompaniesById = useMemo(
|
|
112
|
+
() => buildFranchiseCompaniesById(availableFranchiseCompanies),
|
|
113
|
+
[availableFranchiseCompanies],
|
|
114
|
+
);
|
|
115
|
+
const franchiseAddressesById = useMemo(
|
|
116
|
+
() => buildFranchiseAddressesById(availableFranchiseCompanies),
|
|
117
|
+
[availableFranchiseCompanies],
|
|
118
|
+
);
|
|
119
|
+
const selectedFranchiseCompanies = useMemo(
|
|
120
|
+
() =>
|
|
121
|
+
resolveSelectedFranchiseCompanies({
|
|
122
|
+
companyIds: visibleFranchiseCompanyIds,
|
|
123
|
+
companiesById: franchiseCompaniesById,
|
|
124
|
+
}),
|
|
125
|
+
[franchiseCompaniesById, visibleFranchiseCompanyIds],
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const selectedFranchiseAddressGroups = useMemo(
|
|
129
|
+
() =>
|
|
130
|
+
selectedFranchiseCompanies.map(company => {
|
|
131
|
+
const linkedCompany = {
|
|
132
|
+
id: company?.id,
|
|
133
|
+
alias: company?.alias,
|
|
134
|
+
name: company?.name,
|
|
135
|
+
};
|
|
136
|
+
const addresses = (company?.shopAddresses || []).map(address => ({
|
|
137
|
+
...address,
|
|
138
|
+
linkedCompany,
|
|
139
|
+
}));
|
|
140
|
+
const selectedCount = addresses.filter(address =>
|
|
141
|
+
visibleFranchiseAddressIds.includes(normalizeShopEntityId(address)),
|
|
142
|
+
).length;
|
|
143
|
+
return {addresses, company, selectedCount};
|
|
144
|
+
}),
|
|
145
|
+
[selectedFranchiseCompanies, visibleFranchiseAddressIds],
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const hasFranchiseCompanySearch = String(franchiseCompanySearch || '').trim() !== '';
|
|
149
|
+
const visibleFranchiseCompanyResults = useMemo(() => {
|
|
150
|
+
if (!hasFranchiseCompanySearch) return [];
|
|
151
|
+
return filterSelectableItems({
|
|
152
|
+
items: availableFranchiseCompanies.filter(
|
|
153
|
+
company =>
|
|
154
|
+
!visibleFranchiseCompanyIds.includes(normalizeShopEntityId(company)),
|
|
155
|
+
),
|
|
156
|
+
query: franchiseCompanySearch,
|
|
157
|
+
resolveSearchText: company =>
|
|
158
|
+
buildNormalizedSearchText(
|
|
159
|
+
resolveCompanyLabel(company),
|
|
160
|
+
resolveCompanyMeta(company),
|
|
161
|
+
),
|
|
162
|
+
});
|
|
163
|
+
}, [
|
|
164
|
+
availableFranchiseCompanies,
|
|
165
|
+
franchiseCompanySearch,
|
|
166
|
+
hasFranchiseCompanySearch,
|
|
167
|
+
visibleFranchiseCompanyIds,
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (visibleFranchiseCompanyIds.length === 0) {
|
|
172
|
+
if (visibleFranchiseAddressIds.length === 0) return;
|
|
173
|
+
setVisibleFranchiseAddressIds([]);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (Object.keys(franchiseAddressesById).length === 0) return;
|
|
177
|
+
const nextAddressIds = pruneFranchiseAddressIds({
|
|
178
|
+
addressIds: visibleFranchiseAddressIds,
|
|
179
|
+
companyIds: visibleFranchiseCompanyIds,
|
|
180
|
+
addressesById: franchiseAddressesById,
|
|
181
|
+
});
|
|
182
|
+
if (
|
|
183
|
+
nextAddressIds.length === visibleFranchiseAddressIds.length &&
|
|
184
|
+
nextAddressIds.every(
|
|
185
|
+
(addressId, index) => addressId === visibleFranchiseAddressIds[index],
|
|
186
|
+
)
|
|
187
|
+
) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
setVisibleFranchiseAddressIds(nextAddressIds);
|
|
191
|
+
}, [franchiseAddressesById, visibleFranchiseAddressIds, visibleFranchiseCompanyIds]);
|
|
192
|
+
|
|
193
|
+
const saveFranchiseVisibility = useCallback(
|
|
194
|
+
(nextCompanyIds, nextAddressIds) => {
|
|
195
|
+
setVisibleFranchiseCompanyIds(nextCompanyIds);
|
|
196
|
+
setVisibleFranchiseAddressIds(nextAddressIds);
|
|
197
|
+
if (typeof onVisibilityChange === 'function') {
|
|
198
|
+
onVisibilityChange(nextCompanyIds, nextAddressIds);
|
|
199
|
+
}
|
|
200
|
+
return saveConfigs({
|
|
201
|
+
[SHOP_FRANCHISE_VISIBLE_COMPANY_IDS_CONFIG_KEY]: nextCompanyIds,
|
|
202
|
+
[SHOP_FRANCHISE_VISIBLE_ADDRESS_IDS_CONFIG_KEY]: nextAddressIds,
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
[onVisibilityChange, saveConfigs],
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const companyHasMapCoords = useCallback(company => {
|
|
209
|
+
const addresses = Array.isArray(company?.shopAddresses)
|
|
210
|
+
? company.shopAddresses
|
|
211
|
+
: [];
|
|
212
|
+
const primary = resolveFranchiseMapAddress(
|
|
213
|
+
addresses,
|
|
214
|
+
resolveFranchiseAddressCoords,
|
|
215
|
+
);
|
|
216
|
+
if (!primary) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
const coords = resolveFranchiseAddressCoords(primary);
|
|
220
|
+
return (
|
|
221
|
+
coords.latitude != null &&
|
|
222
|
+
coords.longitude != null &&
|
|
223
|
+
Math.abs(Number(coords.latitude)) > 0.000001 &&
|
|
224
|
+
Math.abs(Number(coords.longitude)) > 0.000001
|
|
225
|
+
);
|
|
226
|
+
}, []);
|
|
227
|
+
|
|
228
|
+
const toggleFranchiseCompany = useCallback(
|
|
229
|
+
company => {
|
|
230
|
+
const companyId = normalizeShopEntityId(company);
|
|
231
|
+
if (!companyId) return;
|
|
232
|
+
// Sem lat/long não pode entrar no mapa.
|
|
233
|
+
if (!companyHasMapCoords(company)) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const isSelected = visibleFranchiseCompanyIds.includes(companyId);
|
|
237
|
+
const nextCompanyIds = isSelected
|
|
238
|
+
? visibleFranchiseCompanyIds.filter(item => item !== companyId)
|
|
239
|
+
: [...visibleFranchiseCompanyIds, companyId];
|
|
240
|
+
|
|
241
|
+
// One primary address (first with coords) per franchise on the map.
|
|
242
|
+
const addresses = Array.isArray(company?.shopAddresses)
|
|
243
|
+
? company.shopAddresses
|
|
244
|
+
: [];
|
|
245
|
+
const companyAddressIds = addresses
|
|
246
|
+
.map(addr => normalizeShopEntityId(addr))
|
|
247
|
+
.filter(Boolean);
|
|
248
|
+
let primaryAddressId = null;
|
|
249
|
+
for (const addr of addresses) {
|
|
250
|
+
const coords = resolveFranchiseAddressCoords(addr);
|
|
251
|
+
const has =
|
|
252
|
+
coords.latitude != null &&
|
|
253
|
+
coords.longitude != null &&
|
|
254
|
+
Math.abs(Number(coords.latitude)) > 0.000001 &&
|
|
255
|
+
Math.abs(Number(coords.longitude)) > 0.000001;
|
|
256
|
+
if (has) {
|
|
257
|
+
primaryAddressId = normalizeShopEntityId(addr);
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
let nextAddressIds;
|
|
263
|
+
if (isSelected) {
|
|
264
|
+
// Deselecting: drop all addresses of this company.
|
|
265
|
+
nextAddressIds = visibleFranchiseAddressIds.filter(
|
|
266
|
+
addressId => !companyAddressIds.includes(addressId),
|
|
267
|
+
);
|
|
268
|
+
} else {
|
|
269
|
+
// Selecting: keep other companies' addresses + this primary only.
|
|
270
|
+
const withoutThisCompany = visibleFranchiseAddressIds.filter(
|
|
271
|
+
addressId => !companyAddressIds.includes(addressId),
|
|
272
|
+
);
|
|
273
|
+
nextAddressIds = primaryAddressId
|
|
274
|
+
? [...withoutThisCompany, primaryAddressId]
|
|
275
|
+
: withoutThisCompany;
|
|
276
|
+
// Prune orphans (company no longer selected).
|
|
277
|
+
nextAddressIds = nextAddressIds.filter(addressId => {
|
|
278
|
+
const address = franchiseAddressesById[addressId];
|
|
279
|
+
if (!address) {
|
|
280
|
+
return primaryAddressId === addressId;
|
|
281
|
+
}
|
|
282
|
+
return nextCompanyIds.includes(
|
|
283
|
+
normalizeShopEntityId(address?.linkedCompany),
|
|
284
|
+
);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
saveFranchiseVisibility(nextCompanyIds, nextAddressIds);
|
|
289
|
+
},
|
|
290
|
+
[
|
|
291
|
+
companyHasMapCoords,
|
|
292
|
+
franchiseAddressesById,
|
|
293
|
+
saveFranchiseVisibility,
|
|
294
|
+
visibleFranchiseAddressIds,
|
|
295
|
+
visibleFranchiseCompanyIds,
|
|
296
|
+
],
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
const toggleFranchiseAddress = useCallback(
|
|
300
|
+
address => {
|
|
301
|
+
const addressId = normalizeShopEntityId(address);
|
|
302
|
+
if (!addressId) return;
|
|
303
|
+
const nextAddressIds = visibleFranchiseAddressIds.includes(addressId)
|
|
304
|
+
? visibleFranchiseAddressIds.filter(item => item !== addressId)
|
|
305
|
+
: [...visibleFranchiseAddressIds, addressId];
|
|
306
|
+
saveFranchiseVisibility(visibleFranchiseCompanyIds, nextAddressIds);
|
|
307
|
+
},
|
|
308
|
+
[saveFranchiseVisibility, visibleFranchiseAddressIds, visibleFranchiseCompanyIds],
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
return (
|
|
312
|
+
<>
|
|
313
|
+
<View style={localStyles.fieldBlock} testID="maps-franchise-locator">
|
|
314
|
+
<Text style={localStyles.fieldLabel}>Franquias exibidas no localizador</Text>
|
|
315
|
+
<Text style={localStyles.helperText}>
|
|
316
|
+
Selecione quais empresas vinculadas como franquia podem aparecer no mapa do shop.
|
|
317
|
+
</Text>
|
|
318
|
+
<View style={localStyles.selectorRow}>
|
|
319
|
+
<TextInput
|
|
320
|
+
value={franchiseCompanySearch}
|
|
321
|
+
onChangeText={setFranchiseCompanySearch}
|
|
322
|
+
placeholder="Buscar franquia..."
|
|
323
|
+
placeholderTextColor={themePalette.inputPlaceholderText}
|
|
324
|
+
style={[localStyles.input, localStyles.selectorInput]}
|
|
325
|
+
/>
|
|
326
|
+
<TouchableOpacity
|
|
327
|
+
style={localStyles.selectorListButton}
|
|
328
|
+
activeOpacity={0.85}
|
|
329
|
+
onPress={() => setFranchiseCompanySelectorVisible(true)}>
|
|
330
|
+
<Icon name="view-list" size={18} color={themePalette.buttonIcon} />
|
|
331
|
+
<Text style={localStyles.selectorListButtonText}>Lista</Text>
|
|
332
|
+
</TouchableOpacity>
|
|
333
|
+
</View>
|
|
334
|
+
{isLoadingFranchiseDirectory ? (
|
|
335
|
+
<ActivityIndicator size="small" color={themePalette.loadingSpinner} style={localStyles.sectionLoader} />
|
|
336
|
+
) : String(franchiseCompanySearch || '').trim() && visibleFranchiseCompanyResults.length === 0 ? (
|
|
337
|
+
<View style={localStyles.emptyBox}>
|
|
338
|
+
<Text style={localStyles.emptyTitle}>Nenhuma franquia encontrada</Text>
|
|
339
|
+
<Text style={localStyles.emptyText}>Tente outro termo ou abra a lista completa ao lado.</Text>
|
|
340
|
+
</View>
|
|
341
|
+
) : (
|
|
342
|
+
visibleFranchiseCompanyResults.length > 0 && (
|
|
343
|
+
<View style={localStyles.printerList}>
|
|
344
|
+
{visibleFranchiseCompanyResults.map(company => {
|
|
345
|
+
const companyId = normalizeShopEntityId(company);
|
|
346
|
+
return (
|
|
347
|
+
<TouchableOpacity
|
|
348
|
+
key={`shop-franchise-company-search-${companyId}`}
|
|
349
|
+
style={localStyles.printerItem}
|
|
350
|
+
activeOpacity={0.85}
|
|
351
|
+
onPress={() => toggleFranchiseCompany(company)}>
|
|
352
|
+
<Icon name="storefront" size={20} color={themePalette.cardIconColor} />
|
|
353
|
+
<View style={localStyles.printerCopy}>
|
|
354
|
+
<Text style={localStyles.printerName}>{resolveCompanyLabel(company)}</Text>
|
|
355
|
+
<Text style={localStyles.printerDevice}>{resolveCompanyMeta(company) || 'Toque para liberar'}</Text>
|
|
356
|
+
</View>
|
|
357
|
+
</TouchableOpacity>
|
|
358
|
+
);
|
|
359
|
+
})}
|
|
360
|
+
</View>
|
|
361
|
+
)
|
|
362
|
+
)}
|
|
363
|
+
<Text style={localStyles.helperText}>
|
|
364
|
+
{availableFranchiseCompanies.length > 0
|
|
365
|
+
? `${availableFranchiseCompanies.length} franquia(s) · ${visibleFranchiseCompanyIds.length} no mapa.`
|
|
366
|
+
: 'Nenhuma franquia vinculada à empresa atual.'}
|
|
367
|
+
</Text>
|
|
368
|
+
{isLoadingFranchiseDirectory ? (
|
|
369
|
+
<ActivityIndicator
|
|
370
|
+
size="small"
|
|
371
|
+
color={themePalette.loadingSpinner}
|
|
372
|
+
style={localStyles.sectionLoader}
|
|
373
|
+
/>
|
|
374
|
+
) : availableFranchiseCompanies.length === 0 ? (
|
|
375
|
+
<View style={localStyles.emptyBox}>
|
|
376
|
+
<Text style={localStyles.emptyTitle}>Nenhuma franquia encontrada</Text>
|
|
377
|
+
<Text style={localStyles.emptyText}>
|
|
378
|
+
Cadastre vínculos linkType=franchisee em Minha empresa → Franquias.
|
|
379
|
+
</Text>
|
|
380
|
+
</View>
|
|
381
|
+
) : (
|
|
382
|
+
<View style={localStyles.printerList}>
|
|
383
|
+
{availableFranchiseCompanies.map(company => {
|
|
384
|
+
const companyId = normalizeShopEntityId(company);
|
|
385
|
+
const selected = visibleFranchiseCompanyIds.includes(companyId);
|
|
386
|
+
const addresses = Array.isArray(company?.shopAddresses)
|
|
387
|
+
? company.shopAddresses
|
|
388
|
+
: [];
|
|
389
|
+
const primaryAddress = resolveFranchiseMapAddress(
|
|
390
|
+
addresses,
|
|
391
|
+
resolveFranchiseAddressCoords,
|
|
392
|
+
);
|
|
393
|
+
const coords = primaryAddress
|
|
394
|
+
? resolveFranchiseAddressCoords(primaryAddress)
|
|
395
|
+
: {latitude: null, longitude: null};
|
|
396
|
+
const hasCoords =
|
|
397
|
+
coords.latitude != null &&
|
|
398
|
+
coords.longitude != null &&
|
|
399
|
+
Math.abs(Number(coords.latitude)) > 0.000001 &&
|
|
400
|
+
Math.abs(Number(coords.longitude)) > 0.000001;
|
|
401
|
+
const name = resolveCompanyLabel(company);
|
|
402
|
+
const addressLine = primaryAddress
|
|
403
|
+
? resolveAddressDetail(primaryAddress) ||
|
|
404
|
+
resolveAddressLabel(primaryAddress) ||
|
|
405
|
+
'Endereço não informado'
|
|
406
|
+
: 'Sem endereço cadastrado';
|
|
407
|
+
const coordsLine = hasCoords
|
|
408
|
+
? `${Number(coords.latitude).toFixed(6)}, ${Number(
|
|
409
|
+
coords.longitude,
|
|
410
|
+
).toFixed(6)}`
|
|
411
|
+
: 'Latitude/longitude não informadas';
|
|
412
|
+
// app-community#812: lápis de edição em todos os cards de franquia
|
|
413
|
+
const needsEdit = true;
|
|
414
|
+
|
|
415
|
+
return (
|
|
416
|
+
<View
|
|
417
|
+
key={`shop-franchise-card-${companyId}`}
|
|
418
|
+
style={[
|
|
419
|
+
localStyles.printerItem,
|
|
420
|
+
selected && localStyles.printerItemActive,
|
|
421
|
+
{alignItems: 'flex-start'},
|
|
422
|
+
]}>
|
|
423
|
+
<TouchableOpacity
|
|
424
|
+
activeOpacity={hasCoords ? 0.85 : 1}
|
|
425
|
+
disabled={!hasCoords}
|
|
426
|
+
onPress={() => {
|
|
427
|
+
if (!hasCoords) return;
|
|
428
|
+
toggleFranchiseCompany(company);
|
|
429
|
+
}}
|
|
430
|
+
style={{paddingTop: 2, marginRight: 10, opacity: hasCoords ? 1 : 0.4}}
|
|
431
|
+
accessibilityRole="checkbox"
|
|
432
|
+
accessibilityState={{checked: selected, disabled: !hasCoords}}
|
|
433
|
+
accessibilityLabel={
|
|
434
|
+
hasCoords
|
|
435
|
+
? `Exibir ${name} no mapa`
|
|
436
|
+
: `${name} sem latitude/longitude — edite o endereço`
|
|
437
|
+
}>
|
|
438
|
+
<Icon
|
|
439
|
+
name={
|
|
440
|
+
!hasCoords
|
|
441
|
+
? 'check-box-outline-blank'
|
|
442
|
+
: selected
|
|
443
|
+
? 'check-box'
|
|
444
|
+
: 'check-box-outline-blank'
|
|
445
|
+
}
|
|
446
|
+
size={24}
|
|
447
|
+
color={
|
|
448
|
+
!hasCoords
|
|
449
|
+
? themePalette.iconDisabled || themePalette.textMuted
|
|
450
|
+
: selected
|
|
451
|
+
? themePalette.iconActive || themePalette.primary
|
|
452
|
+
: themePalette.iconDisabled || themePalette.textMuted
|
|
453
|
+
}
|
|
454
|
+
/>
|
|
455
|
+
</TouchableOpacity>
|
|
456
|
+
<TouchableOpacity
|
|
457
|
+
activeOpacity={hasCoords ? 0.85 : 1}
|
|
458
|
+
disabled={!hasCoords}
|
|
459
|
+
onPress={() => {
|
|
460
|
+
if (!hasCoords) return;
|
|
461
|
+
toggleFranchiseCompany(company);
|
|
462
|
+
}}
|
|
463
|
+
style={[localStyles.printerCopy, {flex: 1, opacity: hasCoords ? 1 : 0.7}]}>
|
|
464
|
+
<Text style={localStyles.printerName}>{name}</Text>
|
|
465
|
+
<Text style={localStyles.printerDevice}>{addressLine}</Text>
|
|
466
|
+
<Text
|
|
467
|
+
style={[
|
|
468
|
+
localStyles.printerDevice,
|
|
469
|
+
!hasCoords && {opacity: 0.75},
|
|
470
|
+
]}>
|
|
471
|
+
{coordsLine}
|
|
472
|
+
</Text>
|
|
473
|
+
</TouchableOpacity>
|
|
474
|
+
{needsEdit ? (
|
|
475
|
+
<TouchableOpacity
|
|
476
|
+
activeOpacity={0.85}
|
|
477
|
+
onPress={() => {
|
|
478
|
+
if (!companyId) return;
|
|
479
|
+
navigation.navigate('MyCompanyDetails', {
|
|
480
|
+
clientId: companyId,
|
|
481
|
+
contextKey: 'company',
|
|
482
|
+
});
|
|
483
|
+
}}
|
|
484
|
+
style={{padding: 6}}
|
|
485
|
+
accessibilityLabel={`Editar endereço de ${name}`}>
|
|
486
|
+
<Icon
|
|
487
|
+
name="edit"
|
|
488
|
+
size={20}
|
|
489
|
+
color={
|
|
490
|
+
themePalette.primary || themePalette.cardIconColor
|
|
491
|
+
}
|
|
492
|
+
/>
|
|
493
|
+
</TouchableOpacity>
|
|
494
|
+
) : null}
|
|
495
|
+
</View>
|
|
496
|
+
);
|
|
497
|
+
})}
|
|
498
|
+
</View>
|
|
499
|
+
)}
|
|
500
|
+
</View>
|
|
501
|
+
|
|
502
|
+
<SelectionModal
|
|
503
|
+
visible={franchiseCompanySelectorVisible}
|
|
504
|
+
title="Selecionar franquias visiveis"
|
|
505
|
+
helperText="Toque nas empresas vinculadas para controlar quais franquias podem aparecer no localizador do shop."
|
|
506
|
+
browser={franchiseCompanyBrowser}
|
|
507
|
+
globalStyles={globalStyles}
|
|
508
|
+
onClose={() => setFranchiseCompanySelectorVisible(false)}
|
|
509
|
+
onSelect={toggleFranchiseCompany}
|
|
510
|
+
selectedIds={new Set(visibleFranchiseCompanyIds)}
|
|
511
|
+
emptyIconName="storefront"
|
|
512
|
+
emptyTitle="Nenhuma franquia encontrada"
|
|
513
|
+
emptyText="Nao ha empresas vinculadas como franquia para esta empresa."
|
|
514
|
+
resolveItemId={normalizeShopEntityId}
|
|
515
|
+
resolveItemLabel={resolveCompanyLabel}
|
|
516
|
+
resolveItemMeta={company => resolveCompanyMeta(company) || 'Toque para liberar'}
|
|
517
|
+
palette={themePalette}
|
|
518
|
+
searchPlaceholder="Pesquisar franquia..."
|
|
519
|
+
selectionMeta={() => 'Franquia liberada para o localizador'}
|
|
520
|
+
styles={localStyles}
|
|
521
|
+
/>
|
|
522
|
+
</>
|
|
523
|
+
);
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
export default ShopFranchiseLocatorSection;
|