@controleonline/ui-crm 1.0.46 → 1.0.48
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/.release/rc-manifest.json +5 -5
- package/package.json +1 -1
- package/src/react/pages/mcp/McpPage.js +1 -1
- package/src/react/pages/settings/GeneralSettings.js +296 -296
- package/src/react/pages/settings/GeneralSettings.shared.js +377 -377
- package/src/react/pages/settings/sections/AiProvidersSection.js +2 -2
- package/src/react/pages/settings/sections/DeviceRuntimeFooterSection.js +10 -10
- package/src/react/pages/settings/sections/IntegrationsSection.js +13 -13
- package/src/react/pages/settings/sections/LogSection.js +10 -10
- package/src/react/pages/settings/sections/LoginSection.js +11 -11
- package/src/react/pages/settings/sections/MaintenanceSection.js +12 -12
- package/src/react/pages/settings/sections/MapsSection.js +10 -10
- package/src/react/pages/settings/sections/ShopSection.js +2 -2
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.48",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.0.
|
|
5
|
-
"baseMaster": "
|
|
4
|
+
"branch": "rc/1.0.48-rc.1",
|
|
5
|
+
"baseMaster": "4c34c7788dae0f3c39e72be637aace2b2f2d32a3",
|
|
6
6
|
"tasks": [
|
|
7
|
-
|
|
7
|
+
1300
|
|
8
8
|
],
|
|
9
9
|
"frozen": true,
|
|
10
10
|
"repositories": {
|
|
11
|
-
"ControleOnline/ui-crm": "
|
|
11
|
+
"ControleOnline/ui-crm": "28f8cf68d6db5c436cf167403585d2cd6a65197f"
|
|
12
12
|
}
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -30,7 +30,7 @@ export default function McpPage() {
|
|
|
30
30
|
const peopleStore = useStore('people');
|
|
31
31
|
const company =
|
|
32
32
|
peopleStore?.getters?.currentCompany ||
|
|
33
|
-
peopleStore?.getters?.
|
|
33
|
+
peopleStore?.getters?.mainCompany ||
|
|
34
34
|
null;
|
|
35
35
|
const companyId = company?.id || company?.['@id']?.split('/').pop() || null;
|
|
36
36
|
|
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
2
|
-
import {ScrollView, Text, TouchableOpacity, View} from 'react-native';
|
|
3
|
-
import {SafeAreaView} from 'react-native-safe-area-context';
|
|
4
|
-
import {useFocusEffect} from '@react-navigation/native';
|
|
5
|
-
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
6
|
-
|
|
7
|
-
import css from '@controleonline/ui-orders/src/react/css/orders';
|
|
8
|
-
import StateStore from '@controleonline/ui-common/src/react/components/StateStore';
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
useGeneralSettingsPalette,
|
|
12
|
-
useGeneralSettingsStyles,
|
|
13
|
-
} from './GeneralSettings.styles';
|
|
14
|
-
import {
|
|
15
|
-
useGeneralSettingsConfig,
|
|
16
|
-
} from './GeneralSettings.shared';
|
|
17
|
-
import {
|
|
18
|
-
readGeneralSettingsActiveTab,
|
|
19
|
-
resolveGeneralSettingsActiveTab,
|
|
20
|
-
writeGeneralSettingsActiveTab,
|
|
21
|
-
} from './generalSettingsActiveTab';
|
|
22
|
-
import DeviceRuntimeFooterSection from './sections/DeviceRuntimeFooterSection';
|
|
23
|
-
import OrderPrintSection from './sections/OrderPrintSection';
|
|
24
|
-
import DisplayPreparationSection from './sections/DisplayPreparationSection';
|
|
25
|
-
import MenuCatalogSection from './sections/MenuCatalogSection';
|
|
26
|
-
import OrderPaymentSection from './sections/OrderPaymentSection';
|
|
27
|
-
import OperationsSection from './sections/OperationsSection';
|
|
1
|
+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
2
|
+
import {ScrollView, Text, TouchableOpacity, View} from 'react-native';
|
|
3
|
+
import {SafeAreaView} from 'react-native-safe-area-context';
|
|
4
|
+
import {useFocusEffect} from '@react-navigation/native';
|
|
5
|
+
import Icon from 'react-native-vector-icons/MaterialIcons';
|
|
6
|
+
|
|
7
|
+
import css from '@controleonline/ui-orders/src/react/css/orders';
|
|
8
|
+
import StateStore from '@controleonline/ui-common/src/react/components/StateStore';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
useGeneralSettingsPalette,
|
|
12
|
+
useGeneralSettingsStyles,
|
|
13
|
+
} from './GeneralSettings.styles';
|
|
14
|
+
import {
|
|
15
|
+
useGeneralSettingsConfig,
|
|
16
|
+
} from './GeneralSettings.shared';
|
|
17
|
+
import {
|
|
18
|
+
readGeneralSettingsActiveTab,
|
|
19
|
+
resolveGeneralSettingsActiveTab,
|
|
20
|
+
writeGeneralSettingsActiveTab,
|
|
21
|
+
} from './generalSettingsActiveTab';
|
|
22
|
+
import DeviceRuntimeFooterSection from './sections/DeviceRuntimeFooterSection';
|
|
23
|
+
import OrderPrintSection from './sections/OrderPrintSection';
|
|
24
|
+
import DisplayPreparationSection from './sections/DisplayPreparationSection';
|
|
25
|
+
import MenuCatalogSection from './sections/MenuCatalogSection';
|
|
26
|
+
import OrderPaymentSection from './sections/OrderPaymentSection';
|
|
27
|
+
import OperationsSection from './sections/OperationsSection';
|
|
28
28
|
import CrmSection from './sections/CrmSection';
|
|
29
29
|
import LoyaltySection from './sections/LoyaltySection';
|
|
30
30
|
import MapsSection from './sections/MapsSection';
|
|
31
31
|
import ShopSettingsSection from './sections/shop/ShopSettingsSection';
|
|
32
|
-
import AiProvidersSection from './sections/AiProvidersSection';
|
|
33
|
-
import IntegrationsSection from './sections/IntegrationsSection';
|
|
34
|
-
import LogSection from './sections/LogSection';
|
|
35
|
-
import MaintenanceSection from './sections/MaintenanceSection';
|
|
36
|
-
|
|
37
|
-
const MAIN_COMPANY_ONLY_TABS = new Set(['shop']);
|
|
38
|
-
const TECHNICAL_TABS = new Set(['integrations', 'logs', 'maintenance']);
|
|
39
|
-
|
|
40
|
-
const SETTINGS_TABS = [
|
|
41
|
-
{
|
|
42
|
-
key: 'devices',
|
|
43
|
-
label: 'Devices',
|
|
44
|
-
icon: 'dvr',
|
|
45
|
-
stores: ['configs', 'people'],
|
|
46
|
-
Component: DeviceRuntimeFooterSection,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
key: 'integrations',
|
|
50
|
-
label: 'Integrações',
|
|
51
|
-
icon: 'link',
|
|
52
|
-
stores: ['configs', 'people'],
|
|
53
|
-
Component: IntegrationsSection,
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
key: 'ai-providers',
|
|
57
|
-
label: 'IA / MCP',
|
|
58
|
-
icon: 'smart-toy',
|
|
59
|
-
stores: ['configs', 'people'],
|
|
60
|
-
Component: AiProvidersSection,
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
key: 'logs',
|
|
64
|
-
label: 'Logs',
|
|
65
|
-
icon: 'bug-report',
|
|
66
|
-
stores: ['configs', 'people'],
|
|
67
|
-
Component: LogSection,
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
key: 'maintenance',
|
|
71
|
-
label: 'Rotinas',
|
|
72
|
-
icon: 'schedule',
|
|
73
|
-
stores: ['configs', 'people'],
|
|
74
|
-
Component: MaintenanceSection,
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
key: 'print',
|
|
78
|
-
label: 'Conferência',
|
|
79
|
-
icon: 'print',
|
|
80
|
-
stores: ['configs', 'printer', 'device_config'],
|
|
81
|
-
Component: OrderPrintSection,
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
key: 'preparation',
|
|
85
|
-
label: 'Preparo',
|
|
86
|
-
icon: 'receipt-long',
|
|
87
|
-
stores: ['device_config'],
|
|
88
|
-
Component: DisplayPreparationSection,
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
key: 'menu',
|
|
92
|
-
label: 'Cardapio PDF',
|
|
93
|
-
icon: 'restaurant-menu',
|
|
94
|
-
stores: ['configs', 'categories', 'product_group', 'models'],
|
|
95
|
-
Component: MenuCatalogSection,
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
key: 'payment',
|
|
99
|
-
label: 'Pagamento',
|
|
100
|
-
icon: 'credit-card',
|
|
101
|
-
stores: ['configs', 'device_config'],
|
|
102
|
-
Component: OrderPaymentSection,
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
key: 'operations',
|
|
106
|
-
label: 'Operações',
|
|
107
|
-
icon: 'point-of-sale',
|
|
108
|
-
stores: [],
|
|
109
|
-
Component: OperationsSection,
|
|
110
|
-
},
|
|
32
|
+
import AiProvidersSection from './sections/AiProvidersSection';
|
|
33
|
+
import IntegrationsSection from './sections/IntegrationsSection';
|
|
34
|
+
import LogSection from './sections/LogSection';
|
|
35
|
+
import MaintenanceSection from './sections/MaintenanceSection';
|
|
36
|
+
|
|
37
|
+
const MAIN_COMPANY_ONLY_TABS = new Set(['shop']);
|
|
38
|
+
const TECHNICAL_TABS = new Set(['integrations', 'logs', 'maintenance']);
|
|
39
|
+
|
|
40
|
+
const SETTINGS_TABS = [
|
|
41
|
+
{
|
|
42
|
+
key: 'devices',
|
|
43
|
+
label: 'Devices',
|
|
44
|
+
icon: 'dvr',
|
|
45
|
+
stores: ['configs', 'people'],
|
|
46
|
+
Component: DeviceRuntimeFooterSection,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
key: 'integrations',
|
|
50
|
+
label: 'Integrações',
|
|
51
|
+
icon: 'link',
|
|
52
|
+
stores: ['configs', 'people'],
|
|
53
|
+
Component: IntegrationsSection,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
key: 'ai-providers',
|
|
57
|
+
label: 'IA / MCP',
|
|
58
|
+
icon: 'smart-toy',
|
|
59
|
+
stores: ['configs', 'people'],
|
|
60
|
+
Component: AiProvidersSection,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: 'logs',
|
|
64
|
+
label: 'Logs',
|
|
65
|
+
icon: 'bug-report',
|
|
66
|
+
stores: ['configs', 'people'],
|
|
67
|
+
Component: LogSection,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
key: 'maintenance',
|
|
71
|
+
label: 'Rotinas',
|
|
72
|
+
icon: 'schedule',
|
|
73
|
+
stores: ['configs', 'people'],
|
|
74
|
+
Component: MaintenanceSection,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: 'print',
|
|
78
|
+
label: 'Conferência',
|
|
79
|
+
icon: 'print',
|
|
80
|
+
stores: ['configs', 'printer', 'device_config'],
|
|
81
|
+
Component: OrderPrintSection,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
key: 'preparation',
|
|
85
|
+
label: 'Preparo',
|
|
86
|
+
icon: 'receipt-long',
|
|
87
|
+
stores: ['device_config'],
|
|
88
|
+
Component: DisplayPreparationSection,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
key: 'menu',
|
|
92
|
+
label: 'Cardapio PDF',
|
|
93
|
+
icon: 'restaurant-menu',
|
|
94
|
+
stores: ['configs', 'categories', 'product_group', 'models'],
|
|
95
|
+
Component: MenuCatalogSection,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
key: 'payment',
|
|
99
|
+
label: 'Pagamento',
|
|
100
|
+
icon: 'credit-card',
|
|
101
|
+
stores: ['configs', 'device_config'],
|
|
102
|
+
Component: OrderPaymentSection,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
key: 'operations',
|
|
106
|
+
label: 'Operações',
|
|
107
|
+
icon: 'point-of-sale',
|
|
108
|
+
stores: [],
|
|
109
|
+
Component: OperationsSection,
|
|
110
|
+
},
|
|
111
111
|
{
|
|
112
112
|
key: 'crm',
|
|
113
113
|
label: 'CRM',
|
|
@@ -125,10 +125,10 @@ const SETTINGS_TABS = [
|
|
|
125
125
|
{
|
|
126
126
|
key: 'maps',
|
|
127
127
|
label: 'Mapas',
|
|
128
|
-
icon: 'map',
|
|
129
|
-
stores: ['configs'],
|
|
130
|
-
Component: MapsSection,
|
|
131
|
-
},
|
|
128
|
+
icon: 'map',
|
|
129
|
+
stores: ['configs'],
|
|
130
|
+
Component: MapsSection,
|
|
131
|
+
},
|
|
132
132
|
{
|
|
133
133
|
key: 'shop',
|
|
134
134
|
label: 'Shop',
|
|
@@ -137,189 +137,189 @@ const SETTINGS_TABS = [
|
|
|
137
137
|
Component: ShopSettingsSection,
|
|
138
138
|
},
|
|
139
139
|
];
|
|
140
|
-
|
|
141
|
-
const GeneralSettings = () => {
|
|
142
|
-
const {styles} = css();
|
|
143
|
-
const localStyles = useGeneralSettingsStyles();
|
|
144
|
-
const {
|
|
145
|
-
companies,
|
|
146
|
-
currentCompany,
|
|
147
|
-
|
|
148
|
-
hasDefaultCompanyAccess,
|
|
149
|
-
isMainCompanySelected,
|
|
150
|
-
peopleActions,
|
|
151
|
-
} =
|
|
152
|
-
useGeneralSettingsConfig();
|
|
153
|
-
const themePalette = useGeneralSettingsPalette();
|
|
154
|
-
const [activeTab, setActiveTab] = useState(
|
|
155
|
-
() => readGeneralSettingsActiveTab() || SETTINGS_TABS[0].key,
|
|
156
|
-
);
|
|
157
|
-
/*
|
|
158
|
-
* @agents Wait for the company context before correcting the tab selection.
|
|
159
|
-
* Without this guard the screen can briefly snap back to the first tab during bootstrap.
|
|
160
|
-
*/
|
|
161
|
-
const [isCompanyContextReady, setIsCompanyContextReady] = useState(false);
|
|
162
|
-
|
|
163
|
-
const availableTabs = useMemo(
|
|
164
|
-
() =>
|
|
165
|
-
SETTINGS_TABS.filter(
|
|
166
|
-
tab =>
|
|
167
|
-
(!MAIN_COMPANY_ONLY_TABS.has(tab.key) || isMainCompanySelected) &&
|
|
168
|
-
(!TECHNICAL_TABS.has(tab.key) || hasDefaultCompanyAccess),
|
|
169
|
-
),
|
|
170
|
-
[hasDefaultCompanyAccess, isMainCompanySelected],
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
useFocusEffect(
|
|
174
|
-
useCallback(() => {
|
|
175
|
-
let cancelled = false;
|
|
176
|
-
const requests = [];
|
|
177
|
-
|
|
178
|
-
setIsCompanyContextReady(false);
|
|
179
|
-
|
|
180
|
-
if (!Array.isArray(companies) || companies.length === 0) {
|
|
181
|
-
const companiesRequest = peopleActions.myCompanies?.();
|
|
182
|
-
if (companiesRequest?.then) {
|
|
183
|
-
requests.push(companiesRequest.catch(() => {}));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (!
|
|
188
|
-
const
|
|
189
|
-
if (
|
|
190
|
-
requests.push(
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
Promise.allSettled(requests).finally(() => {
|
|
195
|
-
if (!cancelled) {
|
|
196
|
-
setIsCompanyContextReady(true);
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
if (requests.length === 0) {
|
|
201
|
-
setIsCompanyContextReady(true);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return () => {
|
|
205
|
-
cancelled = true;
|
|
206
|
-
};
|
|
207
|
-
}, [companies,
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
/*
|
|
211
|
-
* @agents Validate the current tab after mount, then only correct the selection when
|
|
212
|
-
* the active tab stops being available because of company or permission changes.
|
|
213
|
-
*/
|
|
214
|
-
useEffect(() => {
|
|
215
|
-
if (!isCompanyContextReady) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const nextActiveTab = resolveGeneralSettingsActiveTab({
|
|
220
|
-
activeTab,
|
|
221
|
-
availableTabs,
|
|
222
|
-
fallbackTab: SETTINGS_TABS[0].key,
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
if (nextActiveTab !== activeTab) {
|
|
226
|
-
setActiveTab(nextActiveTab);
|
|
227
|
-
}
|
|
228
|
-
}, [activeTab, availableTabs, isCompanyContextReady]);
|
|
229
|
-
|
|
230
|
-
/*
|
|
231
|
-
* @agents Persist the current tab for the next visit, but never use storage to
|
|
232
|
-
* override a valid in-session click.
|
|
233
|
-
*/
|
|
234
|
-
useEffect(() => {
|
|
235
|
-
writeGeneralSettingsActiveTab(activeTab);
|
|
236
|
-
}, [activeTab]);
|
|
237
|
-
|
|
238
|
-
const activeTabConfig = useMemo(
|
|
239
|
-
() =>
|
|
240
|
-
availableTabs.find(tab => tab.key === activeTab) ||
|
|
241
|
-
SETTINGS_TABS.find(tab => tab.key === activeTab) ||
|
|
242
|
-
availableTabs[0] ||
|
|
243
|
-
SETTINGS_TABS[0],
|
|
244
|
-
[activeTab, availableTabs],
|
|
245
|
-
);
|
|
246
|
-
const ActiveTabComponent = activeTabConfig.Component;
|
|
247
|
-
const activeStores = useMemo(
|
|
248
|
-
() => Array.from(new Set(activeTabConfig?.stores || ['configs'])),
|
|
249
|
-
[activeTabConfig],
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
return (
|
|
253
|
-
<SafeAreaView style={styles.Settings.container}>
|
|
254
|
-
<StateStore stores={activeStores} />
|
|
255
|
-
<ScrollView contentContainerStyle={styles.Settings.scrollContent}>
|
|
256
|
-
<View style={styles.Settings.mainContainer}>
|
|
257
|
-
<Text style={localStyles.pageTitle}>Configurador geral</Text>
|
|
258
|
-
<Text style={localStyles.pageSubtitle}>
|
|
259
|
-
{currentCompany?.name || currentCompany?.alias || 'Empresa ativa'}
|
|
260
|
-
</Text>
|
|
261
|
-
|
|
262
|
-
<ScrollView
|
|
263
|
-
horizontal
|
|
264
|
-
showsHorizontalScrollIndicator={false}
|
|
265
|
-
style={localStyles.tabBar}
|
|
266
|
-
contentContainerStyle={localStyles.tabBarContent}>
|
|
267
|
-
{availableTabs.map(tab => {
|
|
268
|
-
const active = tab.key === activeTab;
|
|
269
|
-
const tabColors = active
|
|
270
|
-
? {
|
|
271
|
-
backgroundColor: themePalette.buttonBackground,
|
|
272
|
-
borderColor: themePalette.buttonBorder,
|
|
273
|
-
iconColor: themePalette.buttonIcon,
|
|
274
|
-
textColor: themePalette.buttonText,
|
|
275
|
-
}
|
|
276
|
-
: {
|
|
277
|
-
backgroundColor: themePalette.buttonBackgroundSecondary,
|
|
278
|
-
borderColor: themePalette.buttonBorderSecondary,
|
|
279
|
-
iconColor: themePalette.buttonIconSecondary,
|
|
280
|
-
textColor: themePalette.buttonTextSecondary,
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
return (
|
|
284
|
-
<TouchableOpacity
|
|
285
|
-
key={tab.key}
|
|
286
|
-
style={[
|
|
287
|
-
localStyles.tabItem,
|
|
288
|
-
{
|
|
289
|
-
backgroundColor: tabColors.backgroundColor,
|
|
290
|
-
borderColor: tabColors.borderColor,
|
|
291
|
-
},
|
|
292
|
-
]}
|
|
293
|
-
activeOpacity={0.85}
|
|
294
|
-
onPress={() => setActiveTab(tab.key)}>
|
|
295
|
-
<Icon
|
|
296
|
-
name={tab.icon}
|
|
297
|
-
size={18}
|
|
298
|
-
color={tabColors.iconColor}
|
|
299
|
-
/>
|
|
300
|
-
<Text
|
|
301
|
-
style={[
|
|
302
|
-
localStyles.tabLabel,
|
|
303
|
-
active && localStyles.tabLabelActive,
|
|
304
|
-
{color: tabColors.textColor},
|
|
305
|
-
]}>
|
|
306
|
-
{tab.label}
|
|
307
|
-
</Text>
|
|
308
|
-
</TouchableOpacity>
|
|
309
|
-
);
|
|
310
|
-
})}
|
|
311
|
-
</ScrollView>
|
|
312
|
-
|
|
313
|
-
<Text style={localStyles.tabHelper}>
|
|
314
|
-
Cada aba carrega apenas os dados da própria sessão para reduzir a
|
|
315
|
-
latência inicial e deixar a tela mais organizada.
|
|
316
|
-
</Text>
|
|
317
|
-
|
|
318
|
-
<ActiveTabComponent />
|
|
319
|
-
</View>
|
|
320
|
-
</ScrollView>
|
|
321
|
-
</SafeAreaView>
|
|
322
|
-
);
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
export default GeneralSettings;
|
|
140
|
+
|
|
141
|
+
const GeneralSettings = () => {
|
|
142
|
+
const {styles} = css();
|
|
143
|
+
const localStyles = useGeneralSettingsStyles();
|
|
144
|
+
const {
|
|
145
|
+
companies,
|
|
146
|
+
currentCompany,
|
|
147
|
+
mainCompany,
|
|
148
|
+
hasDefaultCompanyAccess,
|
|
149
|
+
isMainCompanySelected,
|
|
150
|
+
peopleActions,
|
|
151
|
+
} =
|
|
152
|
+
useGeneralSettingsConfig();
|
|
153
|
+
const themePalette = useGeneralSettingsPalette();
|
|
154
|
+
const [activeTab, setActiveTab] = useState(
|
|
155
|
+
() => readGeneralSettingsActiveTab() || SETTINGS_TABS[0].key,
|
|
156
|
+
);
|
|
157
|
+
/*
|
|
158
|
+
* @agents Wait for the company context before correcting the tab selection.
|
|
159
|
+
* Without this guard the screen can briefly snap back to the first tab during bootstrap.
|
|
160
|
+
*/
|
|
161
|
+
const [isCompanyContextReady, setIsCompanyContextReady] = useState(false);
|
|
162
|
+
|
|
163
|
+
const availableTabs = useMemo(
|
|
164
|
+
() =>
|
|
165
|
+
SETTINGS_TABS.filter(
|
|
166
|
+
tab =>
|
|
167
|
+
(!MAIN_COMPANY_ONLY_TABS.has(tab.key) || isMainCompanySelected) &&
|
|
168
|
+
(!TECHNICAL_TABS.has(tab.key) || hasDefaultCompanyAccess),
|
|
169
|
+
),
|
|
170
|
+
[hasDefaultCompanyAccess, isMainCompanySelected],
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
useFocusEffect(
|
|
174
|
+
useCallback(() => {
|
|
175
|
+
let cancelled = false;
|
|
176
|
+
const requests = [];
|
|
177
|
+
|
|
178
|
+
setIsCompanyContextReady(false);
|
|
179
|
+
|
|
180
|
+
if (!Array.isArray(companies) || companies.length === 0) {
|
|
181
|
+
const companiesRequest = peopleActions.myCompanies?.();
|
|
182
|
+
if (companiesRequest?.then) {
|
|
183
|
+
requests.push(companiesRequest.catch(() => {}));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!mainCompany?.id) {
|
|
188
|
+
const mainCompanyRequest = peopleActions.mainCompany?.();
|
|
189
|
+
if (mainCompanyRequest?.then) {
|
|
190
|
+
requests.push(mainCompanyRequest.catch(() => {}));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
Promise.allSettled(requests).finally(() => {
|
|
195
|
+
if (!cancelled) {
|
|
196
|
+
setIsCompanyContextReady(true);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
if (requests.length === 0) {
|
|
201
|
+
setIsCompanyContextReady(true);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return () => {
|
|
205
|
+
cancelled = true;
|
|
206
|
+
};
|
|
207
|
+
}, [companies, mainCompany?.id, peopleActions]),
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
/*
|
|
211
|
+
* @agents Validate the current tab after mount, then only correct the selection when
|
|
212
|
+
* the active tab stops being available because of company or permission changes.
|
|
213
|
+
*/
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
if (!isCompanyContextReady) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const nextActiveTab = resolveGeneralSettingsActiveTab({
|
|
220
|
+
activeTab,
|
|
221
|
+
availableTabs,
|
|
222
|
+
fallbackTab: SETTINGS_TABS[0].key,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
if (nextActiveTab !== activeTab) {
|
|
226
|
+
setActiveTab(nextActiveTab);
|
|
227
|
+
}
|
|
228
|
+
}, [activeTab, availableTabs, isCompanyContextReady]);
|
|
229
|
+
|
|
230
|
+
/*
|
|
231
|
+
* @agents Persist the current tab for the next visit, but never use storage to
|
|
232
|
+
* override a valid in-session click.
|
|
233
|
+
*/
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
writeGeneralSettingsActiveTab(activeTab);
|
|
236
|
+
}, [activeTab]);
|
|
237
|
+
|
|
238
|
+
const activeTabConfig = useMemo(
|
|
239
|
+
() =>
|
|
240
|
+
availableTabs.find(tab => tab.key === activeTab) ||
|
|
241
|
+
SETTINGS_TABS.find(tab => tab.key === activeTab) ||
|
|
242
|
+
availableTabs[0] ||
|
|
243
|
+
SETTINGS_TABS[0],
|
|
244
|
+
[activeTab, availableTabs],
|
|
245
|
+
);
|
|
246
|
+
const ActiveTabComponent = activeTabConfig.Component;
|
|
247
|
+
const activeStores = useMemo(
|
|
248
|
+
() => Array.from(new Set(activeTabConfig?.stores || ['configs'])),
|
|
249
|
+
[activeTabConfig],
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
return (
|
|
253
|
+
<SafeAreaView style={styles.Settings.container}>
|
|
254
|
+
<StateStore stores={activeStores} />
|
|
255
|
+
<ScrollView contentContainerStyle={styles.Settings.scrollContent}>
|
|
256
|
+
<View style={styles.Settings.mainContainer}>
|
|
257
|
+
<Text style={localStyles.pageTitle}>Configurador geral</Text>
|
|
258
|
+
<Text style={localStyles.pageSubtitle}>
|
|
259
|
+
{currentCompany?.name || currentCompany?.alias || 'Empresa ativa'}
|
|
260
|
+
</Text>
|
|
261
|
+
|
|
262
|
+
<ScrollView
|
|
263
|
+
horizontal
|
|
264
|
+
showsHorizontalScrollIndicator={false}
|
|
265
|
+
style={localStyles.tabBar}
|
|
266
|
+
contentContainerStyle={localStyles.tabBarContent}>
|
|
267
|
+
{availableTabs.map(tab => {
|
|
268
|
+
const active = tab.key === activeTab;
|
|
269
|
+
const tabColors = active
|
|
270
|
+
? {
|
|
271
|
+
backgroundColor: themePalette.buttonBackground,
|
|
272
|
+
borderColor: themePalette.buttonBorder,
|
|
273
|
+
iconColor: themePalette.buttonIcon,
|
|
274
|
+
textColor: themePalette.buttonText,
|
|
275
|
+
}
|
|
276
|
+
: {
|
|
277
|
+
backgroundColor: themePalette.buttonBackgroundSecondary,
|
|
278
|
+
borderColor: themePalette.buttonBorderSecondary,
|
|
279
|
+
iconColor: themePalette.buttonIconSecondary,
|
|
280
|
+
textColor: themePalette.buttonTextSecondary,
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
return (
|
|
284
|
+
<TouchableOpacity
|
|
285
|
+
key={tab.key}
|
|
286
|
+
style={[
|
|
287
|
+
localStyles.tabItem,
|
|
288
|
+
{
|
|
289
|
+
backgroundColor: tabColors.backgroundColor,
|
|
290
|
+
borderColor: tabColors.borderColor,
|
|
291
|
+
},
|
|
292
|
+
]}
|
|
293
|
+
activeOpacity={0.85}
|
|
294
|
+
onPress={() => setActiveTab(tab.key)}>
|
|
295
|
+
<Icon
|
|
296
|
+
name={tab.icon}
|
|
297
|
+
size={18}
|
|
298
|
+
color={tabColors.iconColor}
|
|
299
|
+
/>
|
|
300
|
+
<Text
|
|
301
|
+
style={[
|
|
302
|
+
localStyles.tabLabel,
|
|
303
|
+
active && localStyles.tabLabelActive,
|
|
304
|
+
{color: tabColors.textColor},
|
|
305
|
+
]}>
|
|
306
|
+
{tab.label}
|
|
307
|
+
</Text>
|
|
308
|
+
</TouchableOpacity>
|
|
309
|
+
);
|
|
310
|
+
})}
|
|
311
|
+
</ScrollView>
|
|
312
|
+
|
|
313
|
+
<Text style={localStyles.tabHelper}>
|
|
314
|
+
Cada aba carrega apenas os dados da própria sessão para reduzir a
|
|
315
|
+
latência inicial e deixar a tela mais organizada.
|
|
316
|
+
</Text>
|
|
317
|
+
|
|
318
|
+
<ActiveTabComponent />
|
|
319
|
+
</View>
|
|
320
|
+
</ScrollView>
|
|
321
|
+
</SafeAreaView>
|
|
322
|
+
);
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
export default GeneralSettings;
|