@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,57 @@
1
+ /*
2
+ * @agents This wrapper keeps the settings section chrome consistent.
3
+ * Individual sections only provide content, labels, and contextual metadata.
4
+ */
5
+ import React from 'react';
6
+ import {View, Text} from 'react-native';
7
+ import Icon from 'react-native-vector-icons/MaterialIcons';
8
+
9
+ import DefaultTooltip from '@controleonline/ui-default/src/react/components/help/DefaultTooltip';
10
+
11
+ import {
12
+ useGeneralSettingsPalette,
13
+ useGeneralSettingsStyles,
14
+ } from './GeneralSettings.styles';
15
+
16
+ const GeneralSettingsSection = ({
17
+ children,
18
+ description,
19
+ icon,
20
+ iconBackgroundColor,
21
+ iconColor,
22
+ title,
23
+ }) => {
24
+ const localStyles = useGeneralSettingsStyles();
25
+ const themePalette = useGeneralSettingsPalette();
26
+
27
+ return (
28
+ <View style={localStyles.sectionCard}>
29
+ <View style={localStyles.sectionHeader}>
30
+ <View
31
+ style={[
32
+ localStyles.sectionIconWrap,
33
+ {backgroundColor: iconBackgroundColor},
34
+ ]}>
35
+ <Icon name={icon} size={20} color={iconColor} />
36
+ </View>
37
+ <View style={localStyles.sectionHeaderCopy}>
38
+ <View style={localStyles.sectionTitleRow}>
39
+ <Text style={localStyles.sectionTitle}>{title}</Text>
40
+ {description ? (
41
+ <DefaultTooltip
42
+ accentColor={themePalette.iconInfo}
43
+ message={description}
44
+ style={localStyles.sectionTitleHelp}
45
+ title={title}
46
+ />
47
+ ) : null}
48
+ </View>
49
+ </View>
50
+ </View>
51
+
52
+ {children}
53
+ </View>
54
+ );
55
+ };
56
+
57
+ export default GeneralSettingsSection;
@@ -0,0 +1,85 @@
1
+ export const GENERAL_SETTINGS_ACTIVE_TAB_STORAGE_KEY =
2
+ 'controleonline.general-settings.active-tab';
3
+
4
+ /*
5
+ * @agents This storage helper remembers the last visible settings tab.
6
+ * The page still validates the stored value against the current available tabs.
7
+ */
8
+ const getGeneralSettingsStorage = () => {
9
+ const storage = globalThis?.localStorage;
10
+
11
+ if (
12
+ !storage ||
13
+ typeof storage.getItem !== 'function' ||
14
+ typeof storage.setItem !== 'function'
15
+ ) {
16
+ return null;
17
+ }
18
+
19
+ return storage;
20
+ };
21
+
22
+ export const readGeneralSettingsActiveTab = () => {
23
+ const storage = getGeneralSettingsStorage();
24
+
25
+ if (!storage) {
26
+ return '';
27
+ }
28
+
29
+ try {
30
+ return String(storage.getItem(GENERAL_SETTINGS_ACTIVE_TAB_STORAGE_KEY) || '')
31
+ .trim();
32
+ } catch {
33
+ return '';
34
+ }
35
+ };
36
+
37
+ export const writeGeneralSettingsActiveTab = value => {
38
+ const storage = getGeneralSettingsStorage();
39
+
40
+ if (!storage) {
41
+ return false;
42
+ }
43
+
44
+ const normalizedValue = String(value || '').trim();
45
+ if (!normalizedValue) {
46
+ return false;
47
+ }
48
+
49
+ try {
50
+ storage.setItem(GENERAL_SETTINGS_ACTIVE_TAB_STORAGE_KEY, normalizedValue);
51
+ return true;
52
+ } catch {
53
+ return false;
54
+ }
55
+ };
56
+
57
+ export const resolveGeneralSettingsActiveTab = ({
58
+ activeTab,
59
+ availableTabs = [],
60
+ fallbackTab = '',
61
+ storedTab = '',
62
+ }) => {
63
+ /*
64
+ * @agents The stored tab is only a preference.
65
+ * If it is no longer available, the current tab or the first valid tab wins.
66
+ */
67
+ const availableTabKeys = availableTabs
68
+ .map(tab => String(tab?.key || '').trim())
69
+ .filter(Boolean);
70
+ const availableTabSet = new Set(availableTabKeys);
71
+ const normalizedStoredTab = String(storedTab || '').trim();
72
+ const normalizedActiveTab = String(activeTab || '').trim();
73
+ const normalizedFallbackTab =
74
+ String(fallbackTab || '').trim() || availableTabKeys[0] || '';
75
+
76
+ if (normalizedStoredTab && availableTabSet.has(normalizedStoredTab)) {
77
+ return normalizedStoredTab;
78
+ }
79
+
80
+ if (normalizedActiveTab && availableTabSet.has(normalizedActiveTab)) {
81
+ return normalizedActiveTab;
82
+ }
83
+
84
+ return normalizedFallbackTab;
85
+ };
@@ -0,0 +1,281 @@
1
+ /*
2
+ * @agents This section owns CRM operational settings like sales routing and after-sales profiles.
3
+ * Keep persistence centralized in the shared settings hook instead of local state writes.
4
+ */
5
+ import React, {useCallback, useEffect, useState} from 'react';
6
+ import {Text, TextInput, TouchableOpacity, View} from 'react-native';
7
+ import {Picker} from '@react-native-picker/picker';
8
+ import FeatherIcon from 'react-native-vector-icons/Feather';
9
+ import Icon from 'react-native-vector-icons/MaterialIcons';
10
+
11
+ import css from '@controleonline/ui-orders/src/react/css/orders';
12
+ import Formatter from '@controleonline/ui-common/src/utils/formatter';
13
+ import {
14
+ useGeneralSettingsPalette,
15
+ useGeneralSettingsStyles,
16
+ } from '../GeneralSettings.styles';
17
+ import GeneralSettingsSection from '../GeneralSettingsSection';
18
+ import {
19
+ DEFAULT_AFTER_SALES_PROFILES,
20
+ GENERAL_SETTINGS_PICKER_MODE,
21
+ normalizeProfiles,
22
+ useGeneralSettingsConfig,
23
+ } from '../GeneralSettings.shared';
24
+
25
+ const CrmSection = () => {
26
+ const {styles, globalStyles} = css();
27
+ const localStyles = useGeneralSettingsStyles();
28
+ const themePalette = useGeneralSettingsPalette();
29
+ const {currentCompany, effectiveCompanyConfigs, isSaving, saveConfig} =
30
+ useGeneralSettingsConfig();
31
+
32
+ const [strategy, setStrategy] = useState('random');
33
+ const [maxTasks, setMaxTasks] = useState('10');
34
+ const [revenuePeriod, setRevenuePeriod] = useState('90');
35
+ const [profiles, setProfiles] = useState(DEFAULT_AFTER_SALES_PROFILES);
36
+ const [editingRevenueIndex, setEditingRevenueIndex] = useState(null);
37
+ const [editingRevenueValue, setEditingRevenueValue] = useState('');
38
+
39
+ useEffect(() => {
40
+ setStrategy(
41
+ String(
42
+ effectiveCompanyConfigs['salesman-distribution-strategy'] || 'random',
43
+ ),
44
+ );
45
+ setMaxTasks(String(effectiveCompanyConfigs['salesman-max-tasks'] || '10'));
46
+ setRevenuePeriod(
47
+ String(effectiveCompanyConfigs['after-sales-revenue-period'] || '90'),
48
+ );
49
+ setProfiles(normalizeProfiles(effectiveCompanyConfigs['after-sales-profiles']));
50
+ }, [effectiveCompanyConfigs]);
51
+
52
+ const saveProfiles = useCallback(
53
+ nextProfiles => {
54
+ const value = Array.isArray(nextProfiles) ? nextProfiles : profiles;
55
+ return saveConfig('after-sales-profiles', value);
56
+ },
57
+ [profiles, saveConfig],
58
+ );
59
+
60
+ const addProfile = useCallback(() => {
61
+ const nextProfiles = [...profiles, {maxRevenue: 0, days: 30}];
62
+
63
+ setProfiles(nextProfiles);
64
+ saveProfiles(nextProfiles);
65
+ }, [profiles, saveProfiles]);
66
+
67
+ const updateProfile = useCallback((index, key, value) => {
68
+ setProfiles(current => {
69
+ const copy = [...current];
70
+ copy[index] = {
71
+ ...copy[index],
72
+ [key]: value,
73
+ };
74
+ return copy;
75
+ });
76
+ }, []);
77
+
78
+ const removeProfile = useCallback(index => {
79
+ const nextProfiles = profiles.filter(
80
+ (_, profileIndex) => profileIndex !== index,
81
+ );
82
+
83
+ setProfiles(nextProfiles);
84
+ saveProfiles(nextProfiles);
85
+ }, [profiles, saveProfiles]);
86
+
87
+ const formatRevenueDisplay = value => Formatter.formatMoney(value || 0);
88
+
89
+ const formatRevenueEditValue = value => {
90
+ if (value === null || value === undefined) {
91
+ return '';
92
+ }
93
+
94
+ return String(value).replace('.', ',');
95
+ };
96
+
97
+ const handleRevenueFocus = (index, value) => {
98
+ setEditingRevenueIndex(index);
99
+ setEditingRevenueValue(formatRevenueEditValue(value));
100
+ };
101
+
102
+ const handleRevenueChange = value => {
103
+ setEditingRevenueValue(value);
104
+ };
105
+
106
+ const handleRevenueBlur = index => {
107
+ const nextProfiles = profiles.map((profile, profileIndex) =>
108
+ profileIndex === index
109
+ ? {
110
+ ...profile,
111
+ maxRevenue: Formatter.formatFloat(editingRevenueValue),
112
+ }
113
+ : profile,
114
+ );
115
+
116
+ setProfiles(nextProfiles);
117
+ setEditingRevenueIndex(null);
118
+ setEditingRevenueValue('');
119
+ saveProfiles(nextProfiles);
120
+ };
121
+
122
+ const formatDaysDisplay = value => {
123
+ const days = parseInt(value, 10) || 0;
124
+ return `${days} dias`;
125
+ };
126
+
127
+ return (
128
+ <GeneralSettingsSection
129
+ description="Configuracoes comerciais e regras de distribuicao de atendimento."
130
+ icon="groups"
131
+ iconBackgroundColor={themePalette.cardIconBackground}
132
+ iconColor={themePalette.cardIconColor}
133
+ title="CRM">
134
+ <View style={localStyles.fieldBlock}>
135
+ <Text style={localStyles.fieldLabel}>
136
+ {global.t?.t('configs', 'label', 'salesmanDistributionStrategy')}
137
+ </Text>
138
+
139
+ <Picker
140
+ selectedValue={strategy}
141
+ mode={GENERAL_SETTINGS_PICKER_MODE}
142
+ onValueChange={value => {
143
+ setStrategy(value);
144
+ saveConfig('salesman-distribution-strategy', value);
145
+ }}
146
+ style={styles.Settings.picker}>
147
+ <Picker.Item
148
+ label={global.t?.t('configs', 'option', 'random')}
149
+ value="random"
150
+ />
151
+ <Picker.Item
152
+ label={global.t?.t('configs', 'option', 'roundRobin')}
153
+ value="round_robin"
154
+ />
155
+ <Picker.Item
156
+ label={global.t?.t('configs', 'option', 'leastClients')}
157
+ value="least_clients"
158
+ />
159
+ <Picker.Item
160
+ label={global.t?.t('configs', 'option', 'lastReceived')}
161
+ value="last_received"
162
+ />
163
+ </Picker>
164
+ </View>
165
+
166
+ <View style={localStyles.fieldBlock}>
167
+ <Text style={localStyles.fieldLabel}>
168
+ {global.t?.t('configs', 'label', 'maxTasksPerSalesman')}
169
+ </Text>
170
+
171
+ <TextInput
172
+ style={localStyles.input}
173
+ value={maxTasks}
174
+ keyboardType="numeric"
175
+ onChangeText={setMaxTasks}
176
+ onBlur={() => saveConfig('salesman-max-tasks', maxTasks)}
177
+ />
178
+ </View>
179
+
180
+ <View style={localStyles.fieldBlock}>
181
+ <Text style={localStyles.fieldLabel}>
182
+ {global.t?.t('configs', 'label', 'revenuePeriod')}
183
+ </Text>
184
+
185
+ <TextInput
186
+ style={localStyles.input}
187
+ value={revenuePeriod}
188
+ keyboardType="numeric"
189
+ onChangeText={setRevenuePeriod}
190
+ onBlur={() => saveConfig('after-sales-revenue-period', revenuePeriod)}
191
+ />
192
+ </View>
193
+
194
+ <View style={localStyles.fieldBlock}>
195
+ <Text style={localStyles.fieldLabel}>
196
+ {global.t?.t('configs', 'label', 'afterSalesProfiles')}
197
+ </Text>
198
+
199
+ {profiles.map((profile, index) => (
200
+ <View key={index} style={localStyles.profileRow}>
201
+ <TextInput
202
+ style={[localStyles.input, localStyles.profileInput]}
203
+ keyboardType="decimal-pad"
204
+ value={
205
+ editingRevenueIndex === index
206
+ ? editingRevenueValue
207
+ : formatRevenueDisplay(profile.maxRevenue)
208
+ }
209
+ placeholder={global.t?.t(
210
+ 'configs',
211
+ 'placeholder',
212
+ 'revenueAbove',
213
+ )}
214
+ onFocus={() => handleRevenueFocus(index, profile.maxRevenue)}
215
+ onChangeText={handleRevenueChange}
216
+ onBlur={() => handleRevenueBlur(index)}
217
+ />
218
+
219
+ <TextInput
220
+ style={[
221
+ localStyles.input,
222
+ localStyles.profileInput,
223
+ localStyles.profileInputSpacing,
224
+ ]}
225
+ keyboardType="numeric"
226
+ value={formatDaysDisplay(profile.days)}
227
+ placeholder="Dias"
228
+ onChangeText={value =>
229
+ updateProfile(
230
+ index,
231
+ 'days',
232
+ parseInt(Formatter.onlyNumbers(value), 10) || 0,
233
+ )
234
+ }
235
+ onBlur={() => saveProfiles()}
236
+ />
237
+
238
+ <TouchableOpacity
239
+ onPress={() => removeProfile(index)}
240
+ style={[
241
+ localStyles.removeProfileButton,
242
+ {
243
+ backgroundColor: themePalette.buttonBackground,
244
+ borderColor: themePalette.buttonBackground,
245
+ },
246
+ ]}>
247
+ <FeatherIcon
248
+ name="trash-2"
249
+ size={16}
250
+ color={themePalette.buttonIcon}
251
+ />
252
+ </TouchableOpacity>
253
+ </View>
254
+ ))}
255
+
256
+ <TouchableOpacity
257
+ style={[
258
+ globalStyles.button,
259
+ localStyles.primaryButton,
260
+ {
261
+ alignItems: 'center',
262
+ backgroundColor: themePalette.buttonBackground,
263
+ flexDirection: 'row',
264
+ gap: 6,
265
+ },
266
+ (!currentCompany?.id || isSaving) && localStyles.primaryButtonDisabled,
267
+ ]}
268
+ disabled={!currentCompany?.id || isSaving}
269
+ onPress={addProfile}>
270
+ <Icon name="add" size={18} color={themePalette.buttonIcon} />
271
+ <Text style={localStyles.primaryButtonText}>
272
+ {global.t?.t('configs', 'button', 'addProfile')}
273
+ </Text>
274
+ </TouchableOpacity>
275
+
276
+ </View>
277
+ </GeneralSettingsSection>
278
+ );
279
+ };
280
+
281
+ export default CrmSection;
@@ -0,0 +1,128 @@
1
+ /*
2
+ * @agents This section controls the runtime footer text shown in shared device contexts.
3
+ * Keep writes tied to the shared config key and the current company store.
4
+ */
5
+ import React, {useCallback, useEffect, useState} from 'react';
6
+ import {Alert, Text, TextInput} from 'react-native';
7
+
8
+ import {
9
+ DEVICE_RUNTIME_FOOTER_TEXT_CONFIG_KEY,
10
+ normalizeRuntimeFooterText,
11
+ } from '@controleonline/ui-common/src/react/utils/runtimeFooter';
12
+ import {
13
+ useGeneralSettingsPalette,
14
+ useGeneralSettingsStyles,
15
+ } from '../GeneralSettings.styles';
16
+ import GeneralSettingsSection from '../GeneralSettingsSection';
17
+ import {toConfigRequestValue, useGeneralSettingsConfig} from '../GeneralSettings.shared';
18
+
19
+ const DeviceRuntimeFooterSection = () => {
20
+ const localStyles = useGeneralSettingsStyles();
21
+ const themePalette = useGeneralSettingsPalette();
22
+ const {
23
+ configActions,
24
+ mainCompany,
25
+ mainCompanyLabel,
26
+ hasMainCompanyAccess,
27
+ isMainCompanySelected,
28
+ peopleActions,
29
+ } = useGeneralSettingsConfig();
30
+ const [deviceRuntimeFooterText, setDeviceRuntimeFooterText] = useState('');
31
+ const canEditFooterText = !!mainCompany?.id && hasMainCompanyAccess;
32
+
33
+ useEffect(() => {
34
+ setDeviceRuntimeFooterText(
35
+ normalizeRuntimeFooterText(
36
+ mainCompany?.configs?.[DEVICE_RUNTIME_FOOTER_TEXT_CONFIG_KEY],
37
+ ),
38
+ );
39
+ }, [mainCompany?.configs]);
40
+
41
+ const saveDeviceRuntimeFooter = useCallback(() => {
42
+ if (!mainCompany?.id) {
43
+ Alert.alert(
44
+ 'Empresa principal indisponivel',
45
+ 'Nao foi possivel identificar a empresa principal para salvar o rodape.',
46
+ );
47
+ return Promise.resolve(false);
48
+ }
49
+
50
+ const normalizedText = normalizeRuntimeFooterText(deviceRuntimeFooterText);
51
+
52
+ return new Promise(resolve => {
53
+ configActions.addToQueue(() =>
54
+ configActions
55
+ .addConfigs({
56
+ configKey: DEVICE_RUNTIME_FOOTER_TEXT_CONFIG_KEY,
57
+ configValue: toConfigRequestValue(normalizedText),
58
+ people: '/people/' + mainCompany.id,
59
+ module: 4,
60
+ visibility: 'public',
61
+ })
62
+ .then(async data => {
63
+ setDeviceRuntimeFooterText(normalizedText);
64
+
65
+ try {
66
+ await peopleActions.mainCompany();
67
+ } catch {}
68
+
69
+ resolve(true);
70
+ return data;
71
+ })
72
+ .catch(err => {
73
+ Alert.alert('Erro', err?.message || JSON.stringify(err));
74
+ resolve(false);
75
+ return null;
76
+ }),
77
+ );
78
+ configActions.initQueue();
79
+ });
80
+ }, [
81
+ configActions,
82
+ mainCompany?.id,
83
+ deviceRuntimeFooterText,
84
+ peopleActions,
85
+ ]);
86
+
87
+ return (
88
+ <GeneralSettingsSection
89
+ description="Exibe o nome do device e a versao do software em uma linha fina no rodape. Quando existir texto livre na empresa principal, o app passa por cada linha desse texto antes de mostrar novamente a linha de versao."
90
+ icon="dvr"
91
+ iconBackgroundColor={themePalette.cardIconBackground}
92
+ iconColor={themePalette.cardIconColor}
93
+ title="Rodape dos devices">
94
+ <Text style={localStyles.helperText}>
95
+ {`Esse texto livre e salvo na empresa principal (${mainCompanyLabel}) e compartilhado com todos os devices.`}
96
+ </Text>
97
+
98
+ {!isMainCompanySelected && (
99
+ <Text style={localStyles.helperText}>
100
+ A edicao continua salvando na empresa principal, mesmo fora dela.
101
+ </Text>
102
+ )}
103
+
104
+ <Text style={localStyles.fieldLabel}>Texto livre</Text>
105
+ <TextInput
106
+ style={[
107
+ localStyles.input,
108
+ localStyles.multilineInput,
109
+ !canEditFooterText &&
110
+ localStyles.inputDisabled,
111
+ ]}
112
+ value={deviceRuntimeFooterText}
113
+ onChangeText={setDeviceRuntimeFooterText}
114
+ onBlur={saveDeviceRuntimeFooter}
115
+ multiline
116
+ numberOfLines={4}
117
+ editable={canEditFooterText}
118
+ placeholder={`Ex.:\nwww.seusite.com.br\n(11) 99999-9999`}
119
+ />
120
+ <Text style={localStyles.helperText}>
121
+ No rodape pequeno, o app alterna entre cada linha desse texto e a
122
+ linha de nome do device / versao.
123
+ </Text>
124
+ </GeneralSettingsSection>
125
+ );
126
+ };
127
+
128
+ export default DeviceRuntimeFooterSection;
@@ -0,0 +1,155 @@
1
+ /*
2
+ * @agents This section controls the copy and device mapping for display preparation output.
3
+ * Keep persistence routed through shared config and store-backed device options.
4
+ */
5
+ import React, {useEffect, useMemo} from 'react';
6
+ import {ActivityIndicator, Text, View} from 'react-native';
7
+ import Icon from 'react-native-vector-icons/MaterialIcons';
8
+
9
+ import {
10
+ filterDeviceConfigsByCompany,
11
+ } from '@controleonline/ui-common/src/react/utils/paymentDevices';
12
+ import {useStore} from '@store';
13
+
14
+ import {
15
+ useGeneralSettingsPalette,
16
+ useGeneralSettingsStyles,
17
+ } from '../GeneralSettings.styles';
18
+ import GeneralSettingsSection from '../GeneralSettingsSection';
19
+ import {
20
+ DISPLAY_DEVICE_LINK_CONFIG_KEY,
21
+ DISPLAY_DEVICE_PRINTER_CONFIG_KEY,
22
+ DISPLAY_DEVICE_TYPE,
23
+ parseDeviceConfigs,
24
+ useGeneralSettingsConfig,
25
+ } from '../GeneralSettings.shared';
26
+
27
+ const DisplayPreparationSection = () => {
28
+ const localStyles = useGeneralSettingsStyles();
29
+ const themePalette = useGeneralSettingsPalette();
30
+ const {currentCompany} = useGeneralSettingsConfig();
31
+
32
+ const deviceConfigStore = useStore('device_config');
33
+ const {
34
+ items: companyDeviceConfigs = [],
35
+ isLoading: isLoadingDeviceConfigs,
36
+ } = deviceConfigStore.getters;
37
+ const deviceConfigActions = deviceConfigStore.actions;
38
+
39
+ useEffect(() => {
40
+ if (!currentCompany?.id) {
41
+ return;
42
+ }
43
+
44
+ deviceConfigActions
45
+ .getItems({people: '/people/' + currentCompany.id})
46
+ .catch(() => {});
47
+ }, [currentCompany?.id, deviceConfigActions]);
48
+
49
+ const scopedCompanyDeviceConfigs = useMemo(
50
+ () =>
51
+ filterDeviceConfigsByCompany(companyDeviceConfigs, currentCompany?.id),
52
+ [companyDeviceConfigs, currentCompany?.id],
53
+ );
54
+
55
+ const displayPreparationDevices = useMemo(
56
+ () =>
57
+ scopedCompanyDeviceConfigs.filter(deviceConfig => {
58
+ const deviceType = String(
59
+ deviceConfig?.type || deviceConfig?.device?.type || '',
60
+ )
61
+ .trim()
62
+ .toUpperCase();
63
+ if (deviceType !== DISPLAY_DEVICE_TYPE) {
64
+ return false;
65
+ }
66
+
67
+ const configs = parseDeviceConfigs(deviceConfig?.configs);
68
+ const linkedDisplayId = String(
69
+ configs?.[DISPLAY_DEVICE_LINK_CONFIG_KEY] || '',
70
+ )
71
+ .replace(/\D+/g, '')
72
+ .trim();
73
+ const printerId = String(
74
+ configs?.[DISPLAY_DEVICE_PRINTER_CONFIG_KEY] || '',
75
+ ).trim();
76
+
77
+ return linkedDisplayId !== '' && printerId !== '';
78
+ }),
79
+ [scopedCompanyDeviceConfigs],
80
+ );
81
+
82
+ const configuredDisplayPreparationCount = displayPreparationDevices.length;
83
+
84
+ return (
85
+ <GeneralSettingsSection
86
+ description="A copia de preparo e disparada automaticamente pelo app DISPLAY quando um item entra em preparo. Cada DISPLAY precisa estar vinculado a um display e a uma impressora no detalhe do device para que a copia seja enviada para a fila correta."
87
+ icon="receipt-long"
88
+ iconBackgroundColor={themePalette.cardIconBackground}
89
+ iconColor={themePalette.cardIconColor}
90
+ title="Impressao de preparo por fila">
91
+ <Text style={localStyles.helperText}>
92
+ {configuredDisplayPreparationCount > 0
93
+ ? `${configuredDisplayPreparationCount} device(s) DISPLAY prontos para imprimir filas automaticamente.`
94
+ : 'Nenhum DISPLAY com display vinculado e impressora configurada ainda.'}
95
+ </Text>
96
+
97
+ {isLoadingDeviceConfigs ? (
98
+ <ActivityIndicator
99
+ size="small"
100
+ style={localStyles.sectionLoader}
101
+ color={themePalette.loadingSpinner}
102
+ />
103
+ ) : configuredDisplayPreparationCount > 0 ? (
104
+ <View style={localStyles.printerList}>
105
+ {displayPreparationDevices.map(deviceConfig => {
106
+ const configs = parseDeviceConfigs(deviceConfig?.configs);
107
+ const printerId = String(
108
+ configs?.[DISPLAY_DEVICE_PRINTER_CONFIG_KEY] || '',
109
+ ).trim();
110
+ const displayId = String(
111
+ configs?.[DISPLAY_DEVICE_LINK_CONFIG_KEY] || '',
112
+ )
113
+ .replace(/\D+/g, '')
114
+ .trim();
115
+ const alias =
116
+ deviceConfig?.device?.alias ||
117
+ deviceConfig?.device?.device ||
118
+ `Device #${deviceConfig?.id || '--'}`;
119
+
120
+ return (
121
+ <View
122
+ key={`display-print-${deviceConfig?.id || alias}`}
123
+ style={[localStyles.printerItem, localStyles.printerItemActive]}>
124
+ <Icon
125
+ name="check-circle"
126
+ size={20}
127
+ color={themePalette.iconActive}
128
+ />
129
+ <View style={localStyles.printerCopy}>
130
+ <Text style={localStyles.printerName}>{alias}</Text>
131
+ <Text style={localStyles.printerDevice}>
132
+ {`Display #${displayId || '--'} • Impressora ${printerId || '--'}`}
133
+ </Text>
134
+ </View>
135
+ </View>
136
+ );
137
+ })}
138
+ </View>
139
+ ) : (
140
+ <View style={localStyles.emptyBox}>
141
+ <Text style={localStyles.emptyTitle}>
142
+ Nenhum DISPLAY preparado para a fila
143
+ </Text>
144
+ <Text style={localStyles.emptyText}>
145
+ Abra o detalhe do device DISPLAY, selecione o display vinculado e a
146
+ impressora da fila. Sem isso, a impressao automatica por preparo nao
147
+ e disparada.
148
+ </Text>
149
+ </View>
150
+ )}
151
+ </GeneralSettingsSection>
152
+ );
153
+ };
154
+
155
+ export default DisplayPreparationSection;