@controleonline/ui-crm 1.0.42 → 1.0.44

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 (31) hide show
  1. package/.github/workflows/integration-source-gate.yml +82 -0
  2. package/.github/workflows/manager-worker.yml +7 -155
  3. package/.github/workflows/publish-npm.yml +73 -22
  4. package/AGENTS.md +2 -0
  5. package/package.json +2 -2
  6. package/src/react/pages/crm/hooks/useCrmData.js +23 -17
  7. package/src/react/pages/proposals/CreateProposalsModal.js +1 -0
  8. package/src/react/pages/proposals/index.js +14 -33
  9. package/src/react/pages/settings/GeneralSettings.styles.js +2 -0
  10. package/src/react/pages/settings/sections/LoyaltyProductPicker.js +58 -145
  11. package/src/react/pages/settings/sections/LoyaltySection.js +35 -9
  12. package/src/react/pages/settings/sections/MapsFranchisePreview.js +102 -0
  13. package/src/react/pages/settings/sections/MapsMapasControls.js +262 -0
  14. package/src/react/pages/settings/sections/MapsSection.js +71 -247
  15. package/src/react/pages/settings/sections/loyaltyProductCompany.js +57 -0
  16. package/src/react/pages/settings/sections/mapsSectionHelpers.js +137 -0
  17. package/src/react/pages/settings/sections/shop/ShopFranchiseLocatorSection.js +7 -28
  18. package/src/react/pages/settings/sections/shop/ShopLoyaltySection.js +54 -8
  19. package/src/react/pages/settings/sections/shop/shopSettingsShared.js +32 -11
  20. package/src/react/utils/clientDetailsNavigation.js +56 -0
  21. package/src/react/utils/clientSellerVisibility.js +60 -0
  22. package/src/react/utils/proposalProductSelection.js +103 -13
  23. package/src/react/utils/proposalStatus.js +160 -0
  24. package/src/tests/browser/crm/create-proposal-product-category-filter.spec.js +25 -0
  25. package/src/tests/browser/manager/general-settings-maps.spec.js +173 -347
  26. package/src/tests/react/pages/settings/sections/loyaltyProductCompany.test.js +41 -0
  27. package/src/tests/react/pages/settings/sections/mapsSectionHelpers.test.js +38 -0
  28. package/src/tests/react/utils/clientDetailsNavigation.test.js +98 -0
  29. package/src/tests/react/utils/clientSellerVisibility.test.js +74 -0
  30. package/src/tests/react/utils/proposalProductSelection.test.js +57 -1
  31. package/src/tests/react/utils/proposalStatus.test.mjs +77 -0
@@ -1,19 +1,15 @@
1
1
  /*
2
2
  * @agents Shared product picker helpers for Loyalty (Fidelidade) settings.
3
+ * ProductSelectionModal reuses the canonical SelectionModal chrome from shop settings.
3
4
  */
4
5
  import React, {useEffect, 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
6
  import {normalizeShopProductId} from '@controleonline/ui-common/src/react/utils/shopConfig';
7
+ import {searchCompanyProducts} from '@controleonline/ui-common/src/react/utils/commercialDocumentOrders';
8
+ import {
9
+ filterProductsByCompany,
10
+ normalizeLoyaltyCompanyId,
11
+ } from './loyaltyProductCompany';
12
+ import {SelectionModal} from './shop/shopSettingsShared';
17
13
 
18
14
  export const resolveProductLabel = product => {
19
15
  const normalizedId = normalizeShopProductId(product);
@@ -27,25 +23,35 @@ export const resolveProductLabel = product => {
27
23
  );
28
24
  };
29
25
 
30
- export const resolveProductMeta = product => {
26
+ export const resolveProductMetaParts = product => {
31
27
  const sku = String(product?.sku || '').trim();
32
28
  const price = Number(product?.price || 0);
33
- const priceLabel = Number.isFinite(price)
34
- ? `R$ ${price.toFixed(2).replace('.', ',')}`
35
- : '';
29
+ const priceLabel =
30
+ Number.isFinite(price) && price > 0
31
+ ? `R$ ${price.toFixed(2).replace('.', ',')}`
32
+ : '';
33
+
34
+ return {
35
+ sku: sku ? `SKU ${sku}` : '',
36
+ priceLabel,
37
+ metaLine: [sku ? `SKU ${sku}` : null].filter(Boolean).join(' • '),
38
+ };
39
+ };
36
40
 
37
- return [sku ? `SKU ${sku}` : null, price > 0 ? priceLabel : null]
38
- .filter(Boolean)
39
- .join(' • ');
41
+ /** Prefer resolveProductMetaParts when layout needs price separated. */
42
+ export const resolveProductMeta = product => {
43
+ const {sku, priceLabel} = resolveProductMetaParts(product);
44
+ return [sku || null, priceLabel || null].filter(Boolean).join(' • ');
40
45
  };
41
46
 
42
47
  export const useProductBrowser = ({companyId, visible}) => {
43
48
  const [query, setQuery] = useState('');
44
49
  const [results, setResults] = useState([]);
45
50
  const [isLoading, setIsLoading] = useState(false);
51
+ const scopedCompanyId = normalizeLoyaltyCompanyId(companyId);
46
52
 
47
53
  useEffect(() => {
48
- if (!visible || !companyId) {
54
+ if (!visible || !scopedCompanyId) {
49
55
  setResults([]);
50
56
  setIsLoading(false);
51
57
  return undefined;
@@ -58,11 +64,11 @@ export const useProductBrowser = ({companyId, visible}) => {
58
64
  setIsLoading(true);
59
65
  try {
60
66
  const items = await searchCompanyProducts({
61
- companyId,
67
+ companyId: scopedCompanyId,
62
68
  query: trimmedQuery,
63
69
  });
64
70
  if (!cancelled) {
65
- setResults(Array.isArray(items) ? items : []);
71
+ setResults(filterProductsByCompany(items, scopedCompanyId));
66
72
  }
67
73
  } catch {
68
74
  if (!cancelled) {
@@ -79,7 +85,7 @@ export const useProductBrowser = ({companyId, visible}) => {
79
85
  cancelled = true;
80
86
  clearTimeout(timeoutId);
81
87
  };
82
- }, [companyId, query, visible]);
88
+ }, [scopedCompanyId, query, visible]);
83
89
 
84
90
  useEffect(() => {
85
91
  if (!visible) {
@@ -105,126 +111,33 @@ export const ProductSelectionModal = ({
105
111
  palette,
106
112
  styles,
107
113
  globalStyles,
108
- }) => {
109
- const selectedSet = selectedIds || new Set();
110
- const selectedId = String(selectedItemId || '').trim();
111
-
112
- return (
113
- <AnimatedModal visible={visible} onRequestClose={onClose}>
114
- <View style={styles.selectionModal}>
115
- <View style={styles.selectionModalHeader}>
116
- <View style={styles.selectionModalHeaderCopy}>
117
- <Text style={styles.selectionModalTitle}>{title}</Text>
118
- {helperText ? (
119
- <Text style={styles.selectionModalSubtitle}>{helperText}</Text>
120
- ) : null}
121
- </View>
122
- <TouchableOpacity
123
- style={styles.selectionModalClose}
124
- onPress={onClose}
125
- activeOpacity={0.85}>
126
- <Icon name="close" size={20} color={palette.iconDefault} />
127
- </TouchableOpacity>
128
- </View>
129
-
130
- <View style={styles.selectorRow}>
131
- <Icon
132
- name="search"
133
- size={18}
134
- color={palette.iconMuted}
135
- style={{marginRight: 8}}
136
- />
137
- <TextInput
138
- value={browser.query}
139
- onChangeText={browser.setQuery}
140
- placeholder="Pesquisar produto..."
141
- placeholderTextColor={palette.inputPlaceholderText}
142
- style={[styles.input, styles.selectorInput, {flex: 1}]}
143
- returnKeyType="search"
144
- />
145
- </View>
146
-
147
- <ScrollView
148
- style={styles.selectionModalList}
149
- contentContainerStyle={styles.selectionModalListContent}
150
- keyboardShouldPersistTaps="handled">
151
- {browser.isLoading ? (
152
- <ActivityIndicator
153
- size="small"
154
- color={palette.loadingSpinner}
155
- style={styles.sectionLoader}
156
- />
157
- ) : browser.results.length === 0 ? (
158
- <View style={styles.searchEmptyState}>
159
- <Icon name="inventory-2" size={28} color={palette.iconMuted} />
160
- <Text style={styles.searchEmptyStateTitle}>
161
- Nenhum produto encontrado
162
- </Text>
163
- <Text style={styles.searchEmptyStateText}>
164
- {String(browser.query || '').trim()
165
- ? 'Tente outro termo para localizar um produto existente.'
166
- : 'Nenhum item disponível apareceu para seleção.'}
167
- </Text>
168
- </View>
169
- ) : (
170
- browser.results.map(item => {
171
- const itemId = normalizeShopProductId(item);
172
- const selected = multiSelect
173
- ? selectedSet.has(itemId)
174
- : itemId === selectedId;
175
-
176
- return (
177
- <TouchableOpacity
178
- key={`loyalty-picker-${itemId}`}
179
- style={[
180
- styles.selectionModalItem,
181
- selected && styles.selectionModalItemActive,
182
- ]}
183
- activeOpacity={0.85}
184
- onPress={() => onSelect(item)}>
185
- <Icon
186
- name={
187
- selected
188
- ? multiSelect
189
- ? 'check-circle'
190
- : 'radio-button-checked'
191
- : multiSelect
192
- ? 'add-circle-outline'
193
- : 'radio-button-unchecked'
194
- }
195
- size={20}
196
- color={selected ? palette.iconActive : palette.iconDisabled}
197
- />
198
- <View style={styles.selectionModalItemCopy}>
199
- <Text style={styles.selectionModalItemTitle}>
200
- {resolveProductLabel(item)}
201
- </Text>
202
- <Text style={styles.selectionModalItemMeta}>
203
- {selected
204
- ? multiSelect
205
- ? 'Selecionado para participar da fidelidade'
206
- : 'Selecionado como brinde'
207
- : resolveProductMeta(item) || 'Toque para selecionar'}
208
- </Text>
209
- </View>
210
- </TouchableOpacity>
211
- );
212
- })
213
- )}
214
- </ScrollView>
215
-
216
- {multiSelect ? (
217
- <TouchableOpacity
218
- style={[
219
- globalStyles.button,
220
- styles.primaryButton,
221
- styles.selectionModalActionButton,
222
- ]}
223
- onPress={onClose}>
224
- <Text style={styles.primaryButtonText}>Concluir seleção</Text>
225
- </TouchableOpacity>
226
- ) : null}
227
- </View>
228
- </AnimatedModal>
229
- );
230
- };
114
+ }) => (
115
+ <SelectionModal
116
+ visible={visible}
117
+ title={title}
118
+ helperText={helperText}
119
+ browser={browser}
120
+ globalStyles={globalStyles}
121
+ onClose={onClose}
122
+ onSelect={onSelect}
123
+ selectedIds={selectedIds}
124
+ selectedItemId={selectedItemId}
125
+ multiSelect={multiSelect}
126
+ emptyIconName="inventory-2"
127
+ emptyTitle="Nenhum produto encontrado"
128
+ emptyText="Tente outro termo para localizar um produto existente."
129
+ resolveItemId={normalizeShopProductId}
130
+ resolveItemLabel={resolveProductLabel}
131
+ resolveItemMeta={product =>
132
+ resolveProductMeta(product) || 'Toque para selecionar'
133
+ }
134
+ searchPlaceholder="Pesquisar produto..."
135
+ selectionMeta={() =>
136
+ multiSelect
137
+ ? 'Selecionado para participar da fidelidade'
138
+ : 'Selecionado como brinde'
139
+ }
140
+ palette={palette}
141
+ styles={styles}
142
+ />
143
+ );
@@ -37,6 +37,7 @@ import {
37
37
  ProductSelectionModal,
38
38
  resolveProductLabel,
39
39
  resolveProductMeta,
40
+ resolveProductMetaParts,
40
41
  useProductBrowser,
41
42
  } from './LoyaltyProductPicker';
42
43
 
@@ -46,7 +47,7 @@ const LoyaltySection = () => {
46
47
  const {globalStyles} = css();
47
48
  const palette = useGeneralSettingsPalette();
48
49
  const styles = useGeneralSettingsStyles();
49
- const {currentCompany, effectiveCompanyConfigs, saveConfig} =
50
+ const {currentCompany, effectiveCompanyConfigs, saveConfig, selectedCompanyId} =
50
51
  useGeneralSettingsConfig();
51
52
  const productActions = useStore('products').actions;
52
53
 
@@ -62,11 +63,11 @@ const LoyaltySection = () => {
62
63
  const [giftVisible, setGiftVisible] = useState(false);
63
64
 
64
65
  const participantsBrowser = useProductBrowser({
65
- companyId: currentCompany?.id,
66
+ companyId: selectedCompanyId || currentCompany?.id,
66
67
  visible: participantsVisible,
67
68
  });
68
69
  const giftBrowser = useProductBrowser({
69
- companyId: currentCompany?.id,
70
+ companyId: selectedCompanyId || currentCompany?.id,
70
71
  visible: giftVisible,
71
72
  });
72
73
 
@@ -339,13 +340,26 @@ const LoyaltySection = () => {
339
340
  color={palette.iconDanger}
340
341
  />
341
342
  <View style={styles.printerCopy}>
342
- <Text style={styles.printerName}>
343
+ <Text style={styles.printerName} numberOfLines={2}>
343
344
  {resolveProductLabel(product)}
344
345
  </Text>
345
- <Text style={styles.printerDevice}>
346
- {resolveProductMeta(product) || 'Toque para remover'}
346
+ <Text style={styles.printerDevice} numberOfLines={1}>
347
+ {resolveProductMetaParts(product).metaLine ||
348
+ resolveProductMetaParts(product).sku ||
349
+ 'Toque para remover'}
347
350
  </Text>
348
351
  </View>
352
+ {!!resolveProductMetaParts(product).priceLabel && (
353
+ <Text
354
+ style={{
355
+ fontSize: 13,
356
+ fontWeight: '700',
357
+ color: palette.iconSuccess || palette.success,
358
+ marginLeft: 8,
359
+ }}>
360
+ {resolveProductMetaParts(product).priceLabel}
361
+ </Text>
362
+ )}
349
363
  </TouchableOpacity>
350
364
  );
351
365
  })}
@@ -396,14 +410,26 @@ const LoyaltySection = () => {
396
410
  color={palette.iconActive}
397
411
  />
398
412
  <View style={styles.printerCopy}>
399
- <Text style={styles.printerName}>
413
+ <Text style={styles.printerName} numberOfLines={2}>
400
414
  {resolveProductLabel(selectedGiftProduct)}
401
415
  </Text>
402
- <Text style={styles.printerDevice}>
403
- {resolveProductMeta(selectedGiftProduct) ||
416
+ <Text style={styles.printerDevice} numberOfLines={1}>
417
+ {resolveProductMetaParts(selectedGiftProduct).metaLine ||
418
+ resolveProductMetaParts(selectedGiftProduct).sku ||
404
419
  `ID ${giftProductId}`}
405
420
  </Text>
406
421
  </View>
422
+ {!!resolveProductMetaParts(selectedGiftProduct).priceLabel && (
423
+ <Text
424
+ style={{
425
+ fontSize: 13,
426
+ fontWeight: '700',
427
+ color: palette.iconSuccess || palette.success,
428
+ marginLeft: 8,
429
+ }}>
430
+ {resolveProductMetaParts(selectedGiftProduct).priceLabel}
431
+ </Text>
432
+ )}
407
433
  </View>
408
434
  </View>
409
435
  ) : (
@@ -0,0 +1,102 @@
1
+ /*
2
+ * @agents Preview map for selected franchise pins on Mapas (#360).
3
+ */
4
+ import React, {createElement} from 'react';
5
+ import {ActivityIndicator, Image, Platform, Text, View} from 'react-native';
6
+
7
+ const MapsFranchisePreview = ({
8
+ isLoadingFranchiseDirectory,
9
+ leafletMapHtml,
10
+ localStyles,
11
+ mapBoxWidth,
12
+ mapMarkers,
13
+ previewMapUrl,
14
+ setMapBoxWidth,
15
+ themePalette,
16
+ visibleFranchiseCompanyIds,
17
+ }) => (
18
+ <View
19
+ style={[localStyles.fieldBlock, {alignSelf: 'stretch', width: '100%'}]}
20
+ testID="maps-franchise-map">
21
+ <Text style={localStyles.fieldLabel}>Mapa das franquias</Text>
22
+ <Text style={localStyles.helperText}>
23
+ Pins das franquias marcadas acima (com latitude/longitude).
24
+ </Text>
25
+ {isLoadingFranchiseDirectory ? (
26
+ <ActivityIndicator
27
+ size="small"
28
+ color={themePalette.loadingSpinner || themePalette.primary}
29
+ style={localStyles.sectionLoader}
30
+ />
31
+ ) : mapMarkers.length === 0 ? (
32
+ <View style={localStyles.emptyBox}>
33
+ <Text style={localStyles.emptyTitle}>
34
+ Nenhum pin para exibir
35
+ </Text>
36
+ <Text style={localStyles.emptyText}>
37
+ Marque franquias com latitude/longitude na lista acima para
38
+ aparecerem no mapa.
39
+ </Text>
40
+ </View>
41
+ ) : (
42
+ <View style={{alignSelf: 'stretch', width: '100%'}}>
43
+ <View
44
+ onLayout={event => {
45
+ const nextWidth = Math.round(
46
+ event?.nativeEvent?.layout?.width || 0,
47
+ );
48
+ if (nextWidth > 0 && nextWidth !== mapBoxWidth) {
49
+ setMapBoxWidth(nextWidth);
50
+ }
51
+ }}
52
+ style={{
53
+ alignSelf: 'stretch',
54
+ width: '100%',
55
+ height: 360,
56
+ borderRadius: 8,
57
+ overflow: 'hidden',
58
+ backgroundColor: themePalette.inputBackground || '#eee',
59
+ }}>
60
+ {Platform.OS === 'web' && leafletMapHtml && mapBoxWidth > 0
61
+ ? createElement('iframe', {
62
+ key: `franchise-map-${mapBoxWidth}-${mapMarkers.length}`,
63
+ title: 'Mapa das franquias',
64
+ srcDoc: leafletMapHtml,
65
+ width: mapBoxWidth,
66
+ height: 360,
67
+ style: {
68
+ width: mapBoxWidth,
69
+ height: 360,
70
+ border: 'none',
71
+ display: 'block',
72
+ margin: 0,
73
+ padding: 0,
74
+ },
75
+ })
76
+ : previewMapUrl
77
+ ? (
78
+ <Image
79
+ source={{uri: previewMapUrl}}
80
+ style={{
81
+ width: '100%',
82
+ height: 360,
83
+ }}
84
+ resizeMode="cover"
85
+ accessibilityLabel="Mapa das franquias com pins"
86
+ />
87
+ )
88
+ : null}
89
+ </View>
90
+ <Text style={localStyles.helperText}>
91
+ {mapMarkers.length} pin(s) no mapa
92
+ {visibleFranchiseCompanyIds.length > 0
93
+ ? ` · ${visibleFranchiseCompanyIds.length} franquia(s) selecionada(s)`
94
+ : ''}
95
+ </Text>
96
+ </View>
97
+ )}
98
+ </View>
99
+
100
+ );
101
+
102
+ export default MapsFranchisePreview;