@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,392 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents This section owns the integration-specific settings for the CRM page.
|
|
3
|
+
* Keep remote reads and config writes routed through the shared settings contract.
|
|
4
|
+
*/
|
|
5
|
+
import React, {useCallback, useEffect, useState} from 'react';
|
|
6
|
+
import {ActivityIndicator, Text, TextInput} from 'react-native';
|
|
7
|
+
|
|
8
|
+
import useToastMessage from '@controleonline/ui-crm/src/react/hooks/useToastMessage';
|
|
9
|
+
import {api} from '@controleonline/ui-common/src/api';
|
|
10
|
+
import {
|
|
11
|
+
CIELO_CONFIG_KEY,
|
|
12
|
+
DEFAULT_CIELO_CONFIG,
|
|
13
|
+
DEFAULT_NEW_RELIC_CONFIG,
|
|
14
|
+
DEFAULT_SPOTIFY_CONFIG,
|
|
15
|
+
NEW_RELIC_CONFIG_KEY,
|
|
16
|
+
resolveCieloConfig,
|
|
17
|
+
resolveNewRelicConfig,
|
|
18
|
+
resolveSpotifyConfig,
|
|
19
|
+
SPOTIFY_CONFIG_KEY,
|
|
20
|
+
} from '@controleonline/ui-common/src/utils/integrationConfigs';
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
useGeneralSettingsPalette,
|
|
24
|
+
useGeneralSettingsStyles,
|
|
25
|
+
} from '../GeneralSettings.styles';
|
|
26
|
+
import GeneralSettingsSection from '../GeneralSettingsSection';
|
|
27
|
+
import LoginSection from './LoginSection';
|
|
28
|
+
import {
|
|
29
|
+
toConfigCacheValue,
|
|
30
|
+
toConfigRequestValue,
|
|
31
|
+
useGeneralSettingsConfig,
|
|
32
|
+
} from '../GeneralSettings.shared';
|
|
33
|
+
|
|
34
|
+
const buildConfigUpdater = (setState, fieldKey) => value => {
|
|
35
|
+
setState(currentValue => ({
|
|
36
|
+
...currentValue,
|
|
37
|
+
[fieldKey]: value,
|
|
38
|
+
}));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const IntegrationField = ({
|
|
42
|
+
editable,
|
|
43
|
+
fieldKey,
|
|
44
|
+
onBlur,
|
|
45
|
+
onChangeText,
|
|
46
|
+
placeholder,
|
|
47
|
+
sectionState,
|
|
48
|
+
styles,
|
|
49
|
+
}) => (
|
|
50
|
+
<>
|
|
51
|
+
<Text style={styles.fieldLabel}>{fieldKey}</Text>
|
|
52
|
+
<TextInput
|
|
53
|
+
style={[styles.input, !editable && styles.inputDisabled]}
|
|
54
|
+
value={sectionState[fieldKey]}
|
|
55
|
+
onChangeText={onChangeText}
|
|
56
|
+
onBlur={onBlur}
|
|
57
|
+
editable={editable}
|
|
58
|
+
autoCapitalize="none"
|
|
59
|
+
autoCorrect={false}
|
|
60
|
+
placeholder={placeholder}
|
|
61
|
+
/>
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const IntegrationsSection = () => {
|
|
66
|
+
const localStyles = useGeneralSettingsStyles();
|
|
67
|
+
const themePalette = useGeneralSettingsPalette();
|
|
68
|
+
const {showError, showSuccess} = useToastMessage();
|
|
69
|
+
const {
|
|
70
|
+
configActions,
|
|
71
|
+
mainCompany,
|
|
72
|
+
mainCompanyLabel,
|
|
73
|
+
hasMainCompanyAccess,
|
|
74
|
+
isMainCompanySelected,
|
|
75
|
+
isSaving,
|
|
76
|
+
peopleActions,
|
|
77
|
+
} = useGeneralSettingsConfig();
|
|
78
|
+
const [privateConfigs, setPrivateConfigs] = useState({});
|
|
79
|
+
const [isLoadingPrivateConfigs, setIsLoadingPrivateConfigs] = useState(false);
|
|
80
|
+
|
|
81
|
+
const [cieloConfig, setCieloConfig] = useState(DEFAULT_CIELO_CONFIG);
|
|
82
|
+
const [newRelicConfig, setNewRelicConfig] = useState(DEFAULT_NEW_RELIC_CONFIG);
|
|
83
|
+
const [spotifyConfig, setSpotifyConfig] = useState(DEFAULT_SPOTIFY_CONFIG);
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* @agents Keep private integration config loading here until the store exposes the same contract.
|
|
87
|
+
* This is the only place in the section that reads the company-scoped private payload remotely.
|
|
88
|
+
*/
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (!hasMainCompanyAccess || !mainCompany?.id) {
|
|
91
|
+
setPrivateConfigs({});
|
|
92
|
+
setIsLoadingPrivateConfigs(false);
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let cancelled = false;
|
|
97
|
+
setIsLoadingPrivateConfigs(true);
|
|
98
|
+
|
|
99
|
+
api
|
|
100
|
+
.fetch('/configs', {
|
|
101
|
+
params: {
|
|
102
|
+
people: '/people/' + mainCompany.id,
|
|
103
|
+
visibility: 'private',
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
.then(response => {
|
|
107
|
+
if (cancelled) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const items = Array.isArray(response?.member)
|
|
112
|
+
? response.member
|
|
113
|
+
: Array.isArray(response?.['hydra:member'])
|
|
114
|
+
? response['hydra:member']
|
|
115
|
+
: [];
|
|
116
|
+
|
|
117
|
+
const mapped = items.reduce((accumulator, item) => {
|
|
118
|
+
const configKey = String(item?.configKey || '').trim();
|
|
119
|
+
if (configKey) {
|
|
120
|
+
accumulator[configKey] = item?.configValue;
|
|
121
|
+
}
|
|
122
|
+
return accumulator;
|
|
123
|
+
}, {});
|
|
124
|
+
|
|
125
|
+
setPrivateConfigs(mapped);
|
|
126
|
+
})
|
|
127
|
+
.catch(error => {
|
|
128
|
+
if (!cancelled) {
|
|
129
|
+
setPrivateConfigs({});
|
|
130
|
+
showError(
|
|
131
|
+
error?.message ||
|
|
132
|
+
'Nao foi possivel carregar as configuracoes privadas da empresa principal.',
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
.finally(() => {
|
|
137
|
+
if (!cancelled) {
|
|
138
|
+
setIsLoadingPrivateConfigs(false);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return () => {
|
|
143
|
+
cancelled = true;
|
|
144
|
+
};
|
|
145
|
+
}, [mainCompany?.id, hasMainCompanyAccess, showError]);
|
|
146
|
+
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
setCieloConfig(resolveCieloConfig(privateConfigs));
|
|
149
|
+
setNewRelicConfig(resolveNewRelicConfig(privateConfigs));
|
|
150
|
+
setSpotifyConfig(resolveSpotifyConfig(privateConfigs));
|
|
151
|
+
}, [privateConfigs]);
|
|
152
|
+
|
|
153
|
+
const savePrivateConfig = useCallback(
|
|
154
|
+
(configKey, configValue) => {
|
|
155
|
+
if (!hasMainCompanyAccess || !mainCompany?.id) {
|
|
156
|
+
showError(
|
|
157
|
+
'Nao foi possivel identificar a empresa principal para salvar a integracao.',
|
|
158
|
+
);
|
|
159
|
+
return Promise.resolve(false);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (!isMainCompanySelected) {
|
|
163
|
+
showError(
|
|
164
|
+
`Abra a empresa principal (${mainCompanyLabel}) para editar essas credenciais.`,
|
|
165
|
+
);
|
|
166
|
+
return Promise.resolve(false);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return new Promise(resolve => {
|
|
170
|
+
configActions.addToQueue(() =>
|
|
171
|
+
configActions
|
|
172
|
+
.addConfigs({
|
|
173
|
+
configKey,
|
|
174
|
+
configValue: toConfigRequestValue(configValue),
|
|
175
|
+
people: '/people/' + mainCompany.id,
|
|
176
|
+
module: 4,
|
|
177
|
+
visibility: 'private',
|
|
178
|
+
})
|
|
179
|
+
.then(async data => {
|
|
180
|
+
setPrivateConfigs(currentValue => ({
|
|
181
|
+
...(currentValue || {}),
|
|
182
|
+
[configKey]: toConfigCacheValue(configValue),
|
|
183
|
+
}));
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
await peopleActions.mainCompany();
|
|
187
|
+
} catch {}
|
|
188
|
+
|
|
189
|
+
showSuccess('Configuracao tecnica salva com sucesso.');
|
|
190
|
+
resolve(true);
|
|
191
|
+
return data;
|
|
192
|
+
})
|
|
193
|
+
.catch(err => {
|
|
194
|
+
showError(err?.message || JSON.stringify(err));
|
|
195
|
+
resolve(false);
|
|
196
|
+
return null;
|
|
197
|
+
}),
|
|
198
|
+
);
|
|
199
|
+
configActions.initQueue();
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
[
|
|
203
|
+
configActions,
|
|
204
|
+
mainCompany?.id,
|
|
205
|
+
mainCompanyLabel,
|
|
206
|
+
hasMainCompanyAccess,
|
|
207
|
+
isMainCompanySelected,
|
|
208
|
+
peopleActions,
|
|
209
|
+
showError,
|
|
210
|
+
showSuccess,
|
|
211
|
+
],
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
const saveCieloConfig = useCallback(
|
|
215
|
+
() => savePrivateConfig(CIELO_CONFIG_KEY, cieloConfig),
|
|
216
|
+
[cieloConfig, savePrivateConfig],
|
|
217
|
+
);
|
|
218
|
+
const saveNewRelicConfig = useCallback(
|
|
219
|
+
() => savePrivateConfig(NEW_RELIC_CONFIG_KEY, newRelicConfig),
|
|
220
|
+
[newRelicConfig, savePrivateConfig],
|
|
221
|
+
);
|
|
222
|
+
const saveSpotifyConfig = useCallback(
|
|
223
|
+
() => savePrivateConfig(SPOTIFY_CONFIG_KEY, spotifyConfig),
|
|
224
|
+
[savePrivateConfig, spotifyConfig],
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
const editable =
|
|
228
|
+
hasMainCompanyAccess &&
|
|
229
|
+
!!mainCompany?.id &&
|
|
230
|
+
isMainCompanySelected &&
|
|
231
|
+
!isSaving &&
|
|
232
|
+
!isLoadingPrivateConfigs;
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
<>
|
|
236
|
+
<LoginSection />
|
|
237
|
+
|
|
238
|
+
<GeneralSettingsSection
|
|
239
|
+
description="Credenciais tecnicas da Cielo centralizadas na empresa principal."
|
|
240
|
+
icon="credit-card"
|
|
241
|
+
iconBackgroundColor={themePalette.cardIconBackground}
|
|
242
|
+
iconColor={themePalette.cardIconColor}
|
|
243
|
+
title="Cielo">
|
|
244
|
+
<Text style={localStyles.helperText}>
|
|
245
|
+
{`Esses dados privados ficam vinculados a empresa principal (${mainCompanyLabel}).`}
|
|
246
|
+
</Text>
|
|
247
|
+
{!isMainCompanySelected && hasMainCompanyAccess && (
|
|
248
|
+
<Text style={localStyles.helperText}>
|
|
249
|
+
Abra a empresa principal para editar as credenciais. Fora dela esta
|
|
250
|
+
tela fica somente para consulta.
|
|
251
|
+
</Text>
|
|
252
|
+
)}
|
|
253
|
+
{isLoadingPrivateConfigs && (
|
|
254
|
+
<ActivityIndicator
|
|
255
|
+
style={localStyles.sectionLoader}
|
|
256
|
+
color={themePalette.loadingSpinner}
|
|
257
|
+
/>
|
|
258
|
+
)}
|
|
259
|
+
|
|
260
|
+
<IntegrationField
|
|
261
|
+
editable={editable}
|
|
262
|
+
fieldKey="ACCESS_TOKEN"
|
|
263
|
+
onBlur={saveCieloConfig}
|
|
264
|
+
onChangeText={buildConfigUpdater(setCieloConfig, 'ACCESS_TOKEN')}
|
|
265
|
+
placeholder="Token da integracao Cielo"
|
|
266
|
+
sectionState={cieloConfig}
|
|
267
|
+
styles={localStyles}
|
|
268
|
+
/>
|
|
269
|
+
<IntegrationField
|
|
270
|
+
editable={editable}
|
|
271
|
+
fieldKey="CLIENT_ID"
|
|
272
|
+
onBlur={saveCieloConfig}
|
|
273
|
+
onChangeText={buildConfigUpdater(setCieloConfig, 'CLIENT_ID')}
|
|
274
|
+
placeholder="Client ID da Cielo"
|
|
275
|
+
sectionState={cieloConfig}
|
|
276
|
+
styles={localStyles}
|
|
277
|
+
/>
|
|
278
|
+
<IntegrationField
|
|
279
|
+
editable={editable}
|
|
280
|
+
fieldKey="EMAIL"
|
|
281
|
+
onBlur={saveCieloConfig}
|
|
282
|
+
onChangeText={buildConfigUpdater(setCieloConfig, 'EMAIL')}
|
|
283
|
+
placeholder="financeiro@empresa.com.br"
|
|
284
|
+
sectionState={cieloConfig}
|
|
285
|
+
styles={localStyles}
|
|
286
|
+
/>
|
|
287
|
+
</GeneralSettingsSection>
|
|
288
|
+
|
|
289
|
+
<GeneralSettingsSection
|
|
290
|
+
description="Campos de observabilidade centralizados na empresa principal."
|
|
291
|
+
icon="analytics"
|
|
292
|
+
iconBackgroundColor={themePalette.cardIconBackground}
|
|
293
|
+
iconColor={themePalette.cardIconColor}
|
|
294
|
+
title="New Relic">
|
|
295
|
+
<Text style={localStyles.helperText}>
|
|
296
|
+
Use esta area para centralizar os parametros do New Relic da empresa
|
|
297
|
+
principal.
|
|
298
|
+
</Text>
|
|
299
|
+
|
|
300
|
+
<IntegrationField
|
|
301
|
+
editable={editable}
|
|
302
|
+
fieldKey="LICENSE_KEY"
|
|
303
|
+
onBlur={saveNewRelicConfig}
|
|
304
|
+
onChangeText={buildConfigUpdater(setNewRelicConfig, 'LICENSE_KEY')}
|
|
305
|
+
placeholder="License key"
|
|
306
|
+
sectionState={newRelicConfig}
|
|
307
|
+
styles={localStyles}
|
|
308
|
+
/>
|
|
309
|
+
<IntegrationField
|
|
310
|
+
editable={editable}
|
|
311
|
+
fieldKey="APPLICATION_ID"
|
|
312
|
+
onBlur={saveNewRelicConfig}
|
|
313
|
+
onChangeText={buildConfigUpdater(
|
|
314
|
+
setNewRelicConfig,
|
|
315
|
+
'APPLICATION_ID',
|
|
316
|
+
)}
|
|
317
|
+
placeholder="Application ID"
|
|
318
|
+
sectionState={newRelicConfig}
|
|
319
|
+
styles={localStyles}
|
|
320
|
+
/>
|
|
321
|
+
<IntegrationField
|
|
322
|
+
editable={editable}
|
|
323
|
+
fieldKey="ACCOUNT_ID"
|
|
324
|
+
onBlur={saveNewRelicConfig}
|
|
325
|
+
onChangeText={buildConfigUpdater(setNewRelicConfig, 'ACCOUNT_ID')}
|
|
326
|
+
placeholder="Account ID"
|
|
327
|
+
sectionState={newRelicConfig}
|
|
328
|
+
styles={localStyles}
|
|
329
|
+
/>
|
|
330
|
+
<IntegrationField
|
|
331
|
+
editable={editable}
|
|
332
|
+
fieldKey="TRUST_KEY"
|
|
333
|
+
onBlur={saveNewRelicConfig}
|
|
334
|
+
onChangeText={buildConfigUpdater(setNewRelicConfig, 'TRUST_KEY')}
|
|
335
|
+
placeholder="Trust key"
|
|
336
|
+
sectionState={newRelicConfig}
|
|
337
|
+
styles={localStyles}
|
|
338
|
+
/>
|
|
339
|
+
<IntegrationField
|
|
340
|
+
editable={editable}
|
|
341
|
+
fieldKey="BEACON"
|
|
342
|
+
onBlur={saveNewRelicConfig}
|
|
343
|
+
onChangeText={buildConfigUpdater(setNewRelicConfig, 'BEACON')}
|
|
344
|
+
placeholder="bam.nr-data.net"
|
|
345
|
+
sectionState={newRelicConfig}
|
|
346
|
+
styles={localStyles}
|
|
347
|
+
/>
|
|
348
|
+
<IntegrationField
|
|
349
|
+
editable={editable}
|
|
350
|
+
fieldKey="ERROR_BEACON"
|
|
351
|
+
onBlur={saveNewRelicConfig}
|
|
352
|
+
onChangeText={buildConfigUpdater(setNewRelicConfig, 'ERROR_BEACON')}
|
|
353
|
+
placeholder="bam.nr-data.net"
|
|
354
|
+
sectionState={newRelicConfig}
|
|
355
|
+
styles={localStyles}
|
|
356
|
+
/>
|
|
357
|
+
</GeneralSettingsSection>
|
|
358
|
+
|
|
359
|
+
<GeneralSettingsSection
|
|
360
|
+
description="Chaves usadas pela integracao Spotify da empresa principal."
|
|
361
|
+
icon="graphic-eq"
|
|
362
|
+
iconBackgroundColor={themePalette.cardIconBackground}
|
|
363
|
+
iconColor={themePalette.cardIconColor}
|
|
364
|
+
title="Spotify">
|
|
365
|
+
<Text style={localStyles.helperText}>
|
|
366
|
+
Guarde aqui as chaves de Spotify vinculadas a empresa principal.
|
|
367
|
+
</Text>
|
|
368
|
+
|
|
369
|
+
<IntegrationField
|
|
370
|
+
editable={editable}
|
|
371
|
+
fieldKey="CLIENT_ID"
|
|
372
|
+
onBlur={saveSpotifyConfig}
|
|
373
|
+
onChangeText={buildConfigUpdater(setSpotifyConfig, 'CLIENT_ID')}
|
|
374
|
+
placeholder="Client ID do Spotify"
|
|
375
|
+
sectionState={spotifyConfig}
|
|
376
|
+
styles={localStyles}
|
|
377
|
+
/>
|
|
378
|
+
<IntegrationField
|
|
379
|
+
editable={editable}
|
|
380
|
+
fieldKey="CLIENT_SECRET"
|
|
381
|
+
onBlur={saveSpotifyConfig}
|
|
382
|
+
onChangeText={buildConfigUpdater(setSpotifyConfig, 'CLIENT_SECRET')}
|
|
383
|
+
placeholder="Client secret do Spotify"
|
|
384
|
+
sectionState={spotifyConfig}
|
|
385
|
+
styles={localStyles}
|
|
386
|
+
/>
|
|
387
|
+
</GeneralSettingsSection>
|
|
388
|
+
</>
|
|
389
|
+
);
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
export default IntegrationsSection;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents This section exposes the runtime logs and log-related controls.
|
|
3
|
+
* It should remain read-oriented and avoid duplicating queue or transport logic locally.
|
|
4
|
+
*/
|
|
5
|
+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
6
|
+
import {Switch, Text, TextInput, View} from 'react-native';
|
|
7
|
+
|
|
8
|
+
import useToastMessage from '@controleonline/ui-crm/src/react/hooks/useToastMessage';
|
|
9
|
+
import {
|
|
10
|
+
DEFAULT_LOG_POLICY,
|
|
11
|
+
findInvalidLogAlertRecipients,
|
|
12
|
+
formatRecipientsForInput,
|
|
13
|
+
LOG_ERROR_EMAIL_ENABLED_KEY,
|
|
14
|
+
LOG_ERROR_EMAIL_RECIPIENTS_KEY,
|
|
15
|
+
LOG_POLICY_CONFIG_KEY,
|
|
16
|
+
LOG_POLICY_ITEMS,
|
|
17
|
+
normalizeLogAlertRecipients,
|
|
18
|
+
normalizeLogPolicy,
|
|
19
|
+
} from '@controleonline/ui-common/src/react/utils/logSettings';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
getGeneralSettingsSwitchProps,
|
|
23
|
+
useGeneralSettingsPalette,
|
|
24
|
+
useGeneralSettingsStyles,
|
|
25
|
+
} from '../GeneralSettings.styles';
|
|
26
|
+
import GeneralSettingsSection from '../GeneralSettingsSection';
|
|
27
|
+
import {useGeneralSettingsConfig} from '../GeneralSettings.shared';
|
|
28
|
+
|
|
29
|
+
const LogPolicyRow = ({
|
|
30
|
+
editable,
|
|
31
|
+
item,
|
|
32
|
+
onChange,
|
|
33
|
+
onCommit,
|
|
34
|
+
palette,
|
|
35
|
+
policy,
|
|
36
|
+
styles,
|
|
37
|
+
}) => {
|
|
38
|
+
const keepForever = policy.retentionDays === null;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<View style={styles.logPolicyCard}>
|
|
42
|
+
<View style={styles.settingRow}>
|
|
43
|
+
<View style={styles.settingCopy}>
|
|
44
|
+
<Text style={styles.statusLabel}>{item.title}</Text>
|
|
45
|
+
<Text style={styles.settingDescription}>{item.description}</Text>
|
|
46
|
+
</View>
|
|
47
|
+
<Switch
|
|
48
|
+
value={!!policy.enabled}
|
|
49
|
+
onValueChange={value => onCommit(item.key, {enabled: value})}
|
|
50
|
+
disabled={!editable}
|
|
51
|
+
{...getGeneralSettingsSwitchProps({
|
|
52
|
+
disabled: !editable,
|
|
53
|
+
palette,
|
|
54
|
+
value: !!policy.enabled,
|
|
55
|
+
})}
|
|
56
|
+
/>
|
|
57
|
+
</View>
|
|
58
|
+
|
|
59
|
+
<View style={styles.settingRow}>
|
|
60
|
+
<View style={styles.settingCopy}>
|
|
61
|
+
<Text style={styles.statusLabel}>Manter para sempre</Text>
|
|
62
|
+
<Text style={styles.settingDescription}>
|
|
63
|
+
Desative para informar quantos dias esse grupo deve ficar salvo.
|
|
64
|
+
</Text>
|
|
65
|
+
</View>
|
|
66
|
+
<Switch
|
|
67
|
+
value={keepForever}
|
|
68
|
+
onValueChange={value =>
|
|
69
|
+
onCommit(item.key, {retentionDays: value ? null : 30})
|
|
70
|
+
}
|
|
71
|
+
disabled={!editable}
|
|
72
|
+
{...getGeneralSettingsSwitchProps({
|
|
73
|
+
disabled: !editable,
|
|
74
|
+
palette,
|
|
75
|
+
value: keepForever,
|
|
76
|
+
})}
|
|
77
|
+
/>
|
|
78
|
+
</View>
|
|
79
|
+
|
|
80
|
+
{!keepForever && (
|
|
81
|
+
<View style={styles.fieldBlock}>
|
|
82
|
+
<Text style={styles.fieldLabel}>Retencao em dias</Text>
|
|
83
|
+
<TextInput
|
|
84
|
+
style={[styles.input, !editable && styles.inputDisabled]}
|
|
85
|
+
value={policy.retentionDays ? String(policy.retentionDays) : ''}
|
|
86
|
+
onChangeText={value =>
|
|
87
|
+
onChange(item.key, {
|
|
88
|
+
retentionDays:
|
|
89
|
+
value.replace(/\D+/g, '').trim() === ''
|
|
90
|
+
? null
|
|
91
|
+
: Number(value.replace(/\D+/g, '')),
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
onBlur={() => onCommit(item.key)}
|
|
95
|
+
editable={editable}
|
|
96
|
+
keyboardType="numeric"
|
|
97
|
+
placeholder="30"
|
|
98
|
+
/>
|
|
99
|
+
</View>
|
|
100
|
+
)}
|
|
101
|
+
</View>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const LogSection = () => {
|
|
106
|
+
const localStyles = useGeneralSettingsStyles();
|
|
107
|
+
const themePalette = useGeneralSettingsPalette();
|
|
108
|
+
const {showError, showSuccess} = useToastMessage();
|
|
109
|
+
const {
|
|
110
|
+
currentCompany,
|
|
111
|
+
mainCompany,
|
|
112
|
+
mainCompanyLabel,
|
|
113
|
+
effectiveCompanyConfigs,
|
|
114
|
+
isMainCompanySelected,
|
|
115
|
+
isSaving,
|
|
116
|
+
peopleActions,
|
|
117
|
+
saveConfigs,
|
|
118
|
+
} = useGeneralSettingsConfig();
|
|
119
|
+
|
|
120
|
+
const logConfigsSource = useMemo(() => {
|
|
121
|
+
if (isMainCompanySelected) {
|
|
122
|
+
return effectiveCompanyConfigs;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return mainCompany?.configs || {};
|
|
126
|
+
}, [mainCompany?.configs, effectiveCompanyConfigs, isMainCompanySelected]);
|
|
127
|
+
|
|
128
|
+
const [emailAlertsEnabled, setEmailAlertsEnabled] = useState(false);
|
|
129
|
+
const [recipientInput, setRecipientInput] = useState('');
|
|
130
|
+
const [logPolicy, setLogPolicy] = useState(DEFAULT_LOG_POLICY);
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
setEmailAlertsEnabled(
|
|
134
|
+
String(logConfigsSource?.[LOG_ERROR_EMAIL_ENABLED_KEY] || '')
|
|
135
|
+
.trim()
|
|
136
|
+
.toLowerCase() === 'true' ||
|
|
137
|
+
String(logConfigsSource?.[LOG_ERROR_EMAIL_ENABLED_KEY] || '').trim() === '1',
|
|
138
|
+
);
|
|
139
|
+
setRecipientInput(
|
|
140
|
+
formatRecipientsForInput(logConfigsSource?.[LOG_ERROR_EMAIL_RECIPIENTS_KEY]),
|
|
141
|
+
);
|
|
142
|
+
setLogPolicy(normalizeLogPolicy(logConfigsSource?.[LOG_POLICY_CONFIG_KEY]));
|
|
143
|
+
}, [logConfigsSource]);
|
|
144
|
+
|
|
145
|
+
const editable = !!currentCompany?.id && isMainCompanySelected && !isSaving;
|
|
146
|
+
|
|
147
|
+
const saveLogSettings = useCallback(
|
|
148
|
+
async ({
|
|
149
|
+
nextEmailAlertsEnabled = emailAlertsEnabled,
|
|
150
|
+
nextLogPolicy = logPolicy,
|
|
151
|
+
nextRecipientInput = recipientInput,
|
|
152
|
+
} = {}) => {
|
|
153
|
+
if (!mainCompany?.id || !isMainCompanySelected) {
|
|
154
|
+
showError(
|
|
155
|
+
`Abra a empresa principal (${mainCompanyLabel}) para editar as configuracoes de log.`,
|
|
156
|
+
);
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const invalidRecipients = findInvalidLogAlertRecipients(
|
|
161
|
+
nextRecipientInput,
|
|
162
|
+
);
|
|
163
|
+
if (invalidRecipients.length > 0) {
|
|
164
|
+
showError(
|
|
165
|
+
`Existem e-mails invalidos na lista: ${invalidRecipients.join(', ')}`,
|
|
166
|
+
);
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const normalizedRecipients = normalizeLogAlertRecipients(
|
|
171
|
+
nextRecipientInput,
|
|
172
|
+
);
|
|
173
|
+
if (nextEmailAlertsEnabled && normalizedRecipients.length === 0) {
|
|
174
|
+
showError(
|
|
175
|
+
'Informe ao menos um e-mail valido ou desabilite o aviso por e-mail.',
|
|
176
|
+
);
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const success = await saveConfigs({
|
|
181
|
+
[LOG_ERROR_EMAIL_ENABLED_KEY]: nextEmailAlertsEnabled,
|
|
182
|
+
[LOG_ERROR_EMAIL_RECIPIENTS_KEY]: normalizedRecipients,
|
|
183
|
+
[LOG_POLICY_CONFIG_KEY]: nextLogPolicy,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
if (!success) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
await peopleActions.mainCompany();
|
|
192
|
+
} catch {}
|
|
193
|
+
|
|
194
|
+
showSuccess('Configuracoes de log salvas com sucesso.');
|
|
195
|
+
return true;
|
|
196
|
+
},
|
|
197
|
+
[
|
|
198
|
+
mainCompany?.id,
|
|
199
|
+
mainCompanyLabel,
|
|
200
|
+
emailAlertsEnabled,
|
|
201
|
+
isMainCompanySelected,
|
|
202
|
+
logPolicy,
|
|
203
|
+
peopleActions,
|
|
204
|
+
recipientInput,
|
|
205
|
+
saveConfigs,
|
|
206
|
+
showError,
|
|
207
|
+
showSuccess,
|
|
208
|
+
],
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const updatePolicy = useCallback((policyKey, patch) => {
|
|
212
|
+
setLogPolicy(currentValue => ({
|
|
213
|
+
...currentValue,
|
|
214
|
+
[policyKey]: {
|
|
215
|
+
...(currentValue[policyKey] || DEFAULT_LOG_POLICY[policyKey]),
|
|
216
|
+
...patch,
|
|
217
|
+
},
|
|
218
|
+
}));
|
|
219
|
+
}, []);
|
|
220
|
+
|
|
221
|
+
const commitPolicyChange = useCallback(
|
|
222
|
+
(policyKey, patch = {}) => {
|
|
223
|
+
const nextLogPolicy = {
|
|
224
|
+
...logPolicy,
|
|
225
|
+
[policyKey]: {
|
|
226
|
+
...(logPolicy[policyKey] || DEFAULT_LOG_POLICY[policyKey]),
|
|
227
|
+
...patch,
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
setLogPolicy(nextLogPolicy);
|
|
232
|
+
saveLogSettings({nextLogPolicy});
|
|
233
|
+
},
|
|
234
|
+
[logPolicy, saveLogSettings],
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<GeneralSettingsSection
|
|
239
|
+
description="Centraliza avisos por e-mail e a politica geral de habilitacao e retencao dos logs do sistema."
|
|
240
|
+
icon="bug-report"
|
|
241
|
+
iconBackgroundColor={themePalette.cardIconBackground}
|
|
242
|
+
iconColor={themePalette.cardIconColor}
|
|
243
|
+
title="Logs e alertas">
|
|
244
|
+
<Text style={localStyles.helperText}>
|
|
245
|
+
{`Essas configuracoes sao globais e ficam vinculadas a empresa principal (${mainCompanyLabel}).`}
|
|
246
|
+
</Text>
|
|
247
|
+
|
|
248
|
+
{!isMainCompanySelected && (
|
|
249
|
+
<Text style={localStyles.helperText}>
|
|
250
|
+
Abra a empresa principal para editar essa politica. Nesta visualizacao
|
|
251
|
+
voce esta vendo apenas a configuracao central.
|
|
252
|
+
</Text>
|
|
253
|
+
)}
|
|
254
|
+
|
|
255
|
+
<View style={localStyles.settingRow}>
|
|
256
|
+
<View style={localStyles.settingCopy}>
|
|
257
|
+
<Text style={localStyles.statusLabel}>Aviso por e-mail para erro 500</Text>
|
|
258
|
+
<Text style={localStyles.settingDescription}>
|
|
259
|
+
Quando ativo, erros criticos do backend enviam alerta para os e-mails informados abaixo.
|
|
260
|
+
</Text>
|
|
261
|
+
</View>
|
|
262
|
+
<Switch
|
|
263
|
+
value={emailAlertsEnabled}
|
|
264
|
+
onValueChange={value => {
|
|
265
|
+
setEmailAlertsEnabled(value);
|
|
266
|
+
saveLogSettings({nextEmailAlertsEnabled: value});
|
|
267
|
+
}}
|
|
268
|
+
disabled={!editable}
|
|
269
|
+
{...getGeneralSettingsSwitchProps({
|
|
270
|
+
disabled: !editable,
|
|
271
|
+
palette: themePalette,
|
|
272
|
+
value: emailAlertsEnabled,
|
|
273
|
+
})}
|
|
274
|
+
/>
|
|
275
|
+
</View>
|
|
276
|
+
|
|
277
|
+
<View style={localStyles.fieldBlock}>
|
|
278
|
+
<Text style={localStyles.fieldLabel}>Destinatarios</Text>
|
|
279
|
+
<TextInput
|
|
280
|
+
style={[
|
|
281
|
+
localStyles.input,
|
|
282
|
+
localStyles.multilineInput,
|
|
283
|
+
(!editable || !emailAlertsEnabled) && localStyles.inputDisabled,
|
|
284
|
+
]}
|
|
285
|
+
value={recipientInput}
|
|
286
|
+
onChangeText={setRecipientInput}
|
|
287
|
+
onBlur={() => saveLogSettings()}
|
|
288
|
+
editable={editable && emailAlertsEnabled}
|
|
289
|
+
multiline
|
|
290
|
+
placeholder={'ops@empresa.com.br\nsuporte@empresa.com.br'}
|
|
291
|
+
/>
|
|
292
|
+
<Text style={localStyles.helperText}>
|
|
293
|
+
Use um e-mail por linha ou separe por virgula. Deixe vazio para manter o aviso desabilitado.
|
|
294
|
+
</Text>
|
|
295
|
+
</View>
|
|
296
|
+
|
|
297
|
+
<View style={localStyles.fieldBlock}>
|
|
298
|
+
<Text style={localStyles.fieldLabel}>Politica geral de logs</Text>
|
|
299
|
+
<Text style={localStyles.helperText}>
|
|
300
|
+
Defina quais grupos continuam gravando e por quanto tempo ficam retidos antes da limpeza automatica.
|
|
301
|
+
</Text>
|
|
302
|
+
</View>
|
|
303
|
+
|
|
304
|
+
<View style={localStyles.logPolicyList}>
|
|
305
|
+
{LOG_POLICY_ITEMS.map(item => (
|
|
306
|
+
<LogPolicyRow
|
|
307
|
+
key={item.key}
|
|
308
|
+
editable={editable}
|
|
309
|
+
item={item}
|
|
310
|
+
onChange={updatePolicy}
|
|
311
|
+
onCommit={commitPolicyChange}
|
|
312
|
+
palette={themePalette}
|
|
313
|
+
policy={logPolicy[item.key] || DEFAULT_LOG_POLICY[item.key]}
|
|
314
|
+
styles={localStyles}
|
|
315
|
+
/>
|
|
316
|
+
))}
|
|
317
|
+
</View>
|
|
318
|
+
</GeneralSettingsSection>
|
|
319
|
+
);
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
export default LogSection;
|