@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.
Files changed (141) hide show
  1. package/.github/actions/workers/manager/action.yml +147 -0
  2. package/.github/actions/workers/qa/action.yml +44 -0
  3. package/.github/actions/workers/security/action.yml +44 -0
  4. package/.github/actions/workers/technical-documenter/action.yml +51 -0
  5. package/.github/workflows/manager-worker.yml +167 -0
  6. package/.github/workflows/publish-npm.yml +40 -0
  7. package/.github/workflows/pull-request-checks.yml +29 -0
  8. package/.scrutinizer.yml +24 -0
  9. package/AGENTS.md +56 -0
  10. package/FUNDING.yml +1 -0
  11. package/docs/technical/Cliente-Vendedor-Vinculo-e-Permissoes.md +121 -0
  12. package/docs/technical/Income-Statements-Demonstrativo.md +38 -0
  13. package/docs/technical/Oportunidades-Ordenacao-por-Data-de-Retorno.md +134 -0
  14. package/docs/technical/Propostas-Filtro-de-Status.md +147 -0
  15. package/docs/technical/Royalties-a-pagar-Franqueado.md +51 -0
  16. package/docs/technical/Visao-Vendedor-Comissoes.md +58 -0
  17. package/docs/wiki.md +1 -0
  18. package/package.json +43 -0
  19. package/scripts/validate-wiki-pointer.cjs +13 -0
  20. package/src/react/components/AnimatedModal.js +149 -0
  21. package/src/react/components/AnimatedModal.styles.js +21 -0
  22. package/src/react/components/CreateContractModal.js +151 -0
  23. package/src/react/components/CreateContractModal.styles.js +43 -0
  24. package/src/react/hooks/useToastMessage.js +59 -0
  25. package/src/react/index.js +4 -0
  26. package/src/react/pages/ModelTemplatesPage.js +1461 -0
  27. package/src/react/pages/ModelTemplatesPage.styles.js +441 -0
  28. package/src/react/pages/comissions/IncomeStatementDetailsModal.js +102 -0
  29. package/src/react/pages/comissions/IncomeStatementsFilters.js +120 -0
  30. package/src/react/pages/comissions/SellerCommissionsPage.js +368 -0
  31. package/src/react/pages/comissions/SellerCommissionsPage.styles.js +219 -0
  32. package/src/react/pages/comissions/incomeStatementsHelpers.js +233 -0
  33. package/src/react/pages/comissions/index.js +309 -0
  34. package/src/react/pages/comissions/index.styles.js +381 -0
  35. package/src/react/pages/comissions/sellerCommissionsHelpers.js +222 -0
  36. package/src/react/pages/crm/components/CrmHeader.js +117 -0
  37. package/src/react/pages/crm/components/MarketingEventsSection.js +142 -0
  38. package/src/react/pages/crm/components/MarketingEventsSection.styles.js +105 -0
  39. package/src/react/pages/crm/components/OpportunityCard.js +138 -0
  40. package/src/react/pages/crm/components/OpportunityFormModal.js +279 -0
  41. package/src/react/pages/crm/components/OpportunityList.js +113 -0
  42. package/src/react/pages/crm/components/OpportunitySkeletons.js +53 -0
  43. package/src/react/pages/crm/components/ProviderSelectModal.js +166 -0
  44. package/src/react/pages/crm/components/SelectModal.js +178 -0
  45. package/src/react/pages/crm/conversation.js +342 -0
  46. package/src/react/pages/crm/conversation.styles.js +206 -0
  47. package/src/react/pages/crm/hooks/useCrmData.js +494 -0
  48. package/src/react/pages/crm/hooks/useOpportunityForms.js +306 -0
  49. package/src/react/pages/crm/index.js +262 -0
  50. package/src/react/pages/crm/index.styles.js +13 -0
  51. package/src/react/pages/crm/marketingEventsHelpers.js +41 -0
  52. package/src/react/pages/crm/styles/card.styles.js +178 -0
  53. package/src/react/pages/crm/styles/layout.styles.js +184 -0
  54. package/src/react/pages/crm/styles/modal.styles.js +347 -0
  55. package/src/react/pages/home/index.js +559 -0
  56. package/src/react/pages/home/index.styles.js +268 -0
  57. package/src/react/pages/proposals/CreateProposalsModal.js +466 -0
  58. package/src/react/pages/proposals/CreateProposalsModal.styles.js +344 -0
  59. package/src/react/pages/proposals/CreateProposalsPickers.js +187 -0
  60. package/src/react/pages/proposals/CreateProposalsProductSection.js +117 -0
  61. package/src/react/pages/proposals/ProposalCard.js +112 -0
  62. package/src/react/pages/proposals/ProposalDetails.js +263 -0
  63. package/src/react/pages/proposals/ProposalDetails.styles.js +195 -0
  64. package/src/react/pages/proposals/index.js +488 -0
  65. package/src/react/pages/proposals/index.styles.js +248 -0
  66. package/src/react/pages/proposals/proposalListHelpers.js +216 -0
  67. package/src/react/pages/proposals/proposalNavigation.js +26 -0
  68. package/src/react/pages/royalties/ReceivablePage.js +233 -0
  69. package/src/react/pages/royalties/RoyaltiesPayablePage.js +260 -0
  70. package/src/react/pages/royalties/index.js +2 -0
  71. package/src/react/pages/royalties/royaltiesReceivableHelpers.js +68 -0
  72. package/src/react/pages/settings/GeneralSettings.js +317 -0
  73. package/src/react/pages/settings/GeneralSettings.shared.js +490 -0
  74. package/src/react/pages/settings/GeneralSettings.styles.js +746 -0
  75. package/src/react/pages/settings/GeneralSettingsSection.js +57 -0
  76. package/src/react/pages/settings/generalSettingsActiveTab.js +85 -0
  77. package/src/react/pages/settings/sections/CrmSection.js +281 -0
  78. package/src/react/pages/settings/sections/DeviceRuntimeFooterSection.js +128 -0
  79. package/src/react/pages/settings/sections/DisplayPreparationSection.js +155 -0
  80. package/src/react/pages/settings/sections/IntegrationsSection.js +392 -0
  81. package/src/react/pages/settings/sections/LogSection.js +322 -0
  82. package/src/react/pages/settings/sections/LoginSection.js +137 -0
  83. package/src/react/pages/settings/sections/LoyaltyProductPicker.js +230 -0
  84. package/src/react/pages/settings/sections/LoyaltySection.js +451 -0
  85. package/src/react/pages/settings/sections/MaintenanceSection.js +205 -0
  86. package/src/react/pages/settings/sections/MapsSection.js +629 -0
  87. package/src/react/pages/settings/sections/MenuCatalogSection.js +405 -0
  88. package/src/react/pages/settings/sections/OperationsSection.js +303 -0
  89. package/src/react/pages/settings/sections/OrderPaymentSection.js +379 -0
  90. package/src/react/pages/settings/sections/OrderPrintSection.js +308 -0
  91. package/src/react/pages/settings/sections/ShopSection.js +490 -0
  92. package/src/react/pages/settings/sections/shop/FranchiseMapPreview.js +124 -0
  93. package/src/react/pages/settings/sections/shop/ShopDomainCreateForm.js +57 -0
  94. package/src/react/pages/settings/sections/shop/ShopDomainPanel.js +184 -0
  95. package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.js +237 -0
  96. package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.styles.js +256 -0
  97. package/src/react/pages/settings/sections/shop/ShopDomainTabs.js +61 -0
  98. package/src/react/pages/settings/sections/shop/ShopFranchiseLocatorSection.js +526 -0
  99. package/src/react/pages/settings/sections/shop/ShopLoyaltySection.js +426 -0
  100. package/src/react/pages/settings/sections/shop/ShopSettingsSection.js +10 -0
  101. package/src/react/pages/settings/sections/shop/mapsFranchiseMapHelpers.js +163 -0
  102. package/src/react/pages/settings/sections/shop/shopDomainShowcasesUtils.js +68 -0
  103. package/src/react/pages/settings/sections/shop/shopFranchiseVisibility.js +158 -0
  104. package/src/react/pages/settings/sections/shop/shopSettingsShared.js +427 -0
  105. package/src/react/router/routes.js +135 -0
  106. package/src/react/utils/opportunityDate.js +82 -0
  107. package/src/react/utils/opportunityEditorReferences.js +76 -0
  108. package/src/react/utils/opportunityEmptyState.js +20 -0
  109. package/src/react/utils/opportunityPeople.js +111 -0
  110. package/src/react/utils/opportunityPhone.js +82 -0
  111. package/src/react/utils/opportunityStage.js +30 -0
  112. package/src/react/utils/opportunityStatusFilter.js +54 -0
  113. package/src/react/utils/proposalCreateHelpers.js +61 -0
  114. package/src/react/utils/proposalProductSelection.js +71 -0
  115. package/src/react/utils/royaltiesPayableParams.js +37 -0
  116. package/src/react/utils/translateWithFallback.js +42 -0
  117. package/src/store/crm/index.js +2 -0
  118. package/src/store/model/index.js +104 -0
  119. package/src/tests/browser/crm/create-proposal-product-category-filter.spec.js +149 -0
  120. package/src/tests/browser/crm/crm-index-status-filter.spec.js +263 -0
  121. package/src/tests/browser/crm/crm-opportunity-category-editor.spec.js +269 -0
  122. package/src/tests/browser/crm/royalties-payable.spec.js +122 -0
  123. package/src/tests/browser/crm/royalties-receivable.spec.js +121 -0
  124. package/src/tests/browser/crm/seller-commissions.spec.js +214 -0
  125. package/src/tests/browser/manager/general-settings-maps.spec.js +400 -0
  126. package/src/tests/react/pages/comissions/incomeStatementsHelpers.test.js +181 -0
  127. package/src/tests/react/pages/comissions/sellerCommissionsHelpers.test.js +132 -0
  128. package/src/tests/react/pages/crm/marketingEventsHelpers.test.cjs +53 -0
  129. package/src/tests/react/pages/crm/opportunitySearchParams.test.cjs +44 -0
  130. package/src/tests/react/pages/proposals/navigation.test.js +71 -0
  131. package/src/tests/react/pages/proposals/proposalListHelpers.test.js +42 -0
  132. package/src/tests/react/pages/royalties/royaltiesReceivableHelpers.test.js +60 -0
  133. package/src/tests/react/pages/settings/generalSettings.shared.test.js +102 -0
  134. package/src/tests/react/pages/settings/sections/shop/shopDomainShowcasesUtils.test.js +60 -0
  135. package/src/tests/react/pages/settings/sections/shop/shopFranchiseVisibility.test.js +80 -0
  136. package/src/tests/react/utils/opportunityEditorReferences.test.js +70 -0
  137. package/src/tests/react/utils/opportunityEmptyState.test.js +39 -0
  138. package/src/tests/react/utils/opportunityStatusFilter.test.cjs +81 -0
  139. package/src/tests/react/utils/proposalCreateHelpers.test.js +25 -0
  140. package/src/tests/react/utils/proposalProductSelection.test.js +76 -0
  141. package/src/tests/react/utils/royaltiesPayableParams.test.js +44 -0
@@ -0,0 +1,158 @@
1
+ /*
2
+ * @agents Pure helpers for shop franchise locator visibility.
3
+ * Selection pruning must stay local — never auto-persist when the directory
4
+ * is still loading or incomplete after refresh.
5
+ */
6
+
7
+ const normalizeEntityId = value => {
8
+ if (!value) {
9
+ return '';
10
+ }
11
+
12
+ if (typeof value === 'object') {
13
+ return normalizeEntityId(value?.['@id'] || value?.id);
14
+ }
15
+
16
+ return String(value)
17
+ .replace(/\D+/g, '')
18
+ .trim();
19
+ };
20
+
21
+ const parseConfigListValue = value => {
22
+ if (value === null || value === undefined || value === '') {
23
+ return [];
24
+ }
25
+
26
+ let current = value;
27
+ for (let depth = 0; depth < 3; depth += 1) {
28
+ if (Array.isArray(current)) {
29
+ return current;
30
+ }
31
+ if (typeof current !== 'string') {
32
+ break;
33
+ }
34
+ const trimmed = current.trim();
35
+ if (!trimmed) {
36
+ return [];
37
+ }
38
+ try {
39
+ current = JSON.parse(trimmed);
40
+ } catch {
41
+ return trimmed.split(/\r?\n|,/);
42
+ }
43
+ }
44
+
45
+ if (Array.isArray(current)) {
46
+ return current;
47
+ }
48
+
49
+ if (typeof current === 'string') {
50
+ return current.split(/\r?\n|,/);
51
+ }
52
+
53
+ return [];
54
+ };
55
+
56
+ const normalizeVisibleFranchiseIds = value =>
57
+ Array.from(
58
+ new Set(parseConfigListValue(value).map(normalizeEntityId).filter(Boolean)),
59
+ );
60
+
61
+ const pruneFranchiseAddressIds = ({
62
+ addressIds = [],
63
+ companyIds = [],
64
+ addressesById = {},
65
+ }) => {
66
+ const companyIdSet = new Set(
67
+ (companyIds || []).map(normalizeEntityId).filter(Boolean),
68
+ );
69
+
70
+ return (addressIds || [])
71
+ .map(normalizeEntityId)
72
+ .filter(Boolean)
73
+ .filter(addressId => {
74
+ const address = addressesById[addressId];
75
+ if (!address) {
76
+ return false;
77
+ }
78
+ const linkedCompanyId = normalizeEntityId(address?.linkedCompany);
79
+ return Boolean(linkedCompanyId && companyIdSet.has(linkedCompanyId));
80
+ });
81
+ };
82
+
83
+ const resolveSelectedFranchiseCompanies = ({
84
+ companyIds = [],
85
+ companiesById = {},
86
+ }) =>
87
+ (companyIds || [])
88
+ .map(normalizeEntityId)
89
+ .filter(Boolean)
90
+ .map(companyId => {
91
+ const company = companiesById[companyId];
92
+ if (company) {
93
+ return company;
94
+ }
95
+ return {
96
+ id: companyId,
97
+ alias: `Franquia #${companyId}`,
98
+ name: `Franquia #${companyId}`,
99
+ shopAddresses: [],
100
+ __orphan: true,
101
+ };
102
+ });
103
+
104
+ const buildFranchiseAddressesById = (directory = []) => {
105
+ const map = {};
106
+ (directory || []).forEach(company => {
107
+ const linkedCompany = {
108
+ id: company?.id,
109
+ alias: company?.alias,
110
+ name: company?.name,
111
+ };
112
+ (company?.shopAddresses || []).forEach(address => {
113
+ const addressId = normalizeEntityId(address);
114
+ if (addressId) {
115
+ map[addressId] = {...address, linkedCompany};
116
+ }
117
+ });
118
+ });
119
+ return map;
120
+ };
121
+
122
+ const buildFranchiseCompaniesById = (directory = []) => {
123
+ const map = {};
124
+ (directory || []).forEach(company => {
125
+ const companyId = normalizeEntityId(company);
126
+ if (companyId) {
127
+ map[companyId] = company;
128
+ }
129
+ });
130
+ return map;
131
+ };
132
+
133
+ const resolveFranchiseMapAddress = (addresses = [], resolveCoordinates) => {
134
+ const list = Array.isArray(addresses) ? addresses : [];
135
+ const resolver = typeof resolveCoordinates === 'function'
136
+ ? resolveCoordinates
137
+ : () => ({latitude: null, longitude: null});
138
+ return list.find(address => {
139
+ const coordinates = resolver(address);
140
+ return (
141
+ coordinates?.latitude != null &&
142
+ coordinates?.longitude != null &&
143
+ Math.abs(Number(coordinates.latitude)) > 0.000001 &&
144
+ Math.abs(Number(coordinates.longitude)) > 0.000001
145
+ );
146
+ }) || list[0] || null;
147
+ };
148
+
149
+ module.exports = {
150
+ buildFranchiseAddressesById,
151
+ buildFranchiseCompaniesById,
152
+ normalizeFranchiseEntityId: normalizeEntityId,
153
+ normalizeVisibleFranchiseIds,
154
+ parseConfigListValue,
155
+ pruneFranchiseAddressIds,
156
+ resolveFranchiseMapAddress,
157
+ resolveSelectedFranchiseCompanies,
158
+ };
@@ -0,0 +1,427 @@
1
+ /*
2
+ * @agents Shared shop settings UI helpers (selection, product search, labels).
3
+ */
4
+ import React, {useEffect, useMemo, useState} from 'react';
5
+ import {
6
+ ActivityIndicator,
7
+ ScrollView,
8
+ Text,
9
+ TextInput,
10
+ TouchableOpacity,
11
+ View,
12
+ } from 'react-native';
13
+ import Icon from 'react-native-vector-icons/MaterialIcons';
14
+ import AnimatedModal from '@controleonline/ui-common/src/react/components/AnimatedModal';
15
+ import {searchCompanyProducts} from '@controleonline/ui-common/src/react/utils/commercialDocumentOrders';
16
+ import {buildAddressOptionSummary} from '@controleonline/ui-common/src/react/utils/entityDisplay';
17
+ import {resolveFranchiseCompanyLabel} from '@controleonline/ui-common/src/react/utils/shopFranchises';
18
+ import {normalizeShopEntityId, normalizeShopProductId} from '@controleonline/ui-common/src/react/utils/shopConfig';
19
+
20
+ export const resolveProductLabel = product => {
21
+ const normalizedId = normalizeShopProductId(product);
22
+ return (
23
+ String(
24
+ product?.product ||
25
+ product?.name ||
26
+ product?.description ||
27
+ (normalizedId ? `Produto #${normalizedId}` : 'Produto'),
28
+ ).trim() || 'Produto'
29
+ );
30
+ };
31
+
32
+ export const resolveProductMeta = product => {
33
+ const sku = String(product?.sku || '').trim();
34
+ const price = Number(product?.price || 0);
35
+ const priceLabel = Number.isFinite(price)
36
+ ? `R$ ${price.toFixed(2).replace('.', ',')}`
37
+ : '';
38
+
39
+ return [sku ? `SKU ${sku}` : null, price > 0 ? priceLabel : null]
40
+ .filter(Boolean)
41
+ .join(' • ');
42
+ };
43
+
44
+ export const resolveCompanyLabel = company =>
45
+ resolveFranchiseCompanyLabel(company) || 'Franquia';
46
+
47
+ export const resolveCompanyMeta = company => {
48
+ const documentLabel = Array.isArray(company?.document)
49
+ ? String(company?.document?.[0]?.document || '').trim()
50
+ : String(company?.document?.document || company?.document || '').trim();
51
+
52
+ return documentLabel || 'Empresa vinculada como franquia';
53
+ };
54
+
55
+ export const resolveAddressLabel = address => {
56
+ const summary = buildAddressOptionSummary(address);
57
+ return summary.primary || address?.nickname || 'Endereco';
58
+ };
59
+
60
+ export const resolveAddressDetail = address => {
61
+ const summary = buildAddressOptionSummary(address);
62
+
63
+ return [
64
+ summary.secondary,
65
+ address?.searchFor,
66
+ address?.openingHours,
67
+ ]
68
+ .filter(Boolean)
69
+ .join(' • ');
70
+ };
71
+
72
+ export const buildNormalizedSearchText = (...values) =>
73
+ values
74
+ .flatMap(value => {
75
+ if (Array.isArray(value)) {
76
+ return value;
77
+ }
78
+
79
+ return [value];
80
+ })
81
+ .filter(Boolean)
82
+ .join(' ')
83
+ .toLowerCase();
84
+
85
+ export const filterSelectableItems = ({
86
+ items = [],
87
+ query = '',
88
+ resolveSearchText,
89
+ }) => {
90
+ const normalizedQuery = String(query || '').trim().toLowerCase();
91
+
92
+ if (!normalizedQuery) {
93
+ return items;
94
+ }
95
+
96
+ return items.filter(item =>
97
+ String(resolveSearchText?.(item) || '')
98
+ .toLowerCase()
99
+ .includes(normalizedQuery),
100
+ );
101
+ };
102
+
103
+ export const ConfigToggleRow = ({description, label, onToggle, palette, styles, value}) => (
104
+ <View style={styles.settingRow}>
105
+ <View style={styles.settingCopy}>
106
+ <Text style={styles.statusLabel}>{label}</Text>
107
+ <Text style={styles.settingDescription}>{description}</Text>
108
+ </View>
109
+ <TouchableOpacity
110
+ style={[
111
+ styles.statusChip,
112
+ value
113
+ ? styles.statusChipEnabled
114
+ : styles.statusChipDisabled,
115
+ ]}
116
+ activeOpacity={0.85}
117
+ onPress={onToggle}>
118
+ <Icon
119
+ name={value ? 'check-circle' : 'block'}
120
+ size={16}
121
+ color={value ? palette.badgeSelectedText : palette.badgeDisabledText}
122
+ />
123
+ <Text
124
+ style={[
125
+ styles.statusChipText,
126
+ {color: value ? palette.badgeSelectedText : palette.badgeDisabledText},
127
+ ]}>
128
+ {value ? 'Ativado' : 'Desativado'}
129
+ </Text>
130
+ </TouchableOpacity>
131
+ </View>
132
+ );
133
+
134
+ export const useShopProductBrowser = ({companyId, visible}) => {
135
+ const [query, setQuery] = useState('');
136
+ const [results, setResults] = useState([]);
137
+ const [isLoading, setIsLoading] = useState(false);
138
+
139
+ useEffect(() => {
140
+ if (!visible || !companyId) {
141
+ setResults([]);
142
+ setIsLoading(false);
143
+ return undefined;
144
+ }
145
+
146
+ const trimmedQuery = String(query || '').trim();
147
+ let cancelled = false;
148
+
149
+ const timeoutId = setTimeout(async () => {
150
+ setIsLoading(true);
151
+ try {
152
+ const items = await searchCompanyProducts({
153
+ companyId,
154
+ query: trimmedQuery,
155
+ });
156
+
157
+ if (!cancelled) {
158
+ setResults(Array.isArray(items) ? items : []);
159
+ }
160
+ } catch {
161
+ if (!cancelled) {
162
+ setResults([]);
163
+ }
164
+ } finally {
165
+ if (!cancelled) {
166
+ setIsLoading(false);
167
+ }
168
+ }
169
+ }, trimmedQuery ? 250 : 0);
170
+
171
+ return () => {
172
+ cancelled = true;
173
+ clearTimeout(timeoutId);
174
+ };
175
+ }, [companyId, query, visible]);
176
+
177
+ useEffect(() => {
178
+ if (!visible) {
179
+ setQuery('');
180
+ setResults([]);
181
+ setIsLoading(false);
182
+ }
183
+ }, [visible]);
184
+
185
+ return {
186
+ isLoading,
187
+ query,
188
+ results,
189
+ setQuery,
190
+ };
191
+ };
192
+
193
+ export const useShopProductSearch = companyId => {
194
+ const [query, setQuery] = useState('');
195
+ const [results, setResults] = useState([]);
196
+ const [isLoading, setIsLoading] = useState(false);
197
+
198
+ useEffect(() => {
199
+ const trimmedQuery = String(query || '').trim();
200
+
201
+ if (!companyId || !trimmedQuery) {
202
+ setResults([]);
203
+ setIsLoading(false);
204
+ return undefined;
205
+ }
206
+
207
+ let cancelled = false;
208
+ const timeoutId = setTimeout(async () => {
209
+ setIsLoading(true);
210
+ try {
211
+ const items = await searchCompanyProducts({
212
+ companyId,
213
+ query: trimmedQuery,
214
+ });
215
+
216
+ if (!cancelled) {
217
+ setResults(Array.isArray(items) ? items : []);
218
+ }
219
+ } catch {
220
+ if (!cancelled) {
221
+ setResults([]);
222
+ }
223
+ } finally {
224
+ if (!cancelled) {
225
+ setIsLoading(false);
226
+ }
227
+ }
228
+ }, 250);
229
+
230
+ return () => {
231
+ cancelled = true;
232
+ clearTimeout(timeoutId);
233
+ };
234
+ }, [companyId, query]);
235
+
236
+ return {
237
+ isLoading,
238
+ query,
239
+ results,
240
+ setQuery,
241
+ };
242
+ };
243
+
244
+ export const useLocalSelectionBrowser = ({items, visible, resolveSearchText}) => {
245
+ const [query, setQuery] = useState('');
246
+
247
+ useEffect(() => {
248
+ if (!visible) {
249
+ setQuery('');
250
+ }
251
+ }, [visible]);
252
+
253
+ const results = useMemo(
254
+ () =>
255
+ filterSelectableItems({
256
+ items,
257
+ query,
258
+ resolveSearchText,
259
+ }),
260
+ [items, query, resolveSearchText],
261
+ );
262
+
263
+ return {
264
+ isLoading: false,
265
+ query,
266
+ results,
267
+ setQuery,
268
+ };
269
+ };
270
+
271
+ export const SelectionModal = ({
272
+ visible,
273
+ title,
274
+ helperText,
275
+ browser,
276
+ globalStyles,
277
+ onClose,
278
+ onSelect,
279
+ selectedIds,
280
+ selectedItemId,
281
+ multiSelect = false,
282
+ emptyIconName = 'inventory-2',
283
+ emptyTitle = 'Nenhum item encontrado',
284
+ emptyText = 'A lista ainda nao trouxe itens para selecionar.',
285
+ resolveItemId = normalizeShopEntityId,
286
+ resolveItemLabel = item => String(item?.name || item?.label || 'Item'),
287
+ resolveItemMeta = () => 'Toque para selecionar',
288
+ searchPlaceholder = 'Pesquisar item...',
289
+ selectionMeta,
290
+ palette,
291
+ styles,
292
+ }) => {
293
+ const normalizedSelectedIds = selectedIds || new Set();
294
+ const normalizedSelectedItemId = String(selectedItemId || '').trim();
295
+
296
+ return (
297
+ <AnimatedModal visible={visible} onRequestClose={onClose}>
298
+ <View style={styles.selectionModal}>
299
+ <View style={styles.selectionModalHeader}>
300
+ <View style={styles.selectionModalHeaderCopy}>
301
+ <Text style={styles.selectionModalTitle}>{title}</Text>
302
+ {!!helperText && (
303
+ <Text style={styles.selectionModalSubtitle}>
304
+ {helperText}
305
+ </Text>
306
+ )}
307
+ </View>
308
+ <TouchableOpacity
309
+ onPress={onClose}
310
+ style={styles.selectionModalClose}
311
+ activeOpacity={0.85}>
312
+ <Icon name="close" size={20} color={palette.modalCloseIcon} />
313
+ </TouchableOpacity>
314
+ </View>
315
+
316
+ <View style={styles.selectionSearchWrap}>
317
+ <Icon
318
+ name="search"
319
+ size={18}
320
+ color={palette.inputIcon}
321
+ style={styles.selectionSearchIcon}
322
+ />
323
+ <TextInput
324
+ value={browser.query}
325
+ onChangeText={browser.setQuery}
326
+ placeholder={searchPlaceholder}
327
+ placeholderTextColor={palette.inputPlaceholderText}
328
+ style={styles.selectionSearchInput}
329
+ autoFocus={visible}
330
+ returnKeyType="search"
331
+ />
332
+ {!!browser.query && (
333
+ <TouchableOpacity
334
+ onPress={() => browser.setQuery('')}
335
+ activeOpacity={0.85}>
336
+ <Icon name="cancel" size={18} color={palette.inputIcon} />
337
+ </TouchableOpacity>
338
+ )}
339
+ </View>
340
+
341
+ <ScrollView
342
+ style={styles.selectionModalList}
343
+ contentContainerStyle={styles.selectionModalListContent}
344
+ keyboardShouldPersistTaps="handled"
345
+ showsVerticalScrollIndicator={false}>
346
+ {browser.isLoading ? (
347
+ <View style={styles.searchEmptyState}>
348
+ <ActivityIndicator size="small" color={palette.loadingSpinner} />
349
+ <Text style={styles.searchEmptyStateText}>
350
+ Carregando itens...
351
+ </Text>
352
+ </View>
353
+ ) : browser.results.length === 0 ? (
354
+ <View style={styles.searchEmptyState}>
355
+ <Icon name={emptyIconName} size={36} color={palette.iconDisabled} />
356
+ <Text style={styles.searchEmptyStateTitle}>
357
+ {emptyTitle}
358
+ </Text>
359
+ <Text style={styles.searchEmptyStateText}>
360
+ {String(browser.query || '').trim()
361
+ ? emptyText
362
+ : 'Nenhum item disponivel apareceu para selecao.'}
363
+ </Text>
364
+ </View>
365
+ ) : (
366
+ browser.results.map(item => {
367
+ const itemId = resolveItemId(item);
368
+ const selected = multiSelect
369
+ ? normalizedSelectedIds.has(itemId)
370
+ : itemId === normalizedSelectedItemId;
371
+
372
+ return (
373
+ <TouchableOpacity
374
+ key={`shop-picker-${itemId}`}
375
+ style={[
376
+ styles.selectionModalItem,
377
+ selected && styles.selectionModalItemActive,
378
+ ]}
379
+ activeOpacity={0.85}
380
+ onPress={() => onSelect(item)}>
381
+ <Icon
382
+ name={
383
+ selected
384
+ ? multiSelect
385
+ ? 'check-circle'
386
+ : 'radio-button-checked'
387
+ : multiSelect
388
+ ? 'add-circle-outline'
389
+ : 'radio-button-unchecked'
390
+ }
391
+ size={20}
392
+ color={selected ? palette.iconActive : palette.iconDisabled}
393
+ />
394
+ <View style={styles.selectionModalItemCopy}>
395
+ <Text style={styles.selectionModalItemTitle}>
396
+ {resolveItemLabel(item)}
397
+ </Text>
398
+ <Text style={styles.selectionModalItemMeta}>
399
+ {(selected
400
+ ? selectionMeta?.(item, {selected, multiSelect})
401
+ : null) ||
402
+ resolveItemMeta(item) ||
403
+ 'Toque para selecionar'}
404
+ </Text>
405
+ </View>
406
+ </TouchableOpacity>
407
+ );
408
+ })
409
+ )}
410
+ </ScrollView>
411
+
412
+ {multiSelect && (
413
+ <TouchableOpacity
414
+ style={[
415
+ globalStyles.button,
416
+ styles.primaryButton,
417
+ styles.selectionModalActionButton,
418
+ ]}
419
+ onPress={onClose}>
420
+ <Text style={styles.primaryButtonText}>Concluir selecao</Text>
421
+ </TouchableOpacity>
422
+ )}
423
+ </View>
424
+ </AnimatedModal>
425
+ );
426
+ };
427
+
@@ -0,0 +1,135 @@
1
+ import Comissions from '@controleonline/ui-crm/src/react/pages/comissions';
2
+ import SellerCommissionsPage from '@controleonline/ui-crm/src/react/pages/comissions/SellerCommissionsPage';
3
+ import RoyaltiesPayablePage from '@controleonline/ui-crm/src/react/pages/royalties/RoyaltiesPayablePage';
4
+ import RoyaltiesReceivablePage from '@controleonline/ui-crm/src/react/pages/royalties/ReceivablePage';
5
+ import CrmIndex from '@controleonline/ui-crm/src/react/pages/crm/index';
6
+ import ProposalsPage from '../pages/proposals';
7
+ import CrmConversation from '../pages/crm/conversation';
8
+ import GeneralSettings from '../pages/settings/GeneralSettings';
9
+ import ProposalDetails from '../pages/proposals/ProposalDetails';
10
+
11
+ const crmRoutes = [
12
+ {
13
+ // Company-wide Income Statements (demonstrativo por categorias).
14
+ // Route name kept for existing menu/config entries; title reflects the view.
15
+ // Role-specific commission/royalties screens are separate (ui-crm#21 filhas).
16
+ name: 'ComissionsPage',
17
+ component: Comissions,
18
+ options: {
19
+ showCompanyFilter: true,
20
+ showBottomToolBar: true,
21
+ headerShown: true,
22
+ headerBackVisible: true,
23
+ companyFilterMode: 'icon',
24
+ title: 'Demonstrativo',
25
+ },
26
+ },
27
+ {
28
+ name: 'IncomeStatementsPage',
29
+ component: Comissions,
30
+ options: {
31
+ showCompanyFilter: true,
32
+ showBottomToolBar: true,
33
+ headerShown: true,
34
+ headerBackVisible: true,
35
+ companyFilterMode: 'icon',
36
+ title: 'Demonstrativo',
37
+ },
38
+ },
39
+ {
40
+ name: 'SellerCommissionsPage',
41
+ component: SellerCommissionsPage,
42
+ options: {
43
+ showCompanyFilter: true,
44
+ showBottomToolBar: true,
45
+ headerShown: true,
46
+ headerBackVisible: true,
47
+ companyFilterMode: 'icon',
48
+ title: 'Minhas comissões',
49
+ },
50
+ },
51
+ {
52
+ name: 'RoyaltiesPayablePage',
53
+ component: RoyaltiesPayablePage,
54
+ path: 'royalties-a-pagar',
55
+ options: {
56
+ showCompanyFilter: true,
57
+ showBottomToolBar: true,
58
+ headerShown: true,
59
+ headerBackVisible: true,
60
+ companyFilterMode: 'icon',
61
+ title: 'Royalties a pagar',
62
+ },
63
+ },
64
+ {
65
+ name: 'RoyaltiesReceivablePage',
66
+ component: RoyaltiesReceivablePage,
67
+ path: 'royalties-a-receber',
68
+ options: {
69
+ showCompanyFilter: true,
70
+ showBottomToolBar: true,
71
+ headerShown: true,
72
+ headerBackVisible: true,
73
+ companyFilterMode: 'icon',
74
+ title: 'Royalties a receber',
75
+ },
76
+ },
77
+ {
78
+ name: 'ProposalDetails',
79
+ component: ProposalDetails,
80
+ options: {
81
+ showBottomToolBar: true,
82
+ headerShown: true,
83
+ headerBackVisible: true,
84
+ title: 'Proposta',
85
+ },
86
+ },
87
+ {
88
+ name: 'GeneralSettings',
89
+ component: GeneralSettings,
90
+ options: {
91
+ showCompanyFilter: true,
92
+ showBottomToolBar: true,
93
+ headerShown: true,
94
+ headerBackVisible: true,
95
+ companyFilterMode: 'icon',
96
+ title: 'Configurador geral',
97
+ },
98
+ },
99
+ {
100
+ name: 'CrmIndex',
101
+ component: CrmIndex,
102
+ options: {
103
+ showCompanyFilter: true,
104
+ showBottomToolBar: true,
105
+ headerShown: true,
106
+ headerBackVisible: true,
107
+ companyFilterMode: 'icon',
108
+ title: 'Oportunidades',
109
+ },
110
+ },
111
+ {
112
+ name: 'ProposalsIndex',
113
+ component: ProposalsPage,
114
+ options: {
115
+ showCompanyFilter: true,
116
+ showBottomToolBar: true,
117
+ headerShown: true,
118
+ headerBackVisible: true,
119
+ companyFilterMode: 'icon',
120
+ title: 'Propostas',
121
+ },
122
+ },
123
+ {
124
+ name: 'CrmConversation',
125
+ component: CrmConversation,
126
+ options: {
127
+ showBottomToolBar: false,
128
+ headerShown: false,
129
+ headerBackVisible: false,
130
+ title: 'Conversas',
131
+ },
132
+ },
133
+ ];
134
+
135
+ export default crmRoutes;