@controleonline/ui-common 1.2.109 → 1.2.110
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/components/CategoryForm.js +539 -539
- package/src/react/components/DefaultProvider.native.js +2 -2
- package/src/react/components/DefaultProvider.web.js +2 -2
- package/src/react/components/integrations/IntegrationHero/index.js +1 -1
- package/src/react/components/integrations/IntegrationHero/styles.js +2 -2
- package/src/react/components/integrations/IntegrationTabs/index.js +1 -1
- package/src/react/components/integrations/IntegrationTabs/styles.js +1 -1
- package/src/react/pages/Connections.js +2 -2
- package/src/react/pages/Connections.styles.js +72 -72
- package/src/react/pages/Devices/detail/DeviceDetailHeader.js +1 -1
- package/src/react/pages/Devices/detail/DeviceDetailMovementSections.js +1 -1
- package/src/react/pages/Devices/detail/useDeviceDetailStateA.js +2 -2
- package/src/react/pages/Devices/detail/useDeviceDetailStateB.js +2 -2
- package/src/react/pages/Devices/deviceTypes/DeviceGroupCard.js +1 -1
- package/src/react/pages/Devices/deviceTypes/shared.js +2 -2
- package/src/react/pages/Devices.js +2 -2
- package/src/react/pages/Devices.styles.js +353 -353
- package/src/react/pages/Food99IntegrationPage/components/Food99CatalogTab.js +219 -219
- package/src/react/pages/Food99IntegrationPage/components/Food99OverviewTab.js +134 -134
- package/src/react/pages/Food99IntegrationPage/components/Food99PreviewModal.js +173 -173
- package/src/react/pages/Food99IntegrationPage/components/Food99QuickWalletModal.js +1 -1
- package/src/react/pages/Food99IntegrationPage/components/Food99SettingsTab.js +306 -306
- package/src/react/pages/Food99IntegrationPage/components/Food99StoreTab.js +417 -417
- package/src/react/pages/Food99IntegrationPage/index.js +1530 -1530
- package/src/react/pages/Food99IntegrationPage/styles.js +792 -792
- package/src/react/pages/IFoodIntegrationPage/components/IFoodOperationsTab.js +267 -267
- package/src/react/pages/IFoodIntegrationPage/components/IFoodOverviewTab.js +118 -118
- package/src/react/pages/IFoodIntegrationPage/components/IFoodPreviewModal.js +101 -101
- package/src/react/pages/IFoodIntegrationPage/components/IFoodStoreTab.js +150 -150
- package/src/react/pages/IFoodIntegrationPage/index.js +1298 -1298
- package/src/react/pages/Imports.js +1 -1
- package/src/react/pages/Imports.styles.js +223 -223
- package/src/react/pages/IntegrationConfigPage.js +2 -2
- package/src/react/pages/Integrations.js +299 -299
- package/src/react/pages/Integrations.styles.js +130 -130
- package/src/react/pages/LinkedInIntegrationPage.js +2 -2
- package/src/react/pages/ManagerOrderNotificationsPage.js +642 -642
- package/src/react/pages/MarketplaceIntegrationPage/components/MarketplaceProductCard.js +205 -205
- package/src/react/pages/MercadoLivreIntegrationPage.js +2 -2
- package/src/react/pages/PrinterDeviceDetailPage.js +1915 -1915
- package/src/react/pages/PrinterDeviceFormPage.js +2 -2
- package/src/react/pages/WhatsAppConnectionPage.js +2 -2
- package/src/react/pages/WhatsAppConnectionPage.styles.js +8 -5
- package/src/react/pages/WhatsAppProviderForm.js +1 -1
- package/src/react/utils/fileUrl.js +1 -1
|
@@ -1,299 +1,299 @@
|
|
|
1
|
-
import React, {useCallback, useMemo, useState} from 'react';
|
|
2
|
-
import {
|
|
3
|
-
ActivityIndicator,
|
|
4
|
-
Image,
|
|
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
|
|
20
|
-
import {
|
|
21
|
-
resolveThemePalette,
|
|
22
|
-
withOpacity,
|
|
23
|
-
} from '@controleonline
|
|
24
|
-
|
|
25
|
-
import {
|
|
26
|
-
INTEGRATION_LIST,
|
|
27
|
-
parseIntegrationCollection,
|
|
28
|
-
} from './integrationsCatalog';
|
|
29
|
-
import { createStyles } from './Integrations.styles';
|
|
30
|
-
|
|
31
|
-
const tt = (type, key) => global.t?.t('configs', type, key);
|
|
32
|
-
|
|
33
|
-
const resolveIntegrationColors = brandColors => ({
|
|
34
|
-
...brandColors,
|
|
35
|
-
background: brandColors.background || '#F8FAFC',
|
|
36
|
-
cardBackground: brandColors.cardBackground || brandColors.surface || '#FFFFFF',
|
|
37
|
-
cardBorder: brandColors.cardBorder || brandColors.border || '#E2E8F0',
|
|
38
|
-
cardIconBackground: brandColors.cardIconBackground || brandColors.iconBackground || '#EEF2FF',
|
|
39
|
-
cardIconColor: brandColors.cardIconColor || brandColors.iconColor || '#0F172A',
|
|
40
|
-
cardText: brandColors.cardText || brandColors.textPrimary || brandColors.text || '#0F172A',
|
|
41
|
-
text: brandColors.textPrimary || brandColors.text || '#0F172A',
|
|
42
|
-
mutedText: brandColors.textMuted || brandColors.textSecondary || '#64748B',
|
|
43
|
-
badgeBackground: brandColors.badgeBackground || brandColors.buttonBackgroundSecondary || '#F8FAFC',
|
|
44
|
-
badgeBorder: brandColors.badgeBorder || brandColors.buttonBorderSecondary || '#E2E8F0',
|
|
45
|
-
badgeText: brandColors.badgeText || brandColors.textSecondary || '#64748B',
|
|
46
|
-
badgeSelectedBackground: brandColors.badgeSelectedBackground || brandColors.buttonBackground || '#EFF6FF',
|
|
47
|
-
badgeSelectedBorder: brandColors.badgeSelectedBorder || brandColors.buttonBorder || '#BFDBFE',
|
|
48
|
-
badgeSelectedText: brandColors.badgeSelectedText || brandColors.buttonText || '#0F172A',
|
|
49
|
-
textSuccess: brandColors.textSuccess || '#16A34A',
|
|
50
|
-
textWarning: brandColors.textWarning || '#B45309',
|
|
51
|
-
iconColor: brandColors.iconColor || brandColors.text || '#0F172A',
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const formatApiError = error => {
|
|
55
|
-
if (!error) return tt('integrations_error', 'load') || 'Nao foi possivel carregar as integracoes.';
|
|
56
|
-
if (typeof error === 'string') return error;
|
|
57
|
-
return (
|
|
58
|
-
error?.message ||
|
|
59
|
-
error?.description ||
|
|
60
|
-
error?.errmsg ||
|
|
61
|
-
tt('integrations_error', 'load') ||
|
|
62
|
-
'Nao foi possivel carregar as integracoes.'
|
|
63
|
-
);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const isConnectedValue = value =>
|
|
67
|
-
value === true ||
|
|
68
|
-
value === 1 ||
|
|
69
|
-
value === '1' ||
|
|
70
|
-
String(value).trim().toLowerCase() === 'true';
|
|
71
|
-
|
|
72
|
-
const renderIntegrationIcon = (integration, resolvedStyles, iconColor) => {
|
|
73
|
-
if (integration.logo) {
|
|
74
|
-
return (
|
|
75
|
-
<Image
|
|
76
|
-
source={integration.logo}
|
|
77
|
-
style={resolvedStyles.integrationLogo}
|
|
78
|
-
resizeMode="contain"
|
|
79
|
-
/>
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<Icon
|
|
85
|
-
name={integration.icon || 'box'}
|
|
86
|
-
size={20}
|
|
87
|
-
color={iconColor}
|
|
88
|
-
/>
|
|
89
|
-
);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export default function IntegrationsPage({navigation}) {
|
|
93
|
-
const peopleStore = useStore('people');
|
|
94
|
-
const themeStore = useStore('theme');
|
|
95
|
-
const {currentCompany} = peopleStore.getters;
|
|
96
|
-
const {colors: themeColors} = themeStore.getters;
|
|
97
|
-
const {showError, showInfo} = useToastMessage();
|
|
98
|
-
|
|
99
|
-
const brandColors = useMemo(
|
|
100
|
-
() =>
|
|
101
|
-
resolveThemePalette(
|
|
102
|
-
{
|
|
103
|
-
...themeColors,
|
|
104
|
-
...(currentCompany?.theme?.colors || {}),
|
|
105
|
-
},
|
|
106
|
-
colors,
|
|
107
|
-
),
|
|
108
|
-
[themeColors, currentCompany?.id],
|
|
109
|
-
);
|
|
110
|
-
const integrationColors = useMemo(
|
|
111
|
-
() => resolveIntegrationColors(brandColors),
|
|
112
|
-
[brandColors],
|
|
113
|
-
);
|
|
114
|
-
const styles = useMemo(
|
|
115
|
-
() => createStyles(integrationColors),
|
|
116
|
-
[integrationColors],
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
const [loading, setLoading] = useState(true);
|
|
120
|
-
const [refreshing, setRefreshing] = useState(false);
|
|
121
|
-
const [integrationItems, setIntegrationItems] = useState([]);
|
|
122
|
-
|
|
123
|
-
const providerId = currentCompany?.id;
|
|
124
|
-
|
|
125
|
-
const integrationCards = useMemo(() => {
|
|
126
|
-
const responseMap = new Map(
|
|
127
|
-
(integrationItems || []).map(item => [item?.key, item]),
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
return INTEGRATION_LIST.map(item => {
|
|
131
|
-
const responseItem = responseMap.get(item.key);
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
...item,
|
|
135
|
-
connected: isConnectedValue(responseItem?.connected),
|
|
136
|
-
};
|
|
137
|
-
});
|
|
138
|
-
}, [integrationItems]);
|
|
139
|
-
|
|
140
|
-
const loadIntegrations = useCallback(async () => {
|
|
141
|
-
if (!providerId) {
|
|
142
|
-
setLoading(false);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
try {
|
|
147
|
-
const response = await api.fetch('/marketplace/integrations', {
|
|
148
|
-
params: {provider_id: providerId},
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
setIntegrationItems(parseIntegrationCollection(response));
|
|
152
|
-
} catch (error) {
|
|
153
|
-
showError(formatApiError(error));
|
|
154
|
-
setIntegrationItems([]);
|
|
155
|
-
} finally {
|
|
156
|
-
setLoading(false);
|
|
157
|
-
}
|
|
158
|
-
}, [providerId, showError]);
|
|
159
|
-
|
|
160
|
-
useFocusEffect(
|
|
161
|
-
useCallback(() => {
|
|
162
|
-
setLoading(true);
|
|
163
|
-
loadIntegrations();
|
|
164
|
-
}, [loadIntegrations]),
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
const onRefresh = useCallback(async () => {
|
|
168
|
-
setRefreshing(true);
|
|
169
|
-
try {
|
|
170
|
-
await loadIntegrations();
|
|
171
|
-
} finally {
|
|
172
|
-
setRefreshing(false);
|
|
173
|
-
}
|
|
174
|
-
}, [loadIntegrations]);
|
|
175
|
-
|
|
176
|
-
const handleOpenIntegration = useCallback(
|
|
177
|
-
integration => {
|
|
178
|
-
if (!integration.route) {
|
|
179
|
-
showInfo(tt('integrations_text', 'unavailable') || 'Essa integracao ainda nao esta disponivel.');
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
navigation.navigate(integration.route, {
|
|
184
|
-
providerKey: integration.routeParams?.providerKey || integration.key,
|
|
185
|
-
});
|
|
186
|
-
},
|
|
187
|
-
[navigation, showInfo],
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
if (!providerId) {
|
|
191
|
-
return (
|
|
192
|
-
<SafeAreaView style={styles.container} edges={['bottom']}>
|
|
193
|
-
<View style={styles.centerState}>
|
|
194
|
-
<Icon name="building" size={32} color={integrationColors.iconColor} />
|
|
195
|
-
<Text style={styles.centerStateTitle}>{tt('integrations_title', 'selectCompany') || 'Selecione uma empresa'}</Text>
|
|
196
|
-
<Text style={styles.centerStateText}>
|
|
197
|
-
{tt('integrations_text', 'selectCompany') || 'O hub de integracoes depende da empresa ativa.'}
|
|
198
|
-
</Text>
|
|
199
|
-
</View>
|
|
200
|
-
</SafeAreaView>
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (loading) {
|
|
205
|
-
return (
|
|
206
|
-
<SafeAreaView
|
|
207
|
-
style={[styles.container, {backgroundColor: brandColors.background}]}
|
|
208
|
-
edges={['bottom']}>
|
|
209
|
-
<View style={styles.centerState}>
|
|
210
|
-
<ActivityIndicator size="large" color={brandColors.primary} />
|
|
211
|
-
<Text style={styles.centerStateTitle}>{tt('integrations_title', 'loading') || 'Carregando integracoes'}</Text>
|
|
212
|
-
<Text style={styles.centerStateText}>
|
|
213
|
-
{tt('integrations_text', 'loading') || 'Buscando o status de conexao da empresa ativa.'}
|
|
214
|
-
</Text>
|
|
215
|
-
</View>
|
|
216
|
-
</SafeAreaView>
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return (
|
|
221
|
-
<SafeAreaView
|
|
222
|
-
style={[styles.container, {backgroundColor: brandColors.background}]}
|
|
223
|
-
edges={['bottom']}>
|
|
224
|
-
<ScrollView
|
|
225
|
-
contentContainerStyle={styles.scroll}
|
|
226
|
-
showsVerticalScrollIndicator={false}
|
|
227
|
-
refreshControl={
|
|
228
|
-
<RefreshControl
|
|
229
|
-
refreshing={refreshing}
|
|
230
|
-
onRefresh={onRefresh}
|
|
231
|
-
tintColor={brandColors.primary}
|
|
232
|
-
/>
|
|
233
|
-
}>
|
|
234
|
-
<View style={styles.pageHeader}>
|
|
235
|
-
<Text style={styles.pageTitle}>{tt('integrations_title', 'integrations') || 'Integracoes'}</Text>
|
|
236
|
-
<Text style={styles.pageSubtitle}>
|
|
237
|
-
{tt('integrations_text', 'pageSubtitle') ||
|
|
238
|
-
'Toque em uma integracao para abrir a configuracao. O status mostra se a empresa ativa ja tem as credenciais necessarias.'}
|
|
239
|
-
</Text>
|
|
240
|
-
</View>
|
|
241
|
-
|
|
242
|
-
<View style={styles.integrationGrid}>
|
|
243
|
-
{integrationCards.map(integration => {
|
|
244
|
-
const connected = Boolean(integration.connected);
|
|
245
|
-
const statusTone = connected
|
|
246
|
-
? (integrationColors.textSuccess || integrationColors.badgeSelectedText)
|
|
247
|
-
: (integrationColors.textWarning || integrationColors.badgeText);
|
|
248
|
-
const statusText = connected
|
|
249
|
-
? tt('integrations_status', 'connected') || 'Conectado'
|
|
250
|
-
: tt('integrations_status', 'pending') || 'Pendente';
|
|
251
|
-
const statusBackgroundColor = connected
|
|
252
|
-
? (integrationColors.badgeSelectedBackground || withOpacity(statusTone, 0.12))
|
|
253
|
-
: (integrationColors.badgeBackground || withOpacity(statusTone, 0.12));
|
|
254
|
-
const statusBorderColor = connected
|
|
255
|
-
? (integrationColors.badgeSelectedBorder || withOpacity(statusTone, 0.22))
|
|
256
|
-
: (integrationColors.badgeBorder || withOpacity(statusTone, 0.22));
|
|
257
|
-
|
|
258
|
-
return (
|
|
259
|
-
<TouchableOpacity
|
|
260
|
-
key={integration.key}
|
|
261
|
-
style={styles.integrationCard}
|
|
262
|
-
activeOpacity={0.9}
|
|
263
|
-
onPress={() => handleOpenIntegration(integration)}>
|
|
264
|
-
<View style={styles.integrationTopRow}>
|
|
265
|
-
<View style={styles.integrationHeaderLeft}>
|
|
266
|
-
<View style={styles.integrationIconWrap}>
|
|
267
|
-
{renderIntegrationIcon(integration, styles, integrationColors.cardIconColor)}
|
|
268
|
-
</View>
|
|
269
|
-
<Text style={styles.integrationTitle} numberOfLines={1}>
|
|
270
|
-
{integration.label}
|
|
271
|
-
</Text>
|
|
272
|
-
</View>
|
|
273
|
-
|
|
274
|
-
<View
|
|
275
|
-
style={[
|
|
276
|
-
styles.integrationStatus,
|
|
277
|
-
{
|
|
278
|
-
backgroundColor: statusBackgroundColor,
|
|
279
|
-
borderColor: statusBorderColor,
|
|
280
|
-
},
|
|
281
|
-
]}>
|
|
282
|
-
<Text
|
|
283
|
-
style={[
|
|
284
|
-
styles.integrationStatusText,
|
|
285
|
-
{color: statusTone},
|
|
286
|
-
]}>
|
|
287
|
-
{statusText}
|
|
288
|
-
</Text>
|
|
289
|
-
</View>
|
|
290
|
-
</View>
|
|
291
|
-
</TouchableOpacity>
|
|
292
|
-
);
|
|
293
|
-
})}
|
|
294
|
-
</View>
|
|
295
|
-
</ScrollView>
|
|
296
|
-
</SafeAreaView>
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
// TODO(store-first): quando este arquivo for mexido, mover a leitura para stores, remover api.fetch e evitar repassar dados em objetos quando o store ja resolver isso.
|
|
1
|
+
import React, {useCallback, useMemo, useState} from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ActivityIndicator,
|
|
4
|
+
Image,
|
|
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/ui-layout/src/styles/colors';
|
|
20
|
+
import {
|
|
21
|
+
resolveThemePalette,
|
|
22
|
+
withOpacity,
|
|
23
|
+
} from '@controleonline/ui-layout/src/styles/branding';
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
INTEGRATION_LIST,
|
|
27
|
+
parseIntegrationCollection,
|
|
28
|
+
} from './integrationsCatalog';
|
|
29
|
+
import { createStyles } from './Integrations.styles';
|
|
30
|
+
|
|
31
|
+
const tt = (type, key) => global.t?.t('configs', type, key);
|
|
32
|
+
|
|
33
|
+
const resolveIntegrationColors = brandColors => ({
|
|
34
|
+
...brandColors,
|
|
35
|
+
background: brandColors.background || '#F8FAFC',
|
|
36
|
+
cardBackground: brandColors.cardBackground || brandColors.surface || '#FFFFFF',
|
|
37
|
+
cardBorder: brandColors.cardBorder || brandColors.border || '#E2E8F0',
|
|
38
|
+
cardIconBackground: brandColors.cardIconBackground || brandColors.iconBackground || '#EEF2FF',
|
|
39
|
+
cardIconColor: brandColors.cardIconColor || brandColors.iconColor || '#0F172A',
|
|
40
|
+
cardText: brandColors.cardText || brandColors.textPrimary || brandColors.text || '#0F172A',
|
|
41
|
+
text: brandColors.textPrimary || brandColors.text || '#0F172A',
|
|
42
|
+
mutedText: brandColors.textMuted || brandColors.textSecondary || '#64748B',
|
|
43
|
+
badgeBackground: brandColors.badgeBackground || brandColors.buttonBackgroundSecondary || '#F8FAFC',
|
|
44
|
+
badgeBorder: brandColors.badgeBorder || brandColors.buttonBorderSecondary || '#E2E8F0',
|
|
45
|
+
badgeText: brandColors.badgeText || brandColors.textSecondary || '#64748B',
|
|
46
|
+
badgeSelectedBackground: brandColors.badgeSelectedBackground || brandColors.buttonBackground || '#EFF6FF',
|
|
47
|
+
badgeSelectedBorder: brandColors.badgeSelectedBorder || brandColors.buttonBorder || '#BFDBFE',
|
|
48
|
+
badgeSelectedText: brandColors.badgeSelectedText || brandColors.buttonText || '#0F172A',
|
|
49
|
+
textSuccess: brandColors.textSuccess || '#16A34A',
|
|
50
|
+
textWarning: brandColors.textWarning || '#B45309',
|
|
51
|
+
iconColor: brandColors.iconColor || brandColors.text || '#0F172A',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const formatApiError = error => {
|
|
55
|
+
if (!error) return tt('integrations_error', 'load') || 'Nao foi possivel carregar as integracoes.';
|
|
56
|
+
if (typeof error === 'string') return error;
|
|
57
|
+
return (
|
|
58
|
+
error?.message ||
|
|
59
|
+
error?.description ||
|
|
60
|
+
error?.errmsg ||
|
|
61
|
+
tt('integrations_error', 'load') ||
|
|
62
|
+
'Nao foi possivel carregar as integracoes.'
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const isConnectedValue = value =>
|
|
67
|
+
value === true ||
|
|
68
|
+
value === 1 ||
|
|
69
|
+
value === '1' ||
|
|
70
|
+
String(value).trim().toLowerCase() === 'true';
|
|
71
|
+
|
|
72
|
+
const renderIntegrationIcon = (integration, resolvedStyles, iconColor) => {
|
|
73
|
+
if (integration.logo) {
|
|
74
|
+
return (
|
|
75
|
+
<Image
|
|
76
|
+
source={integration.logo}
|
|
77
|
+
style={resolvedStyles.integrationLogo}
|
|
78
|
+
resizeMode="contain"
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<Icon
|
|
85
|
+
name={integration.icon || 'box'}
|
|
86
|
+
size={20}
|
|
87
|
+
color={iconColor}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export default function IntegrationsPage({navigation}) {
|
|
93
|
+
const peopleStore = useStore('people');
|
|
94
|
+
const themeStore = useStore('theme');
|
|
95
|
+
const {currentCompany} = peopleStore.getters;
|
|
96
|
+
const {colors: themeColors} = themeStore.getters;
|
|
97
|
+
const {showError, showInfo} = useToastMessage();
|
|
98
|
+
|
|
99
|
+
const brandColors = useMemo(
|
|
100
|
+
() =>
|
|
101
|
+
resolveThemePalette(
|
|
102
|
+
{
|
|
103
|
+
...themeColors,
|
|
104
|
+
...(currentCompany?.theme?.colors || {}),
|
|
105
|
+
},
|
|
106
|
+
colors,
|
|
107
|
+
),
|
|
108
|
+
[themeColors, currentCompany?.id],
|
|
109
|
+
);
|
|
110
|
+
const integrationColors = useMemo(
|
|
111
|
+
() => resolveIntegrationColors(brandColors),
|
|
112
|
+
[brandColors],
|
|
113
|
+
);
|
|
114
|
+
const styles = useMemo(
|
|
115
|
+
() => createStyles(integrationColors),
|
|
116
|
+
[integrationColors],
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const [loading, setLoading] = useState(true);
|
|
120
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
121
|
+
const [integrationItems, setIntegrationItems] = useState([]);
|
|
122
|
+
|
|
123
|
+
const providerId = currentCompany?.id;
|
|
124
|
+
|
|
125
|
+
const integrationCards = useMemo(() => {
|
|
126
|
+
const responseMap = new Map(
|
|
127
|
+
(integrationItems || []).map(item => [item?.key, item]),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
return INTEGRATION_LIST.map(item => {
|
|
131
|
+
const responseItem = responseMap.get(item.key);
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
...item,
|
|
135
|
+
connected: isConnectedValue(responseItem?.connected),
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
}, [integrationItems]);
|
|
139
|
+
|
|
140
|
+
const loadIntegrations = useCallback(async () => {
|
|
141
|
+
if (!providerId) {
|
|
142
|
+
setLoading(false);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
const response = await api.fetch('/marketplace/integrations', {
|
|
148
|
+
params: {provider_id: providerId},
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
setIntegrationItems(parseIntegrationCollection(response));
|
|
152
|
+
} catch (error) {
|
|
153
|
+
showError(formatApiError(error));
|
|
154
|
+
setIntegrationItems([]);
|
|
155
|
+
} finally {
|
|
156
|
+
setLoading(false);
|
|
157
|
+
}
|
|
158
|
+
}, [providerId, showError]);
|
|
159
|
+
|
|
160
|
+
useFocusEffect(
|
|
161
|
+
useCallback(() => {
|
|
162
|
+
setLoading(true);
|
|
163
|
+
loadIntegrations();
|
|
164
|
+
}, [loadIntegrations]),
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const onRefresh = useCallback(async () => {
|
|
168
|
+
setRefreshing(true);
|
|
169
|
+
try {
|
|
170
|
+
await loadIntegrations();
|
|
171
|
+
} finally {
|
|
172
|
+
setRefreshing(false);
|
|
173
|
+
}
|
|
174
|
+
}, [loadIntegrations]);
|
|
175
|
+
|
|
176
|
+
const handleOpenIntegration = useCallback(
|
|
177
|
+
integration => {
|
|
178
|
+
if (!integration.route) {
|
|
179
|
+
showInfo(tt('integrations_text', 'unavailable') || 'Essa integracao ainda nao esta disponivel.');
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
navigation.navigate(integration.route, {
|
|
184
|
+
providerKey: integration.routeParams?.providerKey || integration.key,
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
[navigation, showInfo],
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
if (!providerId) {
|
|
191
|
+
return (
|
|
192
|
+
<SafeAreaView style={styles.container} edges={['bottom']}>
|
|
193
|
+
<View style={styles.centerState}>
|
|
194
|
+
<Icon name="building" size={32} color={integrationColors.iconColor} />
|
|
195
|
+
<Text style={styles.centerStateTitle}>{tt('integrations_title', 'selectCompany') || 'Selecione uma empresa'}</Text>
|
|
196
|
+
<Text style={styles.centerStateText}>
|
|
197
|
+
{tt('integrations_text', 'selectCompany') || 'O hub de integracoes depende da empresa ativa.'}
|
|
198
|
+
</Text>
|
|
199
|
+
</View>
|
|
200
|
+
</SafeAreaView>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (loading) {
|
|
205
|
+
return (
|
|
206
|
+
<SafeAreaView
|
|
207
|
+
style={[styles.container, {backgroundColor: brandColors.background}]}
|
|
208
|
+
edges={['bottom']}>
|
|
209
|
+
<View style={styles.centerState}>
|
|
210
|
+
<ActivityIndicator size="large" color={brandColors.primary} />
|
|
211
|
+
<Text style={styles.centerStateTitle}>{tt('integrations_title', 'loading') || 'Carregando integracoes'}</Text>
|
|
212
|
+
<Text style={styles.centerStateText}>
|
|
213
|
+
{tt('integrations_text', 'loading') || 'Buscando o status de conexao da empresa ativa.'}
|
|
214
|
+
</Text>
|
|
215
|
+
</View>
|
|
216
|
+
</SafeAreaView>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<SafeAreaView
|
|
222
|
+
style={[styles.container, {backgroundColor: brandColors.background}]}
|
|
223
|
+
edges={['bottom']}>
|
|
224
|
+
<ScrollView
|
|
225
|
+
contentContainerStyle={styles.scroll}
|
|
226
|
+
showsVerticalScrollIndicator={false}
|
|
227
|
+
refreshControl={
|
|
228
|
+
<RefreshControl
|
|
229
|
+
refreshing={refreshing}
|
|
230
|
+
onRefresh={onRefresh}
|
|
231
|
+
tintColor={brandColors.primary}
|
|
232
|
+
/>
|
|
233
|
+
}>
|
|
234
|
+
<View style={styles.pageHeader}>
|
|
235
|
+
<Text style={styles.pageTitle}>{tt('integrations_title', 'integrations') || 'Integracoes'}</Text>
|
|
236
|
+
<Text style={styles.pageSubtitle}>
|
|
237
|
+
{tt('integrations_text', 'pageSubtitle') ||
|
|
238
|
+
'Toque em uma integracao para abrir a configuracao. O status mostra se a empresa ativa ja tem as credenciais necessarias.'}
|
|
239
|
+
</Text>
|
|
240
|
+
</View>
|
|
241
|
+
|
|
242
|
+
<View style={styles.integrationGrid}>
|
|
243
|
+
{integrationCards.map(integration => {
|
|
244
|
+
const connected = Boolean(integration.connected);
|
|
245
|
+
const statusTone = connected
|
|
246
|
+
? (integrationColors.textSuccess || integrationColors.badgeSelectedText)
|
|
247
|
+
: (integrationColors.textWarning || integrationColors.badgeText);
|
|
248
|
+
const statusText = connected
|
|
249
|
+
? tt('integrations_status', 'connected') || 'Conectado'
|
|
250
|
+
: tt('integrations_status', 'pending') || 'Pendente';
|
|
251
|
+
const statusBackgroundColor = connected
|
|
252
|
+
? (integrationColors.badgeSelectedBackground || withOpacity(statusTone, 0.12))
|
|
253
|
+
: (integrationColors.badgeBackground || withOpacity(statusTone, 0.12));
|
|
254
|
+
const statusBorderColor = connected
|
|
255
|
+
? (integrationColors.badgeSelectedBorder || withOpacity(statusTone, 0.22))
|
|
256
|
+
: (integrationColors.badgeBorder || withOpacity(statusTone, 0.22));
|
|
257
|
+
|
|
258
|
+
return (
|
|
259
|
+
<TouchableOpacity
|
|
260
|
+
key={integration.key}
|
|
261
|
+
style={styles.integrationCard}
|
|
262
|
+
activeOpacity={0.9}
|
|
263
|
+
onPress={() => handleOpenIntegration(integration)}>
|
|
264
|
+
<View style={styles.integrationTopRow}>
|
|
265
|
+
<View style={styles.integrationHeaderLeft}>
|
|
266
|
+
<View style={styles.integrationIconWrap}>
|
|
267
|
+
{renderIntegrationIcon(integration, styles, integrationColors.cardIconColor)}
|
|
268
|
+
</View>
|
|
269
|
+
<Text style={styles.integrationTitle} numberOfLines={1}>
|
|
270
|
+
{integration.label}
|
|
271
|
+
</Text>
|
|
272
|
+
</View>
|
|
273
|
+
|
|
274
|
+
<View
|
|
275
|
+
style={[
|
|
276
|
+
styles.integrationStatus,
|
|
277
|
+
{
|
|
278
|
+
backgroundColor: statusBackgroundColor,
|
|
279
|
+
borderColor: statusBorderColor,
|
|
280
|
+
},
|
|
281
|
+
]}>
|
|
282
|
+
<Text
|
|
283
|
+
style={[
|
|
284
|
+
styles.integrationStatusText,
|
|
285
|
+
{color: statusTone},
|
|
286
|
+
]}>
|
|
287
|
+
{statusText}
|
|
288
|
+
</Text>
|
|
289
|
+
</View>
|
|
290
|
+
</View>
|
|
291
|
+
</TouchableOpacity>
|
|
292
|
+
);
|
|
293
|
+
})}
|
|
294
|
+
</View>
|
|
295
|
+
</ScrollView>
|
|
296
|
+
</SafeAreaView>
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
// TODO(store-first): quando este arquivo for mexido, mover a leitura para stores, remover api.fetch e evitar repassar dados em objetos quando o store ja resolver isso.
|