@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.
- package/.github/actions/workers/manager/action.yml +147 -0
- package/.github/actions/workers/qa/action.yml +44 -0
- package/.github/actions/workers/security/action.yml +44 -0
- package/.github/actions/workers/technical-documenter/action.yml +51 -0
- package/.github/workflows/manager-worker.yml +167 -0
- package/.github/workflows/publish-npm.yml +40 -0
- package/.github/workflows/pull-request-checks.yml +29 -0
- package/.scrutinizer.yml +24 -0
- package/AGENTS.md +56 -0
- package/FUNDING.yml +1 -0
- package/docs/technical/Cliente-Vendedor-Vinculo-e-Permissoes.md +121 -0
- package/docs/technical/Income-Statements-Demonstrativo.md +38 -0
- package/docs/technical/Oportunidades-Ordenacao-por-Data-de-Retorno.md +134 -0
- package/docs/technical/Propostas-Filtro-de-Status.md +147 -0
- package/docs/technical/Royalties-a-pagar-Franqueado.md +51 -0
- package/docs/technical/Visao-Vendedor-Comissoes.md +58 -0
- package/docs/wiki.md +1 -0
- package/package.json +43 -0
- package/scripts/validate-wiki-pointer.cjs +13 -0
- package/src/react/components/AnimatedModal.js +149 -0
- package/src/react/components/AnimatedModal.styles.js +21 -0
- package/src/react/components/CreateContractModal.js +151 -0
- package/src/react/components/CreateContractModal.styles.js +43 -0
- package/src/react/hooks/useToastMessage.js +59 -0
- package/src/react/index.js +4 -0
- package/src/react/pages/ModelTemplatesPage.js +1461 -0
- package/src/react/pages/ModelTemplatesPage.styles.js +441 -0
- package/src/react/pages/comissions/IncomeStatementDetailsModal.js +102 -0
- package/src/react/pages/comissions/IncomeStatementsFilters.js +120 -0
- package/src/react/pages/comissions/SellerCommissionsPage.js +368 -0
- package/src/react/pages/comissions/SellerCommissionsPage.styles.js +219 -0
- package/src/react/pages/comissions/incomeStatementsHelpers.js +233 -0
- package/src/react/pages/comissions/index.js +309 -0
- package/src/react/pages/comissions/index.styles.js +381 -0
- package/src/react/pages/comissions/sellerCommissionsHelpers.js +222 -0
- package/src/react/pages/crm/components/CrmHeader.js +117 -0
- package/src/react/pages/crm/components/MarketingEventsSection.js +142 -0
- package/src/react/pages/crm/components/MarketingEventsSection.styles.js +105 -0
- package/src/react/pages/crm/components/OpportunityCard.js +138 -0
- package/src/react/pages/crm/components/OpportunityFormModal.js +279 -0
- package/src/react/pages/crm/components/OpportunityList.js +113 -0
- package/src/react/pages/crm/components/OpportunitySkeletons.js +53 -0
- package/src/react/pages/crm/components/ProviderSelectModal.js +166 -0
- package/src/react/pages/crm/components/SelectModal.js +178 -0
- package/src/react/pages/crm/conversation.js +342 -0
- package/src/react/pages/crm/conversation.styles.js +206 -0
- package/src/react/pages/crm/hooks/useCrmData.js +494 -0
- package/src/react/pages/crm/hooks/useOpportunityForms.js +306 -0
- package/src/react/pages/crm/index.js +262 -0
- package/src/react/pages/crm/index.styles.js +13 -0
- package/src/react/pages/crm/marketingEventsHelpers.js +41 -0
- package/src/react/pages/crm/styles/card.styles.js +178 -0
- package/src/react/pages/crm/styles/layout.styles.js +184 -0
- package/src/react/pages/crm/styles/modal.styles.js +347 -0
- package/src/react/pages/home/index.js +559 -0
- package/src/react/pages/home/index.styles.js +268 -0
- package/src/react/pages/proposals/CreateProposalsModal.js +466 -0
- package/src/react/pages/proposals/CreateProposalsModal.styles.js +344 -0
- package/src/react/pages/proposals/CreateProposalsPickers.js +187 -0
- package/src/react/pages/proposals/CreateProposalsProductSection.js +117 -0
- package/src/react/pages/proposals/ProposalCard.js +112 -0
- package/src/react/pages/proposals/ProposalDetails.js +263 -0
- package/src/react/pages/proposals/ProposalDetails.styles.js +195 -0
- package/src/react/pages/proposals/index.js +488 -0
- package/src/react/pages/proposals/index.styles.js +248 -0
- package/src/react/pages/proposals/proposalListHelpers.js +216 -0
- package/src/react/pages/proposals/proposalNavigation.js +26 -0
- package/src/react/pages/royalties/ReceivablePage.js +233 -0
- package/src/react/pages/royalties/RoyaltiesPayablePage.js +260 -0
- package/src/react/pages/royalties/index.js +2 -0
- package/src/react/pages/royalties/royaltiesReceivableHelpers.js +68 -0
- package/src/react/pages/settings/GeneralSettings.js +317 -0
- package/src/react/pages/settings/GeneralSettings.shared.js +490 -0
- package/src/react/pages/settings/GeneralSettings.styles.js +746 -0
- package/src/react/pages/settings/GeneralSettingsSection.js +57 -0
- package/src/react/pages/settings/generalSettingsActiveTab.js +85 -0
- package/src/react/pages/settings/sections/CrmSection.js +281 -0
- package/src/react/pages/settings/sections/DeviceRuntimeFooterSection.js +128 -0
- package/src/react/pages/settings/sections/DisplayPreparationSection.js +155 -0
- package/src/react/pages/settings/sections/IntegrationsSection.js +392 -0
- package/src/react/pages/settings/sections/LogSection.js +322 -0
- package/src/react/pages/settings/sections/LoginSection.js +137 -0
- package/src/react/pages/settings/sections/LoyaltyProductPicker.js +230 -0
- package/src/react/pages/settings/sections/LoyaltySection.js +451 -0
- package/src/react/pages/settings/sections/MaintenanceSection.js +205 -0
- package/src/react/pages/settings/sections/MapsSection.js +629 -0
- package/src/react/pages/settings/sections/MenuCatalogSection.js +405 -0
- package/src/react/pages/settings/sections/OperationsSection.js +303 -0
- package/src/react/pages/settings/sections/OrderPaymentSection.js +379 -0
- package/src/react/pages/settings/sections/OrderPrintSection.js +308 -0
- package/src/react/pages/settings/sections/ShopSection.js +490 -0
- package/src/react/pages/settings/sections/shop/FranchiseMapPreview.js +124 -0
- package/src/react/pages/settings/sections/shop/ShopDomainCreateForm.js +57 -0
- package/src/react/pages/settings/sections/shop/ShopDomainPanel.js +184 -0
- package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.js +237 -0
- package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.styles.js +256 -0
- package/src/react/pages/settings/sections/shop/ShopDomainTabs.js +61 -0
- package/src/react/pages/settings/sections/shop/ShopFranchiseLocatorSection.js +526 -0
- package/src/react/pages/settings/sections/shop/ShopLoyaltySection.js +426 -0
- package/src/react/pages/settings/sections/shop/ShopSettingsSection.js +10 -0
- package/src/react/pages/settings/sections/shop/mapsFranchiseMapHelpers.js +163 -0
- package/src/react/pages/settings/sections/shop/shopDomainShowcasesUtils.js +68 -0
- package/src/react/pages/settings/sections/shop/shopFranchiseVisibility.js +158 -0
- package/src/react/pages/settings/sections/shop/shopSettingsShared.js +427 -0
- package/src/react/router/routes.js +135 -0
- package/src/react/utils/opportunityDate.js +82 -0
- package/src/react/utils/opportunityEditorReferences.js +76 -0
- package/src/react/utils/opportunityEmptyState.js +20 -0
- package/src/react/utils/opportunityPeople.js +111 -0
- package/src/react/utils/opportunityPhone.js +82 -0
- package/src/react/utils/opportunityStage.js +30 -0
- package/src/react/utils/opportunityStatusFilter.js +54 -0
- package/src/react/utils/proposalCreateHelpers.js +61 -0
- package/src/react/utils/proposalProductSelection.js +71 -0
- package/src/react/utils/royaltiesPayableParams.js +37 -0
- package/src/react/utils/translateWithFallback.js +42 -0
- package/src/store/crm/index.js +2 -0
- package/src/store/model/index.js +104 -0
- package/src/tests/browser/crm/create-proposal-product-category-filter.spec.js +149 -0
- package/src/tests/browser/crm/crm-index-status-filter.spec.js +263 -0
- package/src/tests/browser/crm/crm-opportunity-category-editor.spec.js +269 -0
- package/src/tests/browser/crm/royalties-payable.spec.js +122 -0
- package/src/tests/browser/crm/royalties-receivable.spec.js +121 -0
- package/src/tests/browser/crm/seller-commissions.spec.js +214 -0
- package/src/tests/browser/manager/general-settings-maps.spec.js +400 -0
- package/src/tests/react/pages/comissions/incomeStatementsHelpers.test.js +181 -0
- package/src/tests/react/pages/comissions/sellerCommissionsHelpers.test.js +132 -0
- package/src/tests/react/pages/crm/marketingEventsHelpers.test.cjs +53 -0
- package/src/tests/react/pages/crm/opportunitySearchParams.test.cjs +44 -0
- package/src/tests/react/pages/proposals/navigation.test.js +71 -0
- package/src/tests/react/pages/proposals/proposalListHelpers.test.js +42 -0
- package/src/tests/react/pages/royalties/royaltiesReceivableHelpers.test.js +60 -0
- package/src/tests/react/pages/settings/generalSettings.shared.test.js +102 -0
- package/src/tests/react/pages/settings/sections/shop/shopDomainShowcasesUtils.test.js +60 -0
- package/src/tests/react/pages/settings/sections/shop/shopFranchiseVisibility.test.js +80 -0
- package/src/tests/react/utils/opportunityEditorReferences.test.js +70 -0
- package/src/tests/react/utils/opportunityEmptyState.test.js +39 -0
- package/src/tests/react/utils/opportunityStatusFilter.test.cjs +81 -0
- package/src/tests/react/utils/proposalCreateHelpers.test.js +25 -0
- package/src/tests/react/utils/proposalProductSelection.test.js +76 -0
- package/src/tests/react/utils/royaltiesPayableParams.test.js +44 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Keep shared settings parsing and persistence helpers in one place.
|
|
3
|
+
* The individual sections should reuse this contract instead of duplicating config logic.
|
|
4
|
+
*/
|
|
5
|
+
import {useCallback, useMemo} from 'react';
|
|
6
|
+
import {Alert} from 'react-native';
|
|
7
|
+
|
|
8
|
+
import {useStore} from '@store';
|
|
9
|
+
export {
|
|
10
|
+
GENERAL_SETTINGS_ACTIVE_TAB_STORAGE_KEY,
|
|
11
|
+
readGeneralSettingsActiveTab,
|
|
12
|
+
resolveGeneralSettingsActiveTab,
|
|
13
|
+
writeGeneralSettingsActiveTab,
|
|
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';
|
|
20
|
+
export const DISPLAY_DEVICE_PRINTER_CONFIG_KEY = 'printer';
|
|
21
|
+
export const MENU_CATALOG_HIDDEN_CATEGORY_IDS_CONFIG_KEY =
|
|
22
|
+
'menu-catalog-hidden-category-ids';
|
|
23
|
+
export const MENU_CATALOG_HIDDEN_GROUP_IDS_CONFIG_KEY =
|
|
24
|
+
'menu-catalog-hidden-group-ids';
|
|
25
|
+
export const GENERAL_SETTINGS_PICKER_MODE = 'dropdown';
|
|
26
|
+
export const DEFAULT_AFTER_SALES_PROFILES = [
|
|
27
|
+
{maxRevenue: 10000, days: 30},
|
|
28
|
+
{maxRevenue: 1000, days: 60},
|
|
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
|
+
|
|
89
|
+
export const normalizeTextConfigValue = value => {
|
|
90
|
+
if (value === null || value === undefined) {
|
|
91
|
+
return '';
|
|
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
|
+
|
|
114
|
+
export const parseDeviceConfigs = value => {
|
|
115
|
+
const parsed = parseJsonValue(value, {});
|
|
116
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
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
|
+
|
|
149
|
+
if (typeof value === 'string') {
|
|
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);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Arrays: single stringify so discovery + parsers resolve to a real array once.
|
|
165
|
+
// Legacy double-stringify made franchise selections appear empty after refresh.
|
|
166
|
+
if (Array.isArray(value)) {
|
|
167
|
+
return JSON.stringify(value);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return JSON.stringify(value);
|
|
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, 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 hasMainCompanyAccess = 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
|
+
[configActions, currentCompany?.id, syncConfigCache],
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
const saveMainCompanyConfigs = useCallback(
|
|
370
|
+
entries => {
|
|
371
|
+
if (!mainCompanyId) {
|
|
372
|
+
Alert.alert(
|
|
373
|
+
'Empresa principal nao selecionada',
|
|
374
|
+
'Selecione uma empresa principal para salvar as configuracoes.',
|
|
375
|
+
);
|
|
376
|
+
return Promise.resolve(false);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const normalizedEntries = Object.entries(entries || {}).reduce(
|
|
380
|
+
(accumulator, [key, value]) => {
|
|
381
|
+
accumulator[key] = value;
|
|
382
|
+
return accumulator;
|
|
383
|
+
},
|
|
384
|
+
{},
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
const requestEntries = Object.entries(normalizedEntries).reduce(
|
|
388
|
+
(accumulator, [key, value]) => {
|
|
389
|
+
accumulator[key] = toConfigRequestValue(value);
|
|
390
|
+
return accumulator;
|
|
391
|
+
},
|
|
392
|
+
{},
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
const cacheEntries = Object.entries(normalizedEntries).reduce(
|
|
396
|
+
(accumulator, [key, value]) => {
|
|
397
|
+
accumulator[key] = toConfigCacheValue(value);
|
|
398
|
+
return accumulator;
|
|
399
|
+
},
|
|
400
|
+
{},
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
return new Promise(resolve => {
|
|
404
|
+
configActions.addToQueue(async () => {
|
|
405
|
+
const requestConfigItems = Object.entries(requestEntries).map(
|
|
406
|
+
([configKey, configValue]) => ({
|
|
407
|
+
configKey,
|
|
408
|
+
configValue,
|
|
409
|
+
}),
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
try {
|
|
413
|
+
const data = await configActions.addManyConfigs({
|
|
414
|
+
configs: requestConfigItems,
|
|
415
|
+
people: '/people/' + mainCompanyId,
|
|
416
|
+
module: 4,
|
|
417
|
+
visibility: 'public',
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
syncConfigCache(cacheEntries);
|
|
421
|
+
resolve(true);
|
|
422
|
+
return data;
|
|
423
|
+
} catch (err) {
|
|
424
|
+
Alert.alert('Erro', err?.message || JSON.stringify(err));
|
|
425
|
+
resolve(false);
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
configActions.initQueue();
|
|
430
|
+
});
|
|
431
|
+
},
|
|
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],
|
|
473
|
+
);
|
|
474
|
+
|
|
475
|
+
return {
|
|
476
|
+
companies,
|
|
477
|
+
configActions,
|
|
478
|
+
currentCompany,
|
|
479
|
+
mainCompany,
|
|
480
|
+
mainCompanyLabel,
|
|
481
|
+
effectiveCompanyConfigs,
|
|
482
|
+
hasMainCompanyAccess,
|
|
483
|
+
isMainCompanySelected,
|
|
484
|
+
isSaving,
|
|
485
|
+
peopleActions,
|
|
486
|
+
saveConfig,
|
|
487
|
+
saveConfigs,
|
|
488
|
+
saveMainCompanyConfigs,
|
|
489
|
+
};
|
|
490
|
+
};
|