@controleonline/ui-crm 1.0.45 → 1.0.47
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 +13 -0
- 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
|
@@ -12,11 +12,11 @@ export {
|
|
|
12
12
|
resolveGeneralSettingsActiveTab,
|
|
13
13
|
writeGeneralSettingsActiveTab,
|
|
14
14
|
} from './generalSettingsActiveTab';
|
|
15
|
-
|
|
16
|
-
export const ORDER_PRINT_DEVICES_CONFIG_KEY = 'order-print-devices';
|
|
17
|
-
export const ORDER_PRINT_FOOTER_TEXT_CONFIG_KEY = 'order-print-footer-text';
|
|
18
|
-
export const DISPLAY_DEVICE_TYPE = 'DISPLAY';
|
|
19
|
-
export const DISPLAY_DEVICE_LINK_CONFIG_KEY = 'display-id';
|
|
15
|
+
|
|
16
|
+
export const ORDER_PRINT_DEVICES_CONFIG_KEY = 'order-print-devices';
|
|
17
|
+
export const ORDER_PRINT_FOOTER_TEXT_CONFIG_KEY = 'order-print-footer-text';
|
|
18
|
+
export const DISPLAY_DEVICE_TYPE = 'DISPLAY';
|
|
19
|
+
export const DISPLAY_DEVICE_LINK_CONFIG_KEY = 'display-id';
|
|
20
20
|
export const DISPLAY_DEVICE_PRINTER_CONFIG_KEY = 'printer';
|
|
21
21
|
export const MENU_CATALOG_HIDDEN_CATEGORY_IDS_CONFIG_KEY =
|
|
22
22
|
'menu-catalog-hidden-category-ids';
|
|
@@ -27,137 +27,137 @@ export const DEFAULT_AFTER_SALES_PROFILES = [
|
|
|
27
27
|
{maxRevenue: 10000, days: 30},
|
|
28
28
|
{maxRevenue: 1000, days: 60},
|
|
29
29
|
{maxRevenue: 0, days: 120},
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
export const parseJsonValue = (value, fallback) => {
|
|
33
|
-
if (value === null || value === undefined || value === '') {
|
|
34
|
-
return fallback;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (typeof value === 'string') {
|
|
38
|
-
try {
|
|
39
|
-
return JSON.parse(value);
|
|
40
|
-
} catch {
|
|
41
|
-
return fallback;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return value;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const normalizeProfiles = value => {
|
|
49
|
-
const parsed = parseJsonValue(value, DEFAULT_AFTER_SALES_PROFILES);
|
|
50
|
-
return Array.isArray(parsed) && parsed.length > 0
|
|
51
|
-
? parsed
|
|
52
|
-
: DEFAULT_AFTER_SALES_PROFILES;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const normalizeIdList = value => {
|
|
56
|
-
const parsed = parseJsonValue(value, []);
|
|
57
|
-
const source = Array.isArray(parsed)
|
|
58
|
-
? parsed
|
|
59
|
-
: String(value || '').split(/\r?\n|,/);
|
|
60
|
-
|
|
61
|
-
return Array.from(
|
|
62
|
-
new Set(
|
|
63
|
-
source
|
|
64
|
-
.map(item => String(item || '').replace(/\D+/g, '').trim())
|
|
65
|
-
.filter(Boolean),
|
|
66
|
-
),
|
|
67
|
-
);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const normalizeNotificationTargets = value => {
|
|
71
|
-
const parsed = parseJsonValue(value, []);
|
|
72
|
-
if (Array.isArray(parsed)) {
|
|
73
|
-
return parsed
|
|
74
|
-
.map(item => String(item || '').trim())
|
|
75
|
-
.filter(Boolean);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return String(value || '')
|
|
79
|
-
.split(/\r?\n|,/)
|
|
80
|
-
.map(item => item.trim())
|
|
81
|
-
.filter(Boolean);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export const normalizeEntityId = value =>
|
|
85
|
-
String(value || '')
|
|
86
|
-
.replace(/\D+/g, '')
|
|
87
|
-
.trim();
|
|
88
|
-
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
export const parseJsonValue = (value, fallback) => {
|
|
33
|
+
if (value === null || value === undefined || value === '') {
|
|
34
|
+
return fallback;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (typeof value === 'string') {
|
|
38
|
+
try {
|
|
39
|
+
return JSON.parse(value);
|
|
40
|
+
} catch {
|
|
41
|
+
return fallback;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return value;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const normalizeProfiles = value => {
|
|
49
|
+
const parsed = parseJsonValue(value, DEFAULT_AFTER_SALES_PROFILES);
|
|
50
|
+
return Array.isArray(parsed) && parsed.length > 0
|
|
51
|
+
? parsed
|
|
52
|
+
: DEFAULT_AFTER_SALES_PROFILES;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const normalizeIdList = value => {
|
|
56
|
+
const parsed = parseJsonValue(value, []);
|
|
57
|
+
const source = Array.isArray(parsed)
|
|
58
|
+
? parsed
|
|
59
|
+
: String(value || '').split(/\r?\n|,/);
|
|
60
|
+
|
|
61
|
+
return Array.from(
|
|
62
|
+
new Set(
|
|
63
|
+
source
|
|
64
|
+
.map(item => String(item || '').replace(/\D+/g, '').trim())
|
|
65
|
+
.filter(Boolean),
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const normalizeNotificationTargets = value => {
|
|
71
|
+
const parsed = parseJsonValue(value, []);
|
|
72
|
+
if (Array.isArray(parsed)) {
|
|
73
|
+
return parsed
|
|
74
|
+
.map(item => String(item || '').trim())
|
|
75
|
+
.filter(Boolean);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return String(value || '')
|
|
79
|
+
.split(/\r?\n|,/)
|
|
80
|
+
.map(item => item.trim())
|
|
81
|
+
.filter(Boolean);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const normalizeEntityId = value =>
|
|
85
|
+
String(value || '')
|
|
86
|
+
.replace(/\D+/g, '')
|
|
87
|
+
.trim();
|
|
88
|
+
|
|
89
89
|
export const normalizeTextConfigValue = value => {
|
|
90
90
|
if (value === null || value === undefined) {
|
|
91
91
|
return '';
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
if (typeof value === 'string') {
|
|
95
|
-
if (value.trim() === '') {
|
|
96
|
-
return '';
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
const parsed = JSON.parse(value);
|
|
101
|
-
if (typeof parsed === 'string') {
|
|
102
|
-
return parsed;
|
|
103
|
-
}
|
|
104
|
-
} catch {
|
|
105
|
-
return value;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return value;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return String(value);
|
|
112
|
-
};
|
|
113
|
-
|
|
93
|
+
|
|
94
|
+
if (typeof value === 'string') {
|
|
95
|
+
if (value.trim() === '') {
|
|
96
|
+
return '';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const parsed = JSON.parse(value);
|
|
101
|
+
if (typeof parsed === 'string') {
|
|
102
|
+
return parsed;
|
|
103
|
+
}
|
|
104
|
+
} catch {
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return String(value);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
114
|
export const parseDeviceConfigs = value => {
|
|
115
115
|
const parsed = parseJsonValue(value, {});
|
|
116
116
|
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
117
117
|
};
|
|
118
|
-
|
|
119
|
-
export const getMenuGroupOptionLabel = group => {
|
|
120
|
-
const groupName = String(group?.productGroup || '').trim();
|
|
121
|
-
const parentValue = group?.parentProduct;
|
|
122
|
-
|
|
123
|
-
if (parentValue && typeof parentValue === 'object') {
|
|
124
|
-
const parentName = String(parentValue?.product || '').trim();
|
|
125
|
-
if (parentName) {
|
|
126
|
-
return `${groupName} • ${parentName}`;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (typeof parentValue === 'string') {
|
|
131
|
-
const parentId = parentValue.replace(/\D+/g, '');
|
|
132
|
-
if (groupName && parentId) {
|
|
133
|
-
return `${groupName} • Produto #${parentId}`;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (groupName) {
|
|
138
|
-
return `${groupName} • #${group?.id || ''}`.trim();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return `Grupo #${group?.id || ''}`;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
export const toConfigRequestValue = value => {
|
|
145
|
-
if (value === undefined) {
|
|
146
|
-
return JSON.stringify('');
|
|
147
|
-
}
|
|
148
|
-
|
|
118
|
+
|
|
119
|
+
export const getMenuGroupOptionLabel = group => {
|
|
120
|
+
const groupName = String(group?.productGroup || '').trim();
|
|
121
|
+
const parentValue = group?.parentProduct;
|
|
122
|
+
|
|
123
|
+
if (parentValue && typeof parentValue === 'object') {
|
|
124
|
+
const parentName = String(parentValue?.product || '').trim();
|
|
125
|
+
if (parentName) {
|
|
126
|
+
return `${groupName} • ${parentName}`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (typeof parentValue === 'string') {
|
|
131
|
+
const parentId = parentValue.replace(/\D+/g, '');
|
|
132
|
+
if (groupName && parentId) {
|
|
133
|
+
return `${groupName} • Produto #${parentId}`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (groupName) {
|
|
138
|
+
return `${groupName} • #${group?.id || ''}`.trim();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return `Grupo #${group?.id || ''}`;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const toConfigRequestValue = value => {
|
|
145
|
+
if (value === undefined) {
|
|
146
|
+
return JSON.stringify('');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
149
|
if (typeof value === 'string') {
|
|
150
150
|
const trimmed = value.trim();
|
|
151
|
-
|
|
152
|
-
if (trimmed === '') {
|
|
153
|
-
return JSON.stringify('');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
try {
|
|
157
|
-
JSON.parse(trimmed);
|
|
158
|
-
return value;
|
|
159
|
-
} catch {
|
|
160
|
-
return JSON.stringify(value);
|
|
151
|
+
|
|
152
|
+
if (trimmed === '') {
|
|
153
|
+
return JSON.stringify('');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
JSON.parse(trimmed);
|
|
158
|
+
return value;
|
|
159
|
+
} catch {
|
|
160
|
+
return JSON.stringify(value);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
@@ -169,206 +169,206 @@ export const toConfigRequestValue = value => {
|
|
|
169
169
|
|
|
170
170
|
return JSON.stringify(value);
|
|
171
171
|
};
|
|
172
|
-
|
|
173
|
-
export const toConfigCacheValue = value => {
|
|
174
|
-
if (value === null || value === undefined) {
|
|
175
|
-
return '';
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (typeof value === 'string') {
|
|
179
|
-
return value;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (typeof value === 'object') {
|
|
183
|
-
return JSON.stringify(value);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return String(value);
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
const isMethodNotAllowedError = error => {
|
|
190
|
-
const status = Number(
|
|
191
|
-
error?.status || error?.response?.status || error?.data?.status || 0,
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
if (status === 405) {
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const details = String(
|
|
199
|
-
error?.detail || error?.message || JSON.stringify(error || {}),
|
|
200
|
-
).toLowerCase();
|
|
201
|
-
|
|
202
|
-
return details.includes('method not allowed') || details.includes('405');
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
export const useGeneralSettingsConfig = () => {
|
|
206
|
-
const peopleStore = useStore('people');
|
|
207
|
-
const {companies, currentCompany,
|
|
208
|
-
const peopleActions = peopleStore.actions;
|
|
209
|
-
|
|
210
|
-
const configsStore = useStore('configs');
|
|
211
|
-
const configsGetters = configsStore.getters;
|
|
212
|
-
const {items: companyConfigs, isSaving} = configsGetters;
|
|
213
|
-
const configActions = configsStore.actions;
|
|
214
|
-
|
|
215
|
-
const effectiveCompanyConfigs = useMemo(() => {
|
|
216
|
-
if (companyConfigs && typeof companyConfigs === 'object') {
|
|
217
|
-
return companyConfigs;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (currentCompany?.configs && typeof currentCompany.configs === 'object') {
|
|
221
|
-
return currentCompany.configs;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return {};
|
|
225
|
-
}, [companyConfigs, currentCompany?.configs]);
|
|
226
|
-
|
|
227
|
-
const selectedCompanyId = useMemo(
|
|
228
|
-
() => normalizeEntityId(currentCompany?.id || currentCompany?.['@id']),
|
|
229
|
-
[currentCompany?.['@id'], currentCompany?.id],
|
|
230
|
-
);
|
|
231
|
-
const
|
|
232
|
-
() => normalizeEntityId(
|
|
233
|
-
[
|
|
234
|
-
);
|
|
235
|
-
const hasDefaultCompanyAccess = useMemo(() => {
|
|
236
|
-
if (
|
|
237
|
-
return false;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return (Array.isArray(companies) ? companies : []).some(
|
|
241
|
-
company =>
|
|
242
|
-
normalizeEntityId(company?.id || company?.['@id']) ===
|
|
243
|
-
);
|
|
244
|
-
}, [companies,
|
|
245
|
-
const isMainCompanySelected =
|
|
246
|
-
selectedCompanyId !== '' &&
|
|
247
|
-
|
|
248
|
-
selectedCompanyId ===
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const syncConfigCache = useCallback(
|
|
253
|
-
entries => {
|
|
254
|
-
const baseConfigs =
|
|
255
|
-
companyConfigs && typeof companyConfigs === 'object'
|
|
256
|
-
? companyConfigs
|
|
257
|
-
: effectiveCompanyConfigs;
|
|
258
|
-
|
|
259
|
-
configActions.setItems({
|
|
260
|
-
...baseConfigs,
|
|
261
|
-
...entries,
|
|
262
|
-
});
|
|
263
|
-
},
|
|
264
|
-
[companyConfigs, configActions, effectiveCompanyConfigs],
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
const saveConfigs = useCallback(
|
|
268
|
-
(entries, options = {}) => {
|
|
269
|
-
const {suppressAlert = false} = options;
|
|
270
|
-
|
|
271
|
-
if (!currentCompany?.id) {
|
|
272
|
-
if (!suppressAlert) {
|
|
273
|
-
Alert.alert(
|
|
274
|
-
'Empresa nao selecionada',
|
|
275
|
-
'Selecione uma empresa para salvar as configuracoes.',
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return Promise.resolve(false);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const normalizedEntries = Object.entries(entries || {}).reduce(
|
|
283
|
-
(accumulator, [key, value]) => {
|
|
284
|
-
accumulator[key] = value;
|
|
285
|
-
return accumulator;
|
|
286
|
-
},
|
|
287
|
-
{},
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
const requestEntries = Object.entries(normalizedEntries).reduce(
|
|
291
|
-
(accumulator, [key, value]) => {
|
|
292
|
-
accumulator[key] = toConfigRequestValue(value);
|
|
293
|
-
return accumulator;
|
|
294
|
-
},
|
|
295
|
-
{},
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
const cacheEntries = Object.entries(normalizedEntries).reduce(
|
|
299
|
-
(accumulator, [key, value]) => {
|
|
300
|
-
accumulator[key] = toConfigCacheValue(value);
|
|
301
|
-
return accumulator;
|
|
302
|
-
},
|
|
303
|
-
{},
|
|
304
|
-
);
|
|
305
|
-
|
|
306
|
-
return new Promise(resolve => {
|
|
307
|
-
configActions.addToQueue(async () => {
|
|
308
|
-
const requestConfigItems = Object.entries(requestEntries).map(
|
|
309
|
-
([configKey, configValue]) => ({
|
|
310
|
-
configKey,
|
|
311
|
-
configValue,
|
|
312
|
-
}),
|
|
313
|
-
);
|
|
314
|
-
|
|
315
|
-
try {
|
|
316
|
-
const data = await configActions.addManyConfigs({
|
|
317
|
-
configs: requestConfigItems,
|
|
318
|
-
people: '/people/' + currentCompany.id,
|
|
319
|
-
module: 4,
|
|
320
|
-
visibility: 'public',
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
syncConfigCache(cacheEntries);
|
|
324
|
-
resolve(true);
|
|
325
|
-
return data;
|
|
326
|
-
} catch (err) {
|
|
327
|
-
if (!isMethodNotAllowedError(err)) {
|
|
328
|
-
if (!suppressAlert) {
|
|
329
|
-
Alert.alert('Erro', err?.message || JSON.stringify(err));
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
resolve(false);
|
|
333
|
-
return null;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
try {
|
|
337
|
-
for (const item of requestConfigItems) {
|
|
338
|
-
await configActions.addConfigs({
|
|
339
|
-
configKey: item.configKey,
|
|
340
|
-
configValue: item.configValue,
|
|
341
|
-
people: '/people/' + currentCompany.id,
|
|
342
|
-
module: 4,
|
|
343
|
-
visibility: 'public',
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
syncConfigCache(cacheEntries);
|
|
348
|
-
resolve(true);
|
|
349
|
-
return true;
|
|
350
|
-
} catch (fallbackErr) {
|
|
351
|
-
if (!suppressAlert) {
|
|
352
|
-
Alert.alert(
|
|
353
|
-
'Erro',
|
|
354
|
-
fallbackErr?.message || JSON.stringify(fallbackErr),
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
resolve(false);
|
|
359
|
-
return null;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
configActions.initQueue();
|
|
364
|
-
});
|
|
365
|
-
},
|
|
172
|
+
|
|
173
|
+
export const toConfigCacheValue = value => {
|
|
174
|
+
if (value === null || value === undefined) {
|
|
175
|
+
return '';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (typeof value === 'string') {
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (typeof value === 'object') {
|
|
183
|
+
return JSON.stringify(value);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return String(value);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const isMethodNotAllowedError = error => {
|
|
190
|
+
const status = Number(
|
|
191
|
+
error?.status || error?.response?.status || error?.data?.status || 0,
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (status === 405) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const details = String(
|
|
199
|
+
error?.detail || error?.message || JSON.stringify(error || {}),
|
|
200
|
+
).toLowerCase();
|
|
201
|
+
|
|
202
|
+
return details.includes('method not allowed') || details.includes('405');
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export const useGeneralSettingsConfig = () => {
|
|
206
|
+
const peopleStore = useStore('people');
|
|
207
|
+
const {companies, currentCompany, mainCompany} = peopleStore.getters;
|
|
208
|
+
const peopleActions = peopleStore.actions;
|
|
209
|
+
|
|
210
|
+
const configsStore = useStore('configs');
|
|
211
|
+
const configsGetters = configsStore.getters;
|
|
212
|
+
const {items: companyConfigs, isSaving} = configsGetters;
|
|
213
|
+
const configActions = configsStore.actions;
|
|
214
|
+
|
|
215
|
+
const effectiveCompanyConfigs = useMemo(() => {
|
|
216
|
+
if (companyConfigs && typeof companyConfigs === 'object') {
|
|
217
|
+
return companyConfigs;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (currentCompany?.configs && typeof currentCompany.configs === 'object') {
|
|
221
|
+
return currentCompany.configs;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return {};
|
|
225
|
+
}, [companyConfigs, currentCompany?.configs]);
|
|
226
|
+
|
|
227
|
+
const selectedCompanyId = useMemo(
|
|
228
|
+
() => normalizeEntityId(currentCompany?.id || currentCompany?.['@id']),
|
|
229
|
+
[currentCompany?.['@id'], currentCompany?.id],
|
|
230
|
+
);
|
|
231
|
+
const mainCompanyId = useMemo(
|
|
232
|
+
() => normalizeEntityId(mainCompany?.id || mainCompany?.['@id']),
|
|
233
|
+
[mainCompany?.['@id'], mainCompany?.id],
|
|
234
|
+
);
|
|
235
|
+
const hasDefaultCompanyAccess = useMemo(() => {
|
|
236
|
+
if (mainCompanyId === '') {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return (Array.isArray(companies) ? companies : []).some(
|
|
241
|
+
company =>
|
|
242
|
+
normalizeEntityId(company?.id || company?.['@id']) === mainCompanyId,
|
|
243
|
+
);
|
|
244
|
+
}, [companies, mainCompanyId]);
|
|
245
|
+
const isMainCompanySelected =
|
|
246
|
+
selectedCompanyId !== '' &&
|
|
247
|
+
mainCompanyId !== '' &&
|
|
248
|
+
selectedCompanyId === mainCompanyId;
|
|
249
|
+
const mainCompanyLabel =
|
|
250
|
+
mainCompany?.alias || mainCompany?.name || 'empresa principal';
|
|
251
|
+
|
|
252
|
+
const syncConfigCache = useCallback(
|
|
253
|
+
entries => {
|
|
254
|
+
const baseConfigs =
|
|
255
|
+
companyConfigs && typeof companyConfigs === 'object'
|
|
256
|
+
? companyConfigs
|
|
257
|
+
: effectiveCompanyConfigs;
|
|
258
|
+
|
|
259
|
+
configActions.setItems({
|
|
260
|
+
...baseConfigs,
|
|
261
|
+
...entries,
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
[companyConfigs, configActions, effectiveCompanyConfigs],
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
const saveConfigs = useCallback(
|
|
268
|
+
(entries, options = {}) => {
|
|
269
|
+
const {suppressAlert = false} = options;
|
|
270
|
+
|
|
271
|
+
if (!currentCompany?.id) {
|
|
272
|
+
if (!suppressAlert) {
|
|
273
|
+
Alert.alert(
|
|
274
|
+
'Empresa nao selecionada',
|
|
275
|
+
'Selecione uma empresa para salvar as configuracoes.',
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return Promise.resolve(false);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const normalizedEntries = Object.entries(entries || {}).reduce(
|
|
283
|
+
(accumulator, [key, value]) => {
|
|
284
|
+
accumulator[key] = value;
|
|
285
|
+
return accumulator;
|
|
286
|
+
},
|
|
287
|
+
{},
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const requestEntries = Object.entries(normalizedEntries).reduce(
|
|
291
|
+
(accumulator, [key, value]) => {
|
|
292
|
+
accumulator[key] = toConfigRequestValue(value);
|
|
293
|
+
return accumulator;
|
|
294
|
+
},
|
|
295
|
+
{},
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
const cacheEntries = Object.entries(normalizedEntries).reduce(
|
|
299
|
+
(accumulator, [key, value]) => {
|
|
300
|
+
accumulator[key] = toConfigCacheValue(value);
|
|
301
|
+
return accumulator;
|
|
302
|
+
},
|
|
303
|
+
{},
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
return new Promise(resolve => {
|
|
307
|
+
configActions.addToQueue(async () => {
|
|
308
|
+
const requestConfigItems = Object.entries(requestEntries).map(
|
|
309
|
+
([configKey, configValue]) => ({
|
|
310
|
+
configKey,
|
|
311
|
+
configValue,
|
|
312
|
+
}),
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
try {
|
|
316
|
+
const data = await configActions.addManyConfigs({
|
|
317
|
+
configs: requestConfigItems,
|
|
318
|
+
people: '/people/' + currentCompany.id,
|
|
319
|
+
module: 4,
|
|
320
|
+
visibility: 'public',
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
syncConfigCache(cacheEntries);
|
|
324
|
+
resolve(true);
|
|
325
|
+
return data;
|
|
326
|
+
} catch (err) {
|
|
327
|
+
if (!isMethodNotAllowedError(err)) {
|
|
328
|
+
if (!suppressAlert) {
|
|
329
|
+
Alert.alert('Erro', err?.message || JSON.stringify(err));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
resolve(false);
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
try {
|
|
337
|
+
for (const item of requestConfigItems) {
|
|
338
|
+
await configActions.addConfigs({
|
|
339
|
+
configKey: item.configKey,
|
|
340
|
+
configValue: item.configValue,
|
|
341
|
+
people: '/people/' + currentCompany.id,
|
|
342
|
+
module: 4,
|
|
343
|
+
visibility: 'public',
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
syncConfigCache(cacheEntries);
|
|
348
|
+
resolve(true);
|
|
349
|
+
return true;
|
|
350
|
+
} catch (fallbackErr) {
|
|
351
|
+
if (!suppressAlert) {
|
|
352
|
+
Alert.alert(
|
|
353
|
+
'Erro',
|
|
354
|
+
fallbackErr?.message || JSON.stringify(fallbackErr),
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
resolve(false);
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
configActions.initQueue();
|
|
364
|
+
});
|
|
365
|
+
},
|
|
366
366
|
[configActions, currentCompany?.id, syncConfigCache],
|
|
367
367
|
);
|
|
368
368
|
|
|
369
|
-
const
|
|
369
|
+
const saveMainCompanyConfigs = useCallback(
|
|
370
370
|
entries => {
|
|
371
|
-
if (!
|
|
371
|
+
if (!mainCompanyId) {
|
|
372
372
|
Alert.alert(
|
|
373
373
|
'Empresa principal nao selecionada',
|
|
374
374
|
'Selecione uma empresa principal para salvar as configuracoes.',
|
|
@@ -412,7 +412,7 @@ export const useGeneralSettingsConfig = () => {
|
|
|
412
412
|
try {
|
|
413
413
|
const data = await configActions.addManyConfigs({
|
|
414
414
|
configs: requestConfigItems,
|
|
415
|
-
people: '/people/' +
|
|
415
|
+
people: '/people/' + mainCompanyId,
|
|
416
416
|
module: 4,
|
|
417
417
|
visibility: 'public',
|
|
418
418
|
});
|
|
@@ -429,62 +429,62 @@ export const useGeneralSettingsConfig = () => {
|
|
|
429
429
|
configActions.initQueue();
|
|
430
430
|
});
|
|
431
431
|
},
|
|
432
|
-
[configActions,
|
|
432
|
+
[configActions, mainCompanyId, syncConfigCache],
|
|
433
|
+
);
|
|
434
|
+
|
|
435
|
+
const saveConfig = useCallback(
|
|
436
|
+
(key, value) => {
|
|
437
|
+
if (!currentCompany?.id) {
|
|
438
|
+
Alert.alert(
|
|
439
|
+
'Empresa nao selecionada',
|
|
440
|
+
'Selecione uma empresa para salvar as configuracoes.',
|
|
441
|
+
);
|
|
442
|
+
return Promise.resolve(false);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const requestValue = toConfigRequestValue(value);
|
|
446
|
+
const cacheValue = toConfigCacheValue(value);
|
|
447
|
+
|
|
448
|
+
return new Promise(resolve => {
|
|
449
|
+
configActions.addToQueue(() =>
|
|
450
|
+
configActions
|
|
451
|
+
.addConfigs({
|
|
452
|
+
configKey: key,
|
|
453
|
+
configValue: requestValue,
|
|
454
|
+
people: '/people/' + currentCompany.id,
|
|
455
|
+
module: 4,
|
|
456
|
+
visibility: 'public',
|
|
457
|
+
})
|
|
458
|
+
.then(data => {
|
|
459
|
+
syncConfigCache({[key]: cacheValue});
|
|
460
|
+
resolve(true);
|
|
461
|
+
return data;
|
|
462
|
+
})
|
|
463
|
+
.catch(err => {
|
|
464
|
+
Alert.alert('Erro', err?.message || JSON.stringify(err));
|
|
465
|
+
resolve(false);
|
|
466
|
+
return null;
|
|
467
|
+
}),
|
|
468
|
+
);
|
|
469
|
+
configActions.initQueue();
|
|
470
|
+
});
|
|
471
|
+
},
|
|
472
|
+
[configActions, currentCompany?.id, syncConfigCache],
|
|
433
473
|
);
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
const cacheValue = toConfigCacheValue(value);
|
|
447
|
-
|
|
448
|
-
return new Promise(resolve => {
|
|
449
|
-
configActions.addToQueue(() =>
|
|
450
|
-
configActions
|
|
451
|
-
.addConfigs({
|
|
452
|
-
configKey: key,
|
|
453
|
-
configValue: requestValue,
|
|
454
|
-
people: '/people/' + currentCompany.id,
|
|
455
|
-
module: 4,
|
|
456
|
-
visibility: 'public',
|
|
457
|
-
})
|
|
458
|
-
.then(data => {
|
|
459
|
-
syncConfigCache({[key]: cacheValue});
|
|
460
|
-
resolve(true);
|
|
461
|
-
return data;
|
|
462
|
-
})
|
|
463
|
-
.catch(err => {
|
|
464
|
-
Alert.alert('Erro', err?.message || JSON.stringify(err));
|
|
465
|
-
resolve(false);
|
|
466
|
-
return null;
|
|
467
|
-
}),
|
|
468
|
-
);
|
|
469
|
-
configActions.initQueue();
|
|
470
|
-
});
|
|
471
|
-
},
|
|
472
|
-
[configActions, currentCompany?.id, syncConfigCache],
|
|
473
|
-
);
|
|
474
|
-
|
|
475
|
-
return {
|
|
476
|
-
companies,
|
|
477
|
-
configActions,
|
|
478
|
-
currentCompany,
|
|
479
|
-
defaultCompany,
|
|
480
|
-
defaultCompanyLabel,
|
|
481
|
-
effectiveCompanyConfigs,
|
|
482
|
-
hasDefaultCompanyAccess,
|
|
483
|
-
isMainCompanySelected,
|
|
484
|
-
isSaving,
|
|
485
|
-
peopleActions,
|
|
474
|
+
|
|
475
|
+
return {
|
|
476
|
+
companies,
|
|
477
|
+
configActions,
|
|
478
|
+
currentCompany,
|
|
479
|
+
mainCompany,
|
|
480
|
+
mainCompanyLabel,
|
|
481
|
+
effectiveCompanyConfigs,
|
|
482
|
+
hasDefaultCompanyAccess,
|
|
483
|
+
isMainCompanySelected,
|
|
484
|
+
isSaving,
|
|
485
|
+
peopleActions,
|
|
486
486
|
saveConfig,
|
|
487
487
|
saveConfigs,
|
|
488
|
-
|
|
488
|
+
saveMainCompanyConfigs,
|
|
489
489
|
};
|
|
490
490
|
};
|