@controleonline/ui-common 1.2.104 → 1.2.106
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/package.json +1 -1
- package/src/react/pages/LinkedInIntegrationPage.js +362 -0
- package/src/react/pages/MarketplaceIntegrationPage/index.js +67 -60
- package/src/react/pages/integrationsCatalog.js +23 -0
- package/src/react/pages/linkedinIntegrationHelpers.js +78 -0
- package/src/react/utils/fileUrl.js +12 -15
- package/src/tests/react/utils/fileUrl.test.js +23 -0
package/package.json
CHANGED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ActivityIndicator,
|
|
4
|
+
Linking,
|
|
5
|
+
Platform,
|
|
6
|
+
RefreshControl,
|
|
7
|
+
ScrollView,
|
|
8
|
+
Text,
|
|
9
|
+
TouchableOpacity,
|
|
10
|
+
View,
|
|
11
|
+
} from 'react-native';
|
|
12
|
+
import {SafeAreaView} from 'react-native-safe-area-context';
|
|
13
|
+
import {useFocusEffect} from '@react-navigation/native';
|
|
14
|
+
import Icon from 'react-native-vector-icons/Feather';
|
|
15
|
+
|
|
16
|
+
import {api} from '@controleonline/ui-common/src/api';
|
|
17
|
+
import useToastMessage from '@controleonline/ui-crm/src/react/hooks/useToastMessage';
|
|
18
|
+
import {useStore} from '@store';
|
|
19
|
+
import {colors} from '@controleonline/../../src/styles/colors';
|
|
20
|
+
import {
|
|
21
|
+
resolveThemePalette,
|
|
22
|
+
withOpacity,
|
|
23
|
+
} from '@controleonline/../../src/styles/branding';
|
|
24
|
+
|
|
25
|
+
import styles from './IntegrationConfigPage.styles';
|
|
26
|
+
import {
|
|
27
|
+
isConnected,
|
|
28
|
+
formatApiError,
|
|
29
|
+
resolveFrontOAuthRedirectUri,
|
|
30
|
+
replaceFrontOAuthStatus,
|
|
31
|
+
formatOAuthStatusError,
|
|
32
|
+
} from './linkedinIntegrationHelpers';
|
|
33
|
+
|
|
34
|
+
const PROVIDER = {
|
|
35
|
+
key: 'linkedin',
|
|
36
|
+
label: 'LinkedIn',
|
|
37
|
+
accent: '#0A66C2',
|
|
38
|
+
button: '#0A66C2',
|
|
39
|
+
icon: 'link',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const tt = (type, key) => global.t?.t('configs', type, key);
|
|
43
|
+
|
|
44
|
+
const shadowStyle = Platform.select({
|
|
45
|
+
ios: {
|
|
46
|
+
shadowColor: '#0F172A',
|
|
47
|
+
shadowOffset: {width: 0, height: 8},
|
|
48
|
+
shadowOpacity: 0.08,
|
|
49
|
+
shadowRadius: 16,
|
|
50
|
+
},
|
|
51
|
+
android: {elevation: 3},
|
|
52
|
+
web: {boxShadow: '0 10px 24px rgba(15,23,42,0.08)'},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export default function LinkedInIntegrationPage() {
|
|
56
|
+
const peopleStore = useStore('people');
|
|
57
|
+
const themeStore = useStore('theme');
|
|
58
|
+
const {currentCompany} = peopleStore.getters;
|
|
59
|
+
const {colors: themeColors} = themeStore.getters;
|
|
60
|
+
const {showError, showSuccess} = useToastMessage();
|
|
61
|
+
|
|
62
|
+
const providerId = currentCompany?.id;
|
|
63
|
+
const brandColors = useMemo(
|
|
64
|
+
() =>
|
|
65
|
+
resolveThemePalette(
|
|
66
|
+
{
|
|
67
|
+
...themeColors,
|
|
68
|
+
...(currentCompany?.theme?.colors || {}),
|
|
69
|
+
},
|
|
70
|
+
colors,
|
|
71
|
+
),
|
|
72
|
+
[themeColors, currentCompany?.id],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const [loading, setLoading] = useState(true);
|
|
76
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
77
|
+
const [authorizing, setAuthorizing] = useState(false);
|
|
78
|
+
const [disconnecting, setDisconnecting] = useState(false);
|
|
79
|
+
const [status, setStatus] = useState(null);
|
|
80
|
+
|
|
81
|
+
const loadPageData = useCallback(
|
|
82
|
+
async ({showLoading = true} = {}) => {
|
|
83
|
+
if (!providerId) {
|
|
84
|
+
setStatus(null);
|
|
85
|
+
setLoading(false);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (showLoading) {
|
|
90
|
+
setLoading(true);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const response = await api.fetch('/integrations/linkedin/status', {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
body: {
|
|
97
|
+
provider_id: providerId,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
setStatus(response || null);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
setStatus(null);
|
|
103
|
+
showError(formatApiError(error));
|
|
104
|
+
} finally {
|
|
105
|
+
setLoading(false);
|
|
106
|
+
setRefreshing(false);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
[providerId, showError],
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
useFocusEffect(
|
|
113
|
+
useCallback(() => {
|
|
114
|
+
loadPageData();
|
|
115
|
+
}, [loadPageData]),
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (Platform.OS !== 'web' || typeof window === 'undefined') {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const params = new URLSearchParams(window.location.search || '');
|
|
124
|
+
const alreadyConnected = params.get('linkedin_connected') === '1';
|
|
125
|
+
const oauthStatusError = params.get('linkedin_error');
|
|
126
|
+
const oauthStatusMessage = params.get('linkedin_message');
|
|
127
|
+
|
|
128
|
+
if (alreadyConnected) {
|
|
129
|
+
showSuccess(
|
|
130
|
+
tt('marketplace_message', 'linkedinConnected') ||
|
|
131
|
+
'LinkedIn conectado com sucesso.',
|
|
132
|
+
);
|
|
133
|
+
replaceFrontOAuthStatus({});
|
|
134
|
+
loadPageData({showLoading: false});
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (oauthStatusError) {
|
|
139
|
+
showError(formatOAuthStatusError(oauthStatusError, oauthStatusMessage));
|
|
140
|
+
replaceFrontOAuthStatus({});
|
|
141
|
+
}
|
|
142
|
+
}, [loadPageData, showError, showSuccess]);
|
|
143
|
+
|
|
144
|
+
const onRefresh = useCallback(() => {
|
|
145
|
+
setRefreshing(true);
|
|
146
|
+
loadPageData({showLoading: false});
|
|
147
|
+
}, [loadPageData]);
|
|
148
|
+
|
|
149
|
+
const connectLinkedIn = useCallback(async () => {
|
|
150
|
+
if (!providerId) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (status?.client_configured === false) {
|
|
155
|
+
showError(
|
|
156
|
+
tt('marketplace_message', 'linkedinClientConfigRequired') ||
|
|
157
|
+
'Configure o Client ID e Secret do app LinkedIn nesta empresa para habilitar o login.',
|
|
158
|
+
);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
setAuthorizing(true);
|
|
163
|
+
try {
|
|
164
|
+
const returnUrl =
|
|
165
|
+
resolveFrontOAuthRedirectUri() ||
|
|
166
|
+
(typeof window !== 'undefined' ? window.location.href : undefined);
|
|
167
|
+
|
|
168
|
+
const response = await api.fetch('/integrations/linkedin/authorization-page', {
|
|
169
|
+
method: 'POST',
|
|
170
|
+
body: {
|
|
171
|
+
provider_id: providerId,
|
|
172
|
+
return_url: returnUrl,
|
|
173
|
+
app_domain:
|
|
174
|
+
typeof window !== 'undefined' ? window.location.hostname : undefined,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const authorizationUrl =
|
|
179
|
+
response?.authorization_url || response?.url || response?.auth_url || '';
|
|
180
|
+
if (!authorizationUrl) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
response?.message ||
|
|
183
|
+
tt('marketplace_error', 'linkedinAuthorizationUrl') ||
|
|
184
|
+
'URL de autorizacao LinkedIn indisponivel.',
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
await Linking.openURL(authorizationUrl);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
showError(formatApiError(error));
|
|
191
|
+
} finally {
|
|
192
|
+
setAuthorizing(false);
|
|
193
|
+
}
|
|
194
|
+
}, [providerId, showError, status?.client_configured]);
|
|
195
|
+
|
|
196
|
+
const disconnectLinkedIn = useCallback(async () => {
|
|
197
|
+
if (!providerId) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
setDisconnecting(true);
|
|
202
|
+
try {
|
|
203
|
+
await api.fetch('/integrations/linkedin/disconnect', {
|
|
204
|
+
method: 'POST',
|
|
205
|
+
body: {
|
|
206
|
+
provider_id: providerId,
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
showSuccess(
|
|
210
|
+
tt('marketplace_message', 'linkedinDisconnected') ||
|
|
211
|
+
'LinkedIn desconectado.',
|
|
212
|
+
);
|
|
213
|
+
await loadPageData({showLoading: false});
|
|
214
|
+
} catch (error) {
|
|
215
|
+
showError(formatApiError(error));
|
|
216
|
+
} finally {
|
|
217
|
+
setDisconnecting(false);
|
|
218
|
+
}
|
|
219
|
+
}, [loadPageData, providerId, showError, showSuccess]);
|
|
220
|
+
|
|
221
|
+
if (!providerId) {
|
|
222
|
+
return (
|
|
223
|
+
<SafeAreaView style={styles.container} edges={['bottom']}>
|
|
224
|
+
<View style={styles.centerState}>
|
|
225
|
+
<Icon name="building" size={32} color={PROVIDER.accent} />
|
|
226
|
+
<Text style={styles.centerStateTitle}>
|
|
227
|
+
{tt('integrations_title', 'selectCompany') || 'Selecione uma empresa'}
|
|
228
|
+
</Text>
|
|
229
|
+
</View>
|
|
230
|
+
</SafeAreaView>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (loading) {
|
|
235
|
+
return (
|
|
236
|
+
<SafeAreaView
|
|
237
|
+
style={[styles.container, {backgroundColor: brandColors.background}]}
|
|
238
|
+
edges={['bottom']}>
|
|
239
|
+
<View style={styles.centerState}>
|
|
240
|
+
<ActivityIndicator size="large" color={brandColors.primary} />
|
|
241
|
+
<Text style={styles.centerStateTitle}>
|
|
242
|
+
{tt('marketplace_title', 'loadingLinkedIn') || 'Carregando LinkedIn'}
|
|
243
|
+
</Text>
|
|
244
|
+
</View>
|
|
245
|
+
</SafeAreaView>
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const connected = isConnected(status?.connected);
|
|
250
|
+
const oauthClientConfigured = status?.client_configured !== false;
|
|
251
|
+
const statusTone = connected ? '#16A34A' : '#e67e22';
|
|
252
|
+
const memberLabel = status?.member_name || status?.member_id || null;
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<SafeAreaView
|
|
256
|
+
style={[styles.container, {backgroundColor: brandColors.background}]}
|
|
257
|
+
edges={['bottom']}>
|
|
258
|
+
<ScrollView
|
|
259
|
+
contentContainerStyle={styles.scroll}
|
|
260
|
+
showsVerticalScrollIndicator={false}
|
|
261
|
+
refreshControl={
|
|
262
|
+
<RefreshControl
|
|
263
|
+
refreshing={refreshing}
|
|
264
|
+
onRefresh={onRefresh}
|
|
265
|
+
tintColor={brandColors.primary}
|
|
266
|
+
/>
|
|
267
|
+
}>
|
|
268
|
+
<View style={[styles.statusCard, shadowStyle]}>
|
|
269
|
+
<View style={styles.statusHeader}>
|
|
270
|
+
<View style={styles.statusCopy}>
|
|
271
|
+
<Text style={styles.cardTitle}>
|
|
272
|
+
{tt('marketplace_title', 'status') || 'Status'}
|
|
273
|
+
</Text>
|
|
274
|
+
<Text style={styles.cardSubtitle}>
|
|
275
|
+
{memberLabel
|
|
276
|
+
? `Conta: ${memberLabel}`
|
|
277
|
+
: tt('marketplace_message', 'connectLinkedInAccount') ||
|
|
278
|
+
'Conecte a conta LinkedIn da empresa ativa.'}
|
|
279
|
+
</Text>
|
|
280
|
+
</View>
|
|
281
|
+
<View
|
|
282
|
+
style={[
|
|
283
|
+
styles.statusBadge,
|
|
284
|
+
{backgroundColor: withOpacity(statusTone, 0.12)},
|
|
285
|
+
]}>
|
|
286
|
+
<Text style={[styles.statusBadgeText, {color: statusTone}]}>
|
|
287
|
+
{connected
|
|
288
|
+
? tt('marketplace_status', 'connected') || 'Conectado'
|
|
289
|
+
: tt('marketplace_status', 'pending') || 'Pendente'}
|
|
290
|
+
</Text>
|
|
291
|
+
</View>
|
|
292
|
+
</View>
|
|
293
|
+
</View>
|
|
294
|
+
|
|
295
|
+
<View style={[styles.formCard, shadowStyle]}>
|
|
296
|
+
<Text style={styles.cardTitle}>
|
|
297
|
+
{tt('marketplace_title', 'linkedinAccount') || 'Conta LinkedIn'}
|
|
298
|
+
</Text>
|
|
299
|
+
<Text style={styles.cardSubtitle}>
|
|
300
|
+
{oauthClientConfigured
|
|
301
|
+
? tt('marketplace_message', 'linkedinOauthFlow') ||
|
|
302
|
+
'O login abre o LinkedIn, autoriza o perfil e retorna para esta tela.'
|
|
303
|
+
: tt('marketplace_message', 'linkedinClientConfigRequired') ||
|
|
304
|
+
'Configure o Client ID e Secret do app LinkedIn nesta empresa para habilitar o login.'}
|
|
305
|
+
</Text>
|
|
306
|
+
|
|
307
|
+
<TouchableOpacity
|
|
308
|
+
style={[
|
|
309
|
+
styles.saveButton,
|
|
310
|
+
{backgroundColor: PROVIDER.button},
|
|
311
|
+
(!oauthClientConfigured || authorizing) && styles.saveButtonDisabled,
|
|
312
|
+
]}
|
|
313
|
+
disabled={!oauthClientConfigured || authorizing}
|
|
314
|
+
activeOpacity={0.9}
|
|
315
|
+
onPress={connectLinkedIn}
|
|
316
|
+
testID="linkedin-connect-button">
|
|
317
|
+
{authorizing ? (
|
|
318
|
+
<ActivityIndicator color="#FFFFFF" />
|
|
319
|
+
) : (
|
|
320
|
+
<Icon name="external-link" size={16} color="#FFFFFF" />
|
|
321
|
+
)}
|
|
322
|
+
<Text style={styles.saveButtonText}>
|
|
323
|
+
{connected
|
|
324
|
+
? tt('marketplace_button', 'reconnectLinkedIn') ||
|
|
325
|
+
'Reconectar LinkedIn'
|
|
326
|
+
: tt('marketplace_button', 'connectLinkedIn') ||
|
|
327
|
+
'Conectar com LinkedIn'}
|
|
328
|
+
</Text>
|
|
329
|
+
</TouchableOpacity>
|
|
330
|
+
|
|
331
|
+
{connected ? (
|
|
332
|
+
<TouchableOpacity
|
|
333
|
+
style={[
|
|
334
|
+
styles.saveButton,
|
|
335
|
+
{
|
|
336
|
+
backgroundColor: '#FFFFFF',
|
|
337
|
+
borderWidth: 1,
|
|
338
|
+
borderColor: '#DC2626',
|
|
339
|
+
marginTop: 12,
|
|
340
|
+
},
|
|
341
|
+
disconnecting && styles.saveButtonDisabled,
|
|
342
|
+
]}
|
|
343
|
+
disabled={disconnecting}
|
|
344
|
+
activeOpacity={0.9}
|
|
345
|
+
onPress={disconnectLinkedIn}
|
|
346
|
+
testID="linkedin-disconnect-button">
|
|
347
|
+
{disconnecting ? (
|
|
348
|
+
<ActivityIndicator color="#DC2626" />
|
|
349
|
+
) : (
|
|
350
|
+
<Icon name="log-out" size={16} color="#DC2626" />
|
|
351
|
+
)}
|
|
352
|
+
<Text style={[styles.saveButtonText, {color: '#DC2626'}]}>
|
|
353
|
+
{tt('marketplace_button', 'disconnectLinkedIn') ||
|
|
354
|
+
'Desconectar LinkedIn'}
|
|
355
|
+
</Text>
|
|
356
|
+
</TouchableOpacity>
|
|
357
|
+
) : null}
|
|
358
|
+
</View>
|
|
359
|
+
</ScrollView>
|
|
360
|
+
</SafeAreaView>
|
|
361
|
+
);
|
|
362
|
+
}
|
|
@@ -1,60 +1,67 @@
|
|
|
1
|
-
import {useLayoutEffect, useMemo} from 'react';
|
|
2
|
-
|
|
3
|
-
import Food99IntegrationPage from '@controleonline/ui-common/src/react/pages/Food99IntegrationPage';
|
|
4
|
-
import IFoodIntegrationPage from '@controleonline/ui-common/src/react/pages/IFoodIntegrationPage';
|
|
5
|
-
import MercadoLivreIntegrationPage from '@controleonline/ui-common/src/react/pages/MercadoLivreIntegrationPage';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
1
|
+
import {useLayoutEffect, useMemo} from 'react';
|
|
2
|
+
|
|
3
|
+
import Food99IntegrationPage from '@controleonline/ui-common/src/react/pages/Food99IntegrationPage';
|
|
4
|
+
import IFoodIntegrationPage from '@controleonline/ui-common/src/react/pages/IFoodIntegrationPage';
|
|
5
|
+
import MercadoLivreIntegrationPage from '@controleonline/ui-common/src/react/pages/MercadoLivreIntegrationPage';
|
|
6
|
+
import LinkedInIntegrationPage from '@controleonline/ui-common/src/react/pages/LinkedInIntegrationPage';
|
|
7
|
+
|
|
8
|
+
const ROUTE_PROVIDER_MAP = {
|
|
9
|
+
Food99IntegrationPage: '99food',
|
|
10
|
+
IFoodIntegrationPage: 'ifood',
|
|
11
|
+
MercadoLivreIntegrationPage: 'mercadolivre',
|
|
12
|
+
LinkedInIntegrationPage: 'linkedin',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const PROVIDER_LABEL_MAP = {
|
|
16
|
+
'99food': '99Food',
|
|
17
|
+
ifood: 'iFood',
|
|
18
|
+
mercadolivre: 'Mercado Livre',
|
|
19
|
+
linkedin: 'LinkedIn',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const normalizeProviderKey = value =>
|
|
23
|
+
String(value || '')
|
|
24
|
+
.trim()
|
|
25
|
+
.toLowerCase();
|
|
26
|
+
|
|
27
|
+
const resolveProviderKey = route =>
|
|
28
|
+
normalizeProviderKey(
|
|
29
|
+
route?.params?.providerKey ||
|
|
30
|
+
route?.params?.integrationKey ||
|
|
31
|
+
ROUTE_PROVIDER_MAP[route?.name] ||
|
|
32
|
+
'',
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export default function MarketplaceIntegrationPage(props) {
|
|
36
|
+
const {navigation, route} = props;
|
|
37
|
+
|
|
38
|
+
const providerKey = useMemo(
|
|
39
|
+
() => resolveProviderKey(route),
|
|
40
|
+
[route?.name, route?.params?.providerKey, route?.params?.integrationKey],
|
|
41
|
+
);
|
|
42
|
+
const providerLabel = PROVIDER_LABEL_MAP[providerKey] || 'Marketplace';
|
|
43
|
+
|
|
44
|
+
useLayoutEffect(() => {
|
|
45
|
+
if (!navigation?.setOptions) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
navigation.setOptions({
|
|
50
|
+
title: providerLabel,
|
|
51
|
+
});
|
|
52
|
+
}, [navigation, providerLabel]);
|
|
53
|
+
|
|
54
|
+
if (providerKey === 'ifood') {
|
|
55
|
+
return <IFoodIntegrationPage {...props} />;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (providerKey === 'mercadolivre') {
|
|
59
|
+
return <MercadoLivreIntegrationPage {...props} />;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (providerKey === 'linkedin') {
|
|
63
|
+
return <LinkedInIntegrationPage {...props} />;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return <Food99IntegrationPage {...props} />;
|
|
67
|
+
}
|
|
@@ -39,6 +39,16 @@ export const INTEGRATION_LIST = [
|
|
|
39
39
|
accent: '#FFE600',
|
|
40
40
|
icon: 'shopping-bag',
|
|
41
41
|
},
|
|
42
|
+
{
|
|
43
|
+
key: 'linkedin',
|
|
44
|
+
label: 'LinkedIn',
|
|
45
|
+
route: 'MarketplaceIntegrationPage',
|
|
46
|
+
routeParams: {
|
|
47
|
+
providerKey: 'linkedin',
|
|
48
|
+
},
|
|
49
|
+
accent: '#0A66C2',
|
|
50
|
+
icon: 'link',
|
|
51
|
+
},
|
|
42
52
|
{
|
|
43
53
|
key: 'uber',
|
|
44
54
|
label: 'Uber',
|
|
@@ -83,6 +93,19 @@ export const INTEGRATION_LIST = [
|
|
|
83
93
|
];
|
|
84
94
|
|
|
85
95
|
export const INTEGRATION_CONFIGS = {
|
|
96
|
+
linkedin: {
|
|
97
|
+
key: 'linkedin',
|
|
98
|
+
label: 'LinkedIn',
|
|
99
|
+
accent: '#0A66C2',
|
|
100
|
+
icon: 'link',
|
|
101
|
+
description:
|
|
102
|
+
'Conecte a conta LinkedIn da empresa para publicacoes e integracoes sociais.',
|
|
103
|
+
oauthConnect: true,
|
|
104
|
+
authorizationEndpoint: '/integrations/linkedin/authorization-page',
|
|
105
|
+
connectLabel: 'Conectar LinkedIn',
|
|
106
|
+
requiredKeys: [],
|
|
107
|
+
fields: [],
|
|
108
|
+
},
|
|
86
109
|
uber: {
|
|
87
110
|
key: 'uber',
|
|
88
111
|
label: 'Uber',
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {Platform} from 'react-native';
|
|
2
|
+
|
|
3
|
+
const tt = (type, key) => global.t?.t('configs', type, key);
|
|
4
|
+
|
|
5
|
+
export const normalizeTextValue = value => String(value ?? '').trim();
|
|
6
|
+
|
|
7
|
+
export const isConnected = value =>
|
|
8
|
+
value === true ||
|
|
9
|
+
value === 1 ||
|
|
10
|
+
value === '1' ||
|
|
11
|
+
String(value).trim().toLowerCase() === 'true';
|
|
12
|
+
|
|
13
|
+
export const formatApiError = error =>
|
|
14
|
+
error?.message ||
|
|
15
|
+
error?.description ||
|
|
16
|
+
error?.error ||
|
|
17
|
+
tt('marketplace_error', 'linkedinLoad') ||
|
|
18
|
+
'Nao foi possivel carregar a integracao LinkedIn.';
|
|
19
|
+
|
|
20
|
+
const LINKEDIN_OAUTH_QUERY_KEYS = [
|
|
21
|
+
'code',
|
|
22
|
+
'state',
|
|
23
|
+
'error',
|
|
24
|
+
'error_description',
|
|
25
|
+
'linkedin_connected',
|
|
26
|
+
'linkedin_error',
|
|
27
|
+
'linkedin_message',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export const resolveFrontOAuthRedirectUri = () => {
|
|
31
|
+
if (Platform.OS !== 'web' || typeof window === 'undefined') {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const url = new URL(window.location.href);
|
|
36
|
+
LINKEDIN_OAUTH_QUERY_KEYS.forEach(key => url.searchParams.delete(key));
|
|
37
|
+
url.hash = '';
|
|
38
|
+
|
|
39
|
+
return url.toString();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const replaceFrontOAuthStatus = statusParams => {
|
|
43
|
+
if (Platform.OS !== 'web' || typeof window === 'undefined') {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const url = new URL(window.location.href);
|
|
48
|
+
LINKEDIN_OAUTH_QUERY_KEYS.forEach(key => url.searchParams.delete(key));
|
|
49
|
+
Object.entries(statusParams || {}).forEach(([key, value]) => {
|
|
50
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
51
|
+
url.searchParams.set(key, String(value));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
window.history.replaceState({}, document.title, url.toString());
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const formatOAuthStatusError = (error, message) => {
|
|
58
|
+
const messageText = normalizeTextValue(message);
|
|
59
|
+
if (messageText) {
|
|
60
|
+
return `${
|
|
61
|
+
tt('marketplace_error', 'linkedinConnectWithMessage') ||
|
|
62
|
+
'Nao foi possivel conectar o LinkedIn:'
|
|
63
|
+
} ${messageText}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const errorText = normalizeTextValue(error);
|
|
67
|
+
if (!errorText) {
|
|
68
|
+
return (
|
|
69
|
+
tt('marketplace_error', 'linkedinConnect') ||
|
|
70
|
+
'Nao foi possivel conectar o LinkedIn.'
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return `${
|
|
75
|
+
tt('marketplace_error', 'linkedinConnect') ||
|
|
76
|
+
'Nao foi possivel conectar o LinkedIn.'
|
|
77
|
+
} (${errorText}).`;
|
|
78
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {env as APP_ENV} from '@env';
|
|
2
|
-
import {filterApiHeaders} from '../../utils/trustedApiUrl';
|
|
2
|
+
import {filterApiHeaders, isTrustedApiUrl} from '../../utils/trustedApiUrl';
|
|
3
3
|
import {buildAssetUrl} from '@controleonline/../../src/styles/branding';
|
|
4
4
|
import {
|
|
5
5
|
resolveAppDomain,
|
|
@@ -79,16 +79,11 @@ const ensureAbsoluteUrl = url => {
|
|
|
79
79
|
const resolveDownloadHost = ({company = null, appDomain = ''} = {}) => {
|
|
80
80
|
const fallbackDomain =
|
|
81
81
|
normalizeText(appDomain) || resolveAppDomain(APP_ENV?.DOMAIN);
|
|
82
|
-
|
|
82
|
+
const companyDomain = resolveCompanyDomain(company, fallbackDomain);
|
|
83
|
+
// FileService may return the API authority instead of an application domain.
|
|
84
|
+
return isApiEntrypointHost(companyDomain) ? fallbackDomain : companyDomain;
|
|
83
85
|
};
|
|
84
86
|
|
|
85
|
-
/**
|
|
86
|
-
* Environment / platform hosts (staging, dev, localhost) are not tenant domains.
|
|
87
|
-
* Injecting them into /{host}/files/{id}/download produces URLs like
|
|
88
|
-
* https://s.controleonline.com/staging.controleonline.com/files/... → 403.
|
|
89
|
-
* Keep app-domain header only; do not path-inject environment hosts.
|
|
90
|
-
* app-community#432
|
|
91
|
-
*/
|
|
92
87
|
const resolveApiEntrypointHost = () => {
|
|
93
88
|
const entry = normalizeText(APP_ENV?.API_ENTRYPOINT);
|
|
94
89
|
if (!entry) {
|
|
@@ -216,11 +211,10 @@ const buildTenantDownloadUrl = (url, host) => {
|
|
|
216
211
|
return absoluteUrl;
|
|
217
212
|
}
|
|
218
213
|
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (isEnvironmentLikeHost(normalizedHost) || isApiEntrypointHost(normalizedHost)) {
|
|
214
|
+
// Public file routes require the application domain, including registered
|
|
215
|
+
// staging/dev/platform domains. Never use the API authority as that domain.
|
|
216
|
+
if (isApiEntrypointHost(normalizedHost) ||
|
|
217
|
+
!isTrustedApiUrl(absoluteUrl, APP_ENV?.API_ENTRYPOINT)) {
|
|
224
218
|
return absoluteUrl;
|
|
225
219
|
}
|
|
226
220
|
|
|
@@ -377,8 +371,11 @@ const resolveFileSource = (
|
|
|
377
371
|
isDownloadLikeUrl(normalizedFile?.uri) ||
|
|
378
372
|
isDownloadLikeUrl(normalizedFile?.url) ||
|
|
379
373
|
isDownloadLikeUrl(normalizedFile?.path);
|
|
374
|
+
const rawUrl = normalizedFile.url || normalizedFile.path || normalizedFile.uri;
|
|
375
|
+
// Relative backend paths belong to API_ENTRYPOINT. File.domain selects the
|
|
376
|
+
// route's tenant segment, not a new server origin.
|
|
380
377
|
const uriBase =
|
|
381
|
-
directUrl ||
|
|
378
|
+
(isDownloadLikeUrl(rawUrl) ? rawUrl : directUrl) ||
|
|
382
379
|
(fileId ? buildBackendDownloadUrl(fileId, {company, appDomain}) : '');
|
|
383
380
|
|
|
384
381
|
if (!uriBase) {
|
|
@@ -14,6 +14,28 @@ const {
|
|
|
14
14
|
} = require('../../../react/utils/fileUrl');
|
|
15
15
|
|
|
16
16
|
describe('fileUrl helpers', () => {
|
|
17
|
+
it.each([
|
|
18
|
+
'staging.controleonline.com', 'dev.controleonline.com',
|
|
19
|
+
'admin.controleonline.com', 'manager.controleonline.com',
|
|
20
|
+
'pos.lave-go.com', 'shop.lave-go.com', 'delivery.controleonline.com',
|
|
21
|
+
'crm.controleonline.com', 'ppc.controleonline.com', 'service.controleonline.com',
|
|
22
|
+
'localhost:8081',
|
|
23
|
+
])('resolves shared file shapes on the application route for %s', appDomain => {
|
|
24
|
+
for (const file of [6042, '/files/6042', '/files/6042/download',
|
|
25
|
+
{id: 6042, domain: 'api.controleonline.com', url: '/api.controleonline.com/files/6042/download'},
|
|
26
|
+
{file: {id: 6042, url: '/files/6042/download'}}]) {
|
|
27
|
+
const source = resolveDefaultFileSource(file, {appDomain, headers: {'API-TOKEN': 'session'}});
|
|
28
|
+
expect(source.uri).toBe(`https://api.controleonline.com/${encodeURIComponent(appDomain)}/files/6042/download`);
|
|
29
|
+
expect(source.headers).toEqual({'API-TOKEN': 'session', 'app-domain': appDomain});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('preserves URL parameters and fragments while replacing an infrastructure prefix', () => {
|
|
34
|
+
expect(resolveFileImageUrl('/api.controleonline.com/files/6042/download?size=48&app-domain=old#image', {
|
|
35
|
+
appDomain: 'staging.controleonline.com',
|
|
36
|
+
})).toBe('https://api.controleonline.com/staging.controleonline.com/files/6042/download?size=48#image');
|
|
37
|
+
});
|
|
38
|
+
|
|
17
39
|
it('uses path app-domain for backend download urls and keeps headers', () => {
|
|
18
40
|
const company = {
|
|
19
41
|
domain: 'maincompany.controleonline.com',
|
|
@@ -108,6 +130,7 @@ describe('file authentication origin boundary', () => {
|
|
|
108
130
|
expect(source.headers).not.toHaveProperty('Authorization');
|
|
109
131
|
expect(source.headers).not.toHaveProperty('App-Domain');
|
|
110
132
|
expect(source.headers.Accept).toBe('image/*');
|
|
133
|
+
expect(source.uri).toBe(uri);
|
|
111
134
|
}
|
|
112
135
|
});
|
|
113
136
|
it('preserves authentication on the configured API download', () => {
|