@controleonline/ui-common 1.2.105 → 1.2.107
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
CHANGED
|
@@ -0,0 +1,366 @@
|
|
|
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
|
+
if (Platform.OS === 'web' && typeof window !== 'undefined') {
|
|
189
|
+
window.location.assign(authorizationUrl);
|
|
190
|
+
} else {
|
|
191
|
+
await Linking.openURL(authorizationUrl);
|
|
192
|
+
}
|
|
193
|
+
} catch (error) {
|
|
194
|
+
showError(formatApiError(error));
|
|
195
|
+
} finally {
|
|
196
|
+
setAuthorizing(false);
|
|
197
|
+
}
|
|
198
|
+
}, [providerId, showError, status?.client_configured]);
|
|
199
|
+
|
|
200
|
+
const disconnectLinkedIn = useCallback(async () => {
|
|
201
|
+
if (!providerId) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
setDisconnecting(true);
|
|
206
|
+
try {
|
|
207
|
+
await api.fetch('/integrations/linkedin/disconnect', {
|
|
208
|
+
method: 'POST',
|
|
209
|
+
body: {
|
|
210
|
+
provider_id: providerId,
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
showSuccess(
|
|
214
|
+
tt('marketplace_message', 'linkedinDisconnected') ||
|
|
215
|
+
'LinkedIn desconectado.',
|
|
216
|
+
);
|
|
217
|
+
await loadPageData({showLoading: false});
|
|
218
|
+
} catch (error) {
|
|
219
|
+
showError(formatApiError(error));
|
|
220
|
+
} finally {
|
|
221
|
+
setDisconnecting(false);
|
|
222
|
+
}
|
|
223
|
+
}, [loadPageData, providerId, showError, showSuccess]);
|
|
224
|
+
|
|
225
|
+
if (!providerId) {
|
|
226
|
+
return (
|
|
227
|
+
<SafeAreaView style={styles.container} edges={['bottom']}>
|
|
228
|
+
<View style={styles.centerState}>
|
|
229
|
+
<Icon name="building" size={32} color={PROVIDER.accent} />
|
|
230
|
+
<Text style={styles.centerStateTitle}>
|
|
231
|
+
{tt('integrations_title', 'selectCompany') || 'Selecione uma empresa'}
|
|
232
|
+
</Text>
|
|
233
|
+
</View>
|
|
234
|
+
</SafeAreaView>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (loading) {
|
|
239
|
+
return (
|
|
240
|
+
<SafeAreaView
|
|
241
|
+
style={[styles.container, {backgroundColor: brandColors.background}]}
|
|
242
|
+
edges={['bottom']}>
|
|
243
|
+
<View style={styles.centerState}>
|
|
244
|
+
<ActivityIndicator size="large" color={brandColors.primary} />
|
|
245
|
+
<Text style={styles.centerStateTitle}>
|
|
246
|
+
{tt('marketplace_title', 'loadingLinkedIn') || 'Carregando LinkedIn'}
|
|
247
|
+
</Text>
|
|
248
|
+
</View>
|
|
249
|
+
</SafeAreaView>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const connected = isConnected(status?.connected);
|
|
254
|
+
const oauthClientConfigured = status?.client_configured !== false;
|
|
255
|
+
const statusTone = connected ? '#16A34A' : '#e67e22';
|
|
256
|
+
const memberLabel = status?.member_name || status?.member_id || null;
|
|
257
|
+
|
|
258
|
+
return (
|
|
259
|
+
<SafeAreaView
|
|
260
|
+
style={[styles.container, {backgroundColor: brandColors.background}]}
|
|
261
|
+
edges={['bottom']}>
|
|
262
|
+
<ScrollView
|
|
263
|
+
contentContainerStyle={styles.scroll}
|
|
264
|
+
showsVerticalScrollIndicator={false}
|
|
265
|
+
refreshControl={
|
|
266
|
+
<RefreshControl
|
|
267
|
+
refreshing={refreshing}
|
|
268
|
+
onRefresh={onRefresh}
|
|
269
|
+
tintColor={brandColors.primary}
|
|
270
|
+
/>
|
|
271
|
+
}>
|
|
272
|
+
<View style={[styles.statusCard, shadowStyle]}>
|
|
273
|
+
<View style={styles.statusHeader}>
|
|
274
|
+
<View style={styles.statusCopy}>
|
|
275
|
+
<Text style={styles.cardTitle}>
|
|
276
|
+
{tt('marketplace_title', 'status') || 'Status'}
|
|
277
|
+
</Text>
|
|
278
|
+
<Text style={styles.cardSubtitle}>
|
|
279
|
+
{memberLabel
|
|
280
|
+
? `Conta: ${memberLabel}`
|
|
281
|
+
: tt('marketplace_message', 'connectLinkedInAccount') ||
|
|
282
|
+
'Conecte a conta LinkedIn da empresa ativa.'}
|
|
283
|
+
</Text>
|
|
284
|
+
</View>
|
|
285
|
+
<View
|
|
286
|
+
style={[
|
|
287
|
+
styles.statusBadge,
|
|
288
|
+
{backgroundColor: withOpacity(statusTone, 0.12)},
|
|
289
|
+
]}>
|
|
290
|
+
<Text style={[styles.statusBadgeText, {color: statusTone}]}>
|
|
291
|
+
{connected
|
|
292
|
+
? tt('marketplace_status', 'connected') || 'Conectado'
|
|
293
|
+
: tt('marketplace_status', 'pending') || 'Pendente'}
|
|
294
|
+
</Text>
|
|
295
|
+
</View>
|
|
296
|
+
</View>
|
|
297
|
+
</View>
|
|
298
|
+
|
|
299
|
+
<View style={[styles.formCard, shadowStyle]}>
|
|
300
|
+
<Text style={styles.cardTitle}>
|
|
301
|
+
{tt('marketplace_title', 'linkedinAccount') || 'Conta LinkedIn'}
|
|
302
|
+
</Text>
|
|
303
|
+
<Text style={styles.cardSubtitle}>
|
|
304
|
+
{oauthClientConfigured
|
|
305
|
+
? tt('marketplace_message', 'linkedinOauthFlow') ||
|
|
306
|
+
'O login abre o LinkedIn, autoriza o perfil e retorna para esta tela.'
|
|
307
|
+
: tt('marketplace_message', 'linkedinClientConfigRequired') ||
|
|
308
|
+
'Configure o Client ID e Secret do app LinkedIn nesta empresa para habilitar o login.'}
|
|
309
|
+
</Text>
|
|
310
|
+
|
|
311
|
+
<TouchableOpacity
|
|
312
|
+
style={[
|
|
313
|
+
styles.saveButton,
|
|
314
|
+
{backgroundColor: PROVIDER.button},
|
|
315
|
+
(!oauthClientConfigured || authorizing) && styles.saveButtonDisabled,
|
|
316
|
+
]}
|
|
317
|
+
disabled={!oauthClientConfigured || authorizing}
|
|
318
|
+
activeOpacity={0.9}
|
|
319
|
+
onPress={connectLinkedIn}
|
|
320
|
+
testID="linkedin-connect-button">
|
|
321
|
+
{authorizing ? (
|
|
322
|
+
<ActivityIndicator color="#FFFFFF" />
|
|
323
|
+
) : (
|
|
324
|
+
<Icon name="external-link" size={16} color="#FFFFFF" />
|
|
325
|
+
)}
|
|
326
|
+
<Text style={styles.saveButtonText}>
|
|
327
|
+
{connected
|
|
328
|
+
? tt('marketplace_button', 'reconnectLinkedIn') ||
|
|
329
|
+
'Reconectar LinkedIn'
|
|
330
|
+
: tt('marketplace_button', 'connectLinkedIn') ||
|
|
331
|
+
'Conectar com LinkedIn'}
|
|
332
|
+
</Text>
|
|
333
|
+
</TouchableOpacity>
|
|
334
|
+
|
|
335
|
+
{connected ? (
|
|
336
|
+
<TouchableOpacity
|
|
337
|
+
style={[
|
|
338
|
+
styles.saveButton,
|
|
339
|
+
{
|
|
340
|
+
backgroundColor: '#FFFFFF',
|
|
341
|
+
borderWidth: 1,
|
|
342
|
+
borderColor: '#DC2626',
|
|
343
|
+
marginTop: 12,
|
|
344
|
+
},
|
|
345
|
+
disconnecting && styles.saveButtonDisabled,
|
|
346
|
+
]}
|
|
347
|
+
disabled={disconnecting}
|
|
348
|
+
activeOpacity={0.9}
|
|
349
|
+
onPress={disconnectLinkedIn}
|
|
350
|
+
testID="linkedin-disconnect-button">
|
|
351
|
+
{disconnecting ? (
|
|
352
|
+
<ActivityIndicator color="#DC2626" />
|
|
353
|
+
) : (
|
|
354
|
+
<Icon name="log-out" size={16} color="#DC2626" />
|
|
355
|
+
)}
|
|
356
|
+
<Text style={[styles.saveButtonText, {color: '#DC2626'}]}>
|
|
357
|
+
{tt('marketplace_button', 'disconnectLinkedIn') ||
|
|
358
|
+
'Desconectar LinkedIn'}
|
|
359
|
+
</Text>
|
|
360
|
+
</TouchableOpacity>
|
|
361
|
+
) : null}
|
|
362
|
+
</View>
|
|
363
|
+
</ScrollView>
|
|
364
|
+
</SafeAreaView>
|
|
365
|
+
);
|
|
366
|
+
}
|
|
@@ -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
|
+
};
|