@controleonline/ui-common 1.2.125 → 1.2.127
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/.release/rc-manifest.json +7 -6
- package/package.json +1 -1
- package/src/react/components/BottomNavigationBar.js +1 -1
- package/src/react/components/ManagerPushBridge.native.js +32 -5
- package/src/react/components/RuntimeInfoFooter.js +3 -3
- package/src/react/pages/Connections.js +33 -1
- package/src/react/pages/EmailConnectionModal.js +120 -0
- package/src/react/pages/WhatsAppConnectionPage.js +31 -2
- package/src/react/utils/runtimeFooter.js +27 -6
- package/src/store/connections/customActions.js +40 -0
- package/src/tests/react/utils/runtimeFooter.test.js +14 -6
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.
|
|
2
|
+
"version": "1.2.127",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.2.
|
|
5
|
-
"baseMaster": "
|
|
4
|
+
"branch": "rc/1.2.127-rc.1",
|
|
5
|
+
"baseMaster": "15fe9362ec2cdc6f98c1eefc6241ff1ed682aa28",
|
|
6
6
|
"tasks": [
|
|
7
|
-
|
|
7
|
+
142,
|
|
8
|
+
145
|
|
8
9
|
],
|
|
9
10
|
"frozen": true,
|
|
10
11
|
"repositories": {
|
|
11
|
-
"ControleOnline/ui-common": "
|
|
12
|
+
"ControleOnline/ui-common": "3751b577d7b45b8311948c9e67adf207c2e8cbf5"
|
|
12
13
|
}
|
|
13
|
-
}
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -125,7 +125,7 @@ const BottomNavigationBar = ({
|
|
|
125
125
|
appearance,
|
|
126
126
|
appVersion: runtimeFooter?.appVersion,
|
|
127
127
|
colors: appearance === 'soft'
|
|
128
|
-
? {...runtimeFooter?.colors, footerBackground: colors.footerBackground,
|
|
128
|
+
? {...runtimeFooter?.colors, footerBackground: colors.footerBackground, footerText: colors.footerText}
|
|
129
129
|
: runtimeFooter?.colors || {},
|
|
130
130
|
mainCompany: runtimeFooter?.mainCompany,
|
|
131
131
|
device: runtimeFooter?.device,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
|
|
2
2
|
import {Platform} from 'react-native';
|
|
3
3
|
import * as Notifications from 'expo-notifications';
|
|
4
|
-
import {app_type} from '@appType';
|
|
4
|
+
import {app_type} from '@appType';
|
|
5
5
|
import {useStore} from '@store';
|
|
6
6
|
import {
|
|
7
7
|
ensureManagerOrderNotificationPermission,
|
|
@@ -39,7 +39,16 @@ const resolvePersistableDeviceEntityId = deviceInfo =>
|
|
|
39
39
|
normalizeText(deviceInfo?.entityId || deviceInfo?.apiId || deviceInfo?.['@id'])
|
|
40
40
|
.replace(/\D+/g, '');
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
// Requests push (app-community#1598) target a person: the signed-in person is stored with the token.
|
|
43
|
+
const peopleIdOf = user =>
|
|
44
|
+
normalizeText(user?.people?.['@id'] || user?.people?.id || user?.people || '').replace(/\D+/g, '');
|
|
45
|
+
|
|
46
|
+
const extractTaskIdFromResponse = response => {
|
|
47
|
+
const data = response?.notification?.request?.content?.data || {};
|
|
48
|
+
return normalizeText(data?.taskId || data?.task_id || '').replace(/\D+/g, '');
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const mergeManagerPushTokenMetadata = (metadata, deviceToken, peopleId = '') => {
|
|
43
52
|
const normalizedMetadata = isPlainObject(metadata) ? metadata : {};
|
|
44
53
|
const nextMetadata = {
|
|
45
54
|
...normalizedMetadata,
|
|
@@ -57,6 +66,11 @@ const mergeManagerPushTokenMetadata = (metadata, deviceToken) => {
|
|
|
57
66
|
|
|
58
67
|
if (normalizeText(deviceToken)) {
|
|
59
68
|
androidTokens.deviceToken = normalizeText(deviceToken);
|
|
69
|
+
if (peopleId) {
|
|
70
|
+
androidTokens.peopleId = Number(peopleId);
|
|
71
|
+
} else {
|
|
72
|
+
delete androidTokens.peopleId;
|
|
73
|
+
}
|
|
60
74
|
managerTokens.android = androidTokens;
|
|
61
75
|
pushTokens.manager = managerTokens;
|
|
62
76
|
nextMetadata.pushTokens = pushTokens;
|
|
@@ -64,6 +78,7 @@ const mergeManagerPushTokenMetadata = (metadata, deviceToken) => {
|
|
|
64
78
|
}
|
|
65
79
|
|
|
66
80
|
delete androidTokens.deviceToken;
|
|
81
|
+
delete androidTokens.peopleId;
|
|
67
82
|
if (Object.keys(androidTokens).length > 0) {
|
|
68
83
|
managerTokens.android = androidTokens;
|
|
69
84
|
} else {
|
|
@@ -93,7 +108,9 @@ const ManagerPushBridge = ({device, setDevice}) => {
|
|
|
93
108
|
const deviceActions = deviceStore.actions;
|
|
94
109
|
|
|
95
110
|
const {isLogged, sessionChecked, user} = authGetters;
|
|
96
|
-
|
|
111
|
+
// Manager and CRM receive order/request pushes.
|
|
112
|
+
const isManagerRuntime = isManagerAppType(app_type) || String(app_type || '').toUpperCase() === 'CRM';
|
|
113
|
+
const peopleId = peopleIdOf(user);
|
|
97
114
|
const pushPreferences = useMemo(
|
|
98
115
|
() => resolveManagerOrderNotificationPreferences(user),
|
|
99
116
|
[user],
|
|
@@ -135,11 +152,15 @@ const ManagerPushBridge = ({device, setDevice}) => {
|
|
|
135
152
|
|
|
136
153
|
const normalizedToken = normalizeText(deviceToken);
|
|
137
154
|
const currentToken = extractManagerPushToken(currentDevice?.metadata);
|
|
155
|
+
const currentPeopleId = normalizeText(
|
|
156
|
+
currentDevice?.metadata?.pushTokens?.manager?.android?.peopleId || '',
|
|
157
|
+
);
|
|
138
158
|
|
|
139
159
|
if (
|
|
140
160
|
!persistImmediately &&
|
|
141
161
|
normalizedToken &&
|
|
142
|
-
currentToken === normalizedToken
|
|
162
|
+
currentToken === normalizedToken &&
|
|
163
|
+
currentPeopleId === peopleId
|
|
143
164
|
) {
|
|
144
165
|
return true;
|
|
145
166
|
}
|
|
@@ -155,6 +176,7 @@ const ManagerPushBridge = ({device, setDevice}) => {
|
|
|
155
176
|
const nextMetadata = mergeManagerPushTokenMetadata(
|
|
156
177
|
currentDevice?.metadata,
|
|
157
178
|
normalizedToken,
|
|
179
|
+
peopleId,
|
|
158
180
|
);
|
|
159
181
|
const nextDevice = {
|
|
160
182
|
...currentDevice,
|
|
@@ -185,7 +207,7 @@ const ManagerPushBridge = ({device, setDevice}) => {
|
|
|
185
207
|
|
|
186
208
|
return true;
|
|
187
209
|
},
|
|
188
|
-
[deviceActions, persistLocalDevice],
|
|
210
|
+
[deviceActions, persistLocalDevice, peopleId],
|
|
189
211
|
);
|
|
190
212
|
|
|
191
213
|
useEffect(() => {
|
|
@@ -286,6 +308,11 @@ const ManagerPushBridge = ({device, setDevice}) => {
|
|
|
286
308
|
if (!notificationResponseListenerRef.current) {
|
|
287
309
|
notificationResponseListenerRef.current =
|
|
288
310
|
Notifications.addNotificationResponseReceivedListener(response => {
|
|
311
|
+
const taskId = extractTaskIdFromResponse(response);
|
|
312
|
+
if (taskId) {
|
|
313
|
+
queueNotificationNavigation('TicketConversation', {taskId});
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
289
316
|
const orderId = extractOrderIdFromResponse(response);
|
|
290
317
|
if (!orderId) {
|
|
291
318
|
return;
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
parseConfigsObject,
|
|
15
15
|
} from '@controleonline/ui-common/src/react/config/deviceConfigBootstrap';
|
|
16
16
|
import {
|
|
17
|
+
formatRuntimeFooterIdentifier,
|
|
17
18
|
getRuntimeFooterDebugInfo,
|
|
18
19
|
getRuntimeFooterPrimaryText,
|
|
19
20
|
getRuntimeFooterRotationEntries,
|
|
@@ -38,7 +39,6 @@ const normalizeColor = value =>
|
|
|
38
39
|
/** Prefer theme colors, but never render text the same as the footer background. */
|
|
39
40
|
const resolveVisibleFooterTextColor = colors => {
|
|
40
41
|
const candidates = [
|
|
41
|
-
colors?.footerLabelInfo,
|
|
42
42
|
colors?.footerText,
|
|
43
43
|
colors?.textSecondary,
|
|
44
44
|
colors?.text,
|
|
@@ -259,7 +259,7 @@ const RuntimeInfoFooter = ({
|
|
|
259
259
|
shouldRotate
|
|
260
260
|
? rotationEntries[activeIndex]
|
|
261
261
|
: inlineText
|
|
262
|
-
) || primaryText || device?.id || '';
|
|
262
|
+
) || primaryText || formatRuntimeFooterIdentifier(device?.id) || '';
|
|
263
263
|
const backgroundColor = colors?.footerBackground;
|
|
264
264
|
const homeSpacing = resolveHomeFooterSpacing(appearance, Platform.OS, insets.bottom);
|
|
265
265
|
const borderColor = colors?.footerBorder;
|
|
@@ -300,7 +300,7 @@ const RuntimeInfoFooter = ({
|
|
|
300
300
|
<RuntimeFooterMarqueeText
|
|
301
301
|
text={
|
|
302
302
|
showDebugInfo
|
|
303
|
-
? inlineText || primaryText || device?.id || '--'
|
|
303
|
+
? inlineText || primaryText || formatRuntimeFooterIdentifier(device?.id) || '--'
|
|
304
304
|
: displayedText
|
|
305
305
|
}
|
|
306
306
|
color={textColor}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useMemo } from 'react';
|
|
1
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
2
2
|
import { Platform, Text, TouchableOpacity, View } from 'react-native';
|
|
3
3
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
4
4
|
import { useFocusEffect, useNavigation } from '@react-navigation/native';
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
withOpacity,
|
|
13
13
|
} from '@controleonline/../../src/styles/branding';
|
|
14
14
|
import DefaultTable from '@controleonline/ui-default/src/react/components/table/DefaultTable';
|
|
15
|
+
import EmailConnectionModal from './EmailConnectionModal';
|
|
15
16
|
|
|
16
17
|
const tt = (type, key) => global.t?.t('configs', type, key);
|
|
17
18
|
|
|
@@ -96,6 +97,8 @@ export default function Connections() {
|
|
|
96
97
|
}, [peopleIri]),
|
|
97
98
|
);
|
|
98
99
|
|
|
100
|
+
const [emailModalVisible, setEmailModalVisible] = useState(false);
|
|
101
|
+
|
|
99
102
|
const openWhatsAppChannel = useCallback(() => {
|
|
100
103
|
navigation.navigate('WhatsAppConnectionPage');
|
|
101
104
|
}, [navigation]);
|
|
@@ -198,6 +201,35 @@ export default function Connections() {
|
|
|
198
201
|
</View>
|
|
199
202
|
</TouchableOpacity>
|
|
200
203
|
|
|
204
|
+
<TouchableOpacity
|
|
205
|
+
activeOpacity={0.92}
|
|
206
|
+
onPress={() => setEmailModalVisible(true)}
|
|
207
|
+
style={[styles.channelCard, shadowStyle]}>
|
|
208
|
+
<View style={styles.channelTopRow}>
|
|
209
|
+
<View style={[styles.channelIconWrap, { backgroundColor: withOpacity(brandColors.primary, 0.12) }]}>
|
|
210
|
+
<Icon name="mail" size={20} color={brandColors.primary} />
|
|
211
|
+
</View>
|
|
212
|
+
</View>
|
|
213
|
+
<Text style={styles.channelTitle}>E-mail</Text>
|
|
214
|
+
<Text style={styles.channelDescription}>
|
|
215
|
+
Conecte a caixa de atendimento (IMAP/SMTP): e-mails viram conversas e as respostas saem por ela.
|
|
216
|
+
</Text>
|
|
217
|
+
<View style={styles.actionRow}>
|
|
218
|
+
<Text style={styles.actionText}>Conectar e-mail</Text>
|
|
219
|
+
<Icon name="arrow-right" size={18} color={brandColors.primary} />
|
|
220
|
+
</View>
|
|
221
|
+
</TouchableOpacity>
|
|
222
|
+
|
|
223
|
+
<EmailConnectionModal
|
|
224
|
+
visible={emailModalVisible}
|
|
225
|
+
peopleIri={peopleIri}
|
|
226
|
+
onClose={() => setEmailModalVisible(false)}
|
|
227
|
+
onSaved={() => {
|
|
228
|
+
setEmailModalVisible(false);
|
|
229
|
+
connectionsStore.actions?.getItems?.({ people: peopleIri });
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
|
|
201
233
|
<View style={{ flex: 1, marginTop: 12 }}>
|
|
202
234
|
<DefaultTable
|
|
203
235
|
storeName="connections"
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents E-mail connection (connections.channel = email): IMAP to read customer e-mails and SMTP to
|
|
3
|
+
* answer them. Credentials go to channel_config (write-only on the API; never read back).
|
|
4
|
+
* Inbound polling runs with the `email:fetch` cron job (api-platform-integration).
|
|
5
|
+
*/
|
|
6
|
+
import React, {useState} from 'react';
|
|
7
|
+
import {ActivityIndicator, Modal, ScrollView, Text, TextInput, TouchableOpacity, View} from 'react-native';
|
|
8
|
+
import {useStore} from '@store';
|
|
9
|
+
|
|
10
|
+
const FIELDS = [
|
|
11
|
+
['name', 'Nome da conexão', 'Atendimento por e-mail'],
|
|
12
|
+
['from_address', 'E-mail de atendimento', 'atendimento@empresa.com.br'],
|
|
13
|
+
['from_name', 'Nome do remetente', 'Equipe Empresa'],
|
|
14
|
+
['username', 'Usuário (login)', 'atendimento@empresa.com.br'],
|
|
15
|
+
['password', 'Senha / senha de app', ''],
|
|
16
|
+
['imap_host', 'Servidor IMAP', 'imap.gmail.com'],
|
|
17
|
+
['imap_port', 'Porta IMAP', '993'],
|
|
18
|
+
['smtp_host', 'Servidor SMTP', 'smtp.gmail.com'],
|
|
19
|
+
['smtp_port', 'Porta SMTP', '587'],
|
|
20
|
+
];
|
|
21
|
+
const TYPES = [
|
|
22
|
+
['support', 'Suporte'],
|
|
23
|
+
['relationship', 'Comercial'],
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
export default function EmailConnectionModal({visible, peopleIri, onClose, onSaved}) {
|
|
27
|
+
const connectionsStore = useStore('connections');
|
|
28
|
+
const [form, setForm] = useState({imap_port: '993', smtp_port: '587', type: 'support'});
|
|
29
|
+
const [saving, setSaving] = useState(false);
|
|
30
|
+
const [error, setError] = useState('');
|
|
31
|
+
const set = key => value => setForm(prev => ({...prev, [key]: value}));
|
|
32
|
+
|
|
33
|
+
const save = async () => {
|
|
34
|
+
const required = ['from_address', 'username', 'password', 'imap_host', 'smtp_host'];
|
|
35
|
+
if (required.some(k => !String(form[k] || '').trim())) {
|
|
36
|
+
setError('Preencha e-mail, usuário, senha, IMAP e SMTP.');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
setSaving(true);
|
|
40
|
+
setError('');
|
|
41
|
+
try {
|
|
42
|
+
await connectionsStore.actions.saveEmailConnection({...form, people: peopleIri});
|
|
43
|
+
setForm({imap_port: '993', smtp_port: '587', type: 'support'});
|
|
44
|
+
onSaved?.();
|
|
45
|
+
} catch (e) {
|
|
46
|
+
setError(e?.message || 'Não foi possível salvar a conexão.');
|
|
47
|
+
} finally {
|
|
48
|
+
setSaving(false);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Modal visible={visible} transparent animationType="fade" onRequestClose={onClose}>
|
|
54
|
+
<View style={s.backdrop}>
|
|
55
|
+
<View style={s.card}>
|
|
56
|
+
<Text style={s.title}>Conexão de e-mail</Text>
|
|
57
|
+
<Text style={s.text}>
|
|
58
|
+
E-mails recebidos viram conversas: a IA atende (se configurada) e a equipe responde pelo CRM ou Suporte.
|
|
59
|
+
As respostas saem por este endereço.
|
|
60
|
+
</Text>
|
|
61
|
+
<ScrollView style={s.scroll}>
|
|
62
|
+
<View style={s.typeRow}>
|
|
63
|
+
{TYPES.map(([value, label]) => (
|
|
64
|
+
<TouchableOpacity key={value} onPress={() => set('type')(value)} style={[s.chip, form.type === value && s.chipActive]}>
|
|
65
|
+
<Text style={[s.chipText, form.type === value && s.chipTextActive]}>{label}</Text>
|
|
66
|
+
</TouchableOpacity>
|
|
67
|
+
))}
|
|
68
|
+
</View>
|
|
69
|
+
{FIELDS.map(([key, label, placeholder]) => (
|
|
70
|
+
<View key={key} style={s.field}>
|
|
71
|
+
<Text style={s.label}>{label}</Text>
|
|
72
|
+
<TextInput
|
|
73
|
+
style={s.input}
|
|
74
|
+
value={String(form[key] || '')}
|
|
75
|
+
onChangeText={set(key)}
|
|
76
|
+
placeholder={placeholder}
|
|
77
|
+
placeholderTextColor="#94A3B8"
|
|
78
|
+
secureTextEntry={key === 'password'}
|
|
79
|
+
autoCapitalize="none"
|
|
80
|
+
keyboardType={key.endsWith('port') ? 'number-pad' : 'default'}
|
|
81
|
+
/>
|
|
82
|
+
</View>
|
|
83
|
+
))}
|
|
84
|
+
</ScrollView>
|
|
85
|
+
{error ? <Text style={s.error}>{error}</Text> : null}
|
|
86
|
+
<View style={s.actions}>
|
|
87
|
+
<TouchableOpacity onPress={onClose} style={s.ghost} disabled={saving}>
|
|
88
|
+
<Text style={s.ghostText}>Cancelar</Text>
|
|
89
|
+
</TouchableOpacity>
|
|
90
|
+
<TouchableOpacity onPress={save} style={s.primary} disabled={saving}>
|
|
91
|
+
{saving ? <ActivityIndicator color="#fff" /> : <Text style={s.primaryText}>Salvar</Text>}
|
|
92
|
+
</TouchableOpacity>
|
|
93
|
+
</View>
|
|
94
|
+
</View>
|
|
95
|
+
</View>
|
|
96
|
+
</Modal>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const s = {
|
|
101
|
+
backdrop: {flex: 1, backgroundColor: 'rgba(15,23,42,0.55)', justifyContent: 'center', alignItems: 'center', padding: 16},
|
|
102
|
+
card: {width: '100%', maxWidth: 520, maxHeight: '90%', backgroundColor: '#FFFFFF', borderRadius: 16, padding: 16, gap: 10},
|
|
103
|
+
title: {fontSize: 17, fontWeight: '700', color: '#0F172A'},
|
|
104
|
+
text: {fontSize: 13, color: '#475569', lineHeight: 18},
|
|
105
|
+
scroll: {flexGrow: 0},
|
|
106
|
+
typeRow: {flexDirection: 'row', gap: 8, marginBottom: 8},
|
|
107
|
+
chip: {borderWidth: 1, borderColor: '#CBD5E1', borderRadius: 14, paddingHorizontal: 12, paddingVertical: 6},
|
|
108
|
+
chipActive: {backgroundColor: '#2563EB', borderColor: '#2563EB'},
|
|
109
|
+
chipText: {color: '#334155', fontSize: 12},
|
|
110
|
+
chipTextActive: {color: '#FFFFFF'},
|
|
111
|
+
field: {marginBottom: 8},
|
|
112
|
+
label: {fontSize: 12, color: '#334155', marginBottom: 4, fontWeight: '600'},
|
|
113
|
+
input: {borderWidth: 1, borderColor: '#CBD5E1', borderRadius: 10, paddingHorizontal: 10, paddingVertical: 8, color: '#0F172A'},
|
|
114
|
+
error: {color: '#DC2626', fontSize: 12},
|
|
115
|
+
actions: {flexDirection: 'row', justifyContent: 'flex-end', gap: 8},
|
|
116
|
+
ghost: {borderWidth: 1, borderColor: '#2563EB', borderRadius: 10, paddingHorizontal: 14, paddingVertical: 9},
|
|
117
|
+
ghostText: {color: '#2563EB', fontWeight: '600'},
|
|
118
|
+
primary: {backgroundColor: '#2563EB', borderRadius: 10, paddingHorizontal: 16, paddingVertical: 9, minWidth: 90, alignItems: 'center'},
|
|
119
|
+
primaryText: {color: '#FFFFFF', fontWeight: '700'},
|
|
120
|
+
};
|
|
@@ -73,6 +73,7 @@ export default function WhatsAppConnectionPage() {
|
|
|
73
73
|
const [accessToken, setAccessToken] = useState('');
|
|
74
74
|
const [phoneNumberId, setPhoneNumberId] = useState('');
|
|
75
75
|
const [apiVersion, setApiVersion] = useState('v22.0');
|
|
76
|
+
const [connectionType, setConnectionType] = useState('support');
|
|
76
77
|
const [qrValue, setQrValue] = useState('');
|
|
77
78
|
const [connectionStatus, setConnectionStatus] = useState('');
|
|
78
79
|
const [lastRequestedPhone, setLastRequestedPhone] = useState('');
|
|
@@ -189,6 +190,7 @@ export default function WhatsAppConnectionPage() {
|
|
|
189
190
|
accessToken: token,
|
|
190
191
|
phoneNumberId: pnid,
|
|
191
192
|
apiVersion: apiVersion || 'v22.0',
|
|
193
|
+
type: connectionType,
|
|
192
194
|
people: peopleIri,
|
|
193
195
|
name: `WhatsApp Oficial ${pnid}`,
|
|
194
196
|
});
|
|
@@ -203,13 +205,14 @@ export default function WhatsAppConnectionPage() {
|
|
|
203
205
|
} finally {
|
|
204
206
|
setSubmitting(false);
|
|
205
207
|
}
|
|
206
|
-
}, [accessToken, phoneNumberId, apiVersion, connectionsActions, peopleIri, loadConnections, showError, showSuccess]);
|
|
208
|
+
}, [accessToken, phoneNumberId, apiVersion, connectionType, connectionsActions, peopleIri, loadConnections, showError, showSuccess]);
|
|
207
209
|
|
|
208
210
|
const handlePrimaryAction = useCallback(async () => {
|
|
209
211
|
if (providerMode === PROVIDER_OFFICIAL) {
|
|
210
212
|
return saveOfficialConnection();
|
|
211
213
|
}
|
|
212
|
-
return handlePrimaryAction()
|
|
214
|
+
// Was `return handlePrimaryAction()` (infinite recursion): the QR flow never started.
|
|
215
|
+
return startPolling(completePhone);
|
|
213
216
|
}, [providerMode, saveOfficialConnection, startPolling, completePhone]);
|
|
214
217
|
|
|
215
218
|
useFocusEffect(
|
|
@@ -365,6 +368,32 @@ export default function WhatsAppConnectionPage() {
|
|
|
365
368
|
onPrimaryAction={() => handlePrimaryAction()}
|
|
366
369
|
/>
|
|
367
370
|
|
|
371
|
+
<View style={{ flexDirection: 'row', gap: 8, marginTop: 8 }}>
|
|
372
|
+
{[['support', 'Suporte'], ['relationship', 'Comercial']].map(([value, label]) => (
|
|
373
|
+
<TouchableOpacity
|
|
374
|
+
key={value}
|
|
375
|
+
onPress={() => setConnectionType(value)}
|
|
376
|
+
style={{
|
|
377
|
+
borderWidth: 1,
|
|
378
|
+
borderColor: connectionType === value ? brandColors.primary : '#CBD5E1',
|
|
379
|
+
backgroundColor: connectionType === value ? brandColors.primary : 'transparent',
|
|
380
|
+
borderRadius: 14,
|
|
381
|
+
paddingHorizontal: 12,
|
|
382
|
+
paddingVertical: 6,
|
|
383
|
+
}}>
|
|
384
|
+
<Text style={{ color: connectionType === value ? '#FFFFFF' : '#334155', fontSize: 12 }}>{label}</Text>
|
|
385
|
+
</TouchableOpacity>
|
|
386
|
+
))}
|
|
387
|
+
</View>
|
|
388
|
+
<Text style={styles.helperText}>
|
|
389
|
+
Sem IA configurada, as conversas deste numero vao para {connectionType === 'support' ? 'Suporte' : 'o CRM'}.
|
|
390
|
+
Com IA, ela atende primeiro e encaminha.
|
|
391
|
+
</Text>
|
|
392
|
+
{providerMode === PROVIDER_OFFICIAL ? (
|
|
393
|
+
<Text style={styles.helperText}>
|
|
394
|
+
Webhook no app Meta: https://api.controleonline.com/webhook/whatsapp-cloud (campo messages).
|
|
395
|
+
</Text>
|
|
396
|
+
) : null}
|
|
368
397
|
<Text style={styles.helperText}>
|
|
369
398
|
Numero atual: {completePhone || 'Nao informado'}
|
|
370
399
|
</Text>
|
|
@@ -130,22 +130,43 @@ const formatRuntimeFooterVersion = version => {
|
|
|
130
130
|
|
|
131
131
|
const IPV4_PATTERN = /^(\d{1,3}\.){3}\d{1,3}$/;
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
const HEX_IDENTIFIER_PATTERN = /^[0-9a-f]+$/i;
|
|
134
|
+
const HEX_IDENTIFIER_TAIL_LENGTH = 8;
|
|
135
|
+
|
|
136
|
+
// IPv4 is shown in full. ':'-separated ids (IPv6/MAC-like) are shortened to an
|
|
137
|
+
// ellipsis plus the last two blocks, e.g. "…46f4:eb0b". Plain hex ids (optionally
|
|
138
|
+
// '-' separated, e.g. UUID) are shortened to an ellipsis plus the last 8
|
|
139
|
+
// characters in two ':'-separated blocks of 4, e.g. "…e5f6:a7b8". Anything else
|
|
140
|
+
// (hostnames, short ids) is returned untouched.
|
|
135
141
|
const formatRuntimeFooterIdentifier = value => {
|
|
136
142
|
const identifier = safeTrim(value);
|
|
137
143
|
|
|
138
|
-
if (!identifier || IPV4_PATTERN.test(identifier)
|
|
144
|
+
if (!identifier || IPV4_PATTERN.test(identifier)) {
|
|
139
145
|
return identifier;
|
|
140
146
|
}
|
|
141
147
|
|
|
142
|
-
|
|
148
|
+
if (identifier.includes(':')) {
|
|
149
|
+
const blocks = identifier.split(':').filter(Boolean);
|
|
143
150
|
|
|
144
|
-
|
|
151
|
+
if (blocks.length <= 2) {
|
|
152
|
+
return identifier;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return `…${blocks.slice(-2).join(':')}`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const hex = identifier.replace(/-/g, '');
|
|
159
|
+
|
|
160
|
+
if (
|
|
161
|
+
!HEX_IDENTIFIER_PATTERN.test(hex) ||
|
|
162
|
+
hex.length <= HEX_IDENTIFIER_TAIL_LENGTH
|
|
163
|
+
) {
|
|
145
164
|
return identifier;
|
|
146
165
|
}
|
|
147
166
|
|
|
148
|
-
|
|
167
|
+
const tail = hex.slice(-HEX_IDENTIFIER_TAIL_LENGTH);
|
|
168
|
+
|
|
169
|
+
return `…${tail.slice(0, 4)}:${tail.slice(4)}`;
|
|
149
170
|
};
|
|
150
171
|
|
|
151
172
|
const getRuntimeFooterWebHost = () => {
|
|
@@ -69,3 +69,43 @@ export const saveOfficialWhatsappConnection = ({ commit, getters }, params = {})
|
|
|
69
69
|
commit(types.SET_ISLOADING, false);
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Persist an e-mail connection (IMAP read + SMTP reply). Credentials go to channelConfig (write-only).
|
|
75
|
+
*/
|
|
76
|
+
export const saveEmailConnection = ({ commit }, params = {}) => {
|
|
77
|
+
commit(types.SET_ISLOADING, true);
|
|
78
|
+
const port = (value, fallback) => Number(String(value || '').replace(/\D/g, '')) || fallback;
|
|
79
|
+
const body = {
|
|
80
|
+
name: params.name || `E-mail ${params.from_address || ''}`.trim(),
|
|
81
|
+
channel: 'email',
|
|
82
|
+
type: params.type || 'support',
|
|
83
|
+
people: params.people,
|
|
84
|
+
channelConfig: JSON.stringify({
|
|
85
|
+
from_address: params.from_address,
|
|
86
|
+
from_name: params.from_name || '',
|
|
87
|
+
username: params.username,
|
|
88
|
+
password: params.password,
|
|
89
|
+
imap_host: params.imap_host,
|
|
90
|
+
imap_port: port(params.imap_port, 993),
|
|
91
|
+
imap_encryption: 'ssl',
|
|
92
|
+
smtp_host: params.smtp_host,
|
|
93
|
+
smtp_port: port(params.smtp_port, 587),
|
|
94
|
+
smtp_encryption: port(params.smtp_port, 587) === 465 ? 'ssl' : 'tls',
|
|
95
|
+
}),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return api
|
|
99
|
+
.fetch(params.id ? `/connections/${params.id}` : '/connections', { method: params.id ? 'PUT' : 'POST', body })
|
|
100
|
+
.then(data => {
|
|
101
|
+
commit(types.SET_ITEM, data);
|
|
102
|
+
return data;
|
|
103
|
+
})
|
|
104
|
+
.catch(e => {
|
|
105
|
+
commit(types.SET_ERROR, e.message);
|
|
106
|
+
throw e;
|
|
107
|
+
})
|
|
108
|
+
.finally(() => {
|
|
109
|
+
commit(types.SET_ISLOADING, false);
|
|
110
|
+
});
|
|
111
|
+
};
|
|
@@ -217,7 +217,7 @@ test('reads the persisted config-version for non-web runtimes', () => {
|
|
|
217
217
|
},
|
|
218
218
|
},
|
|
219
219
|
}),
|
|
220
|
-
'PDV (
|
|
220
|
+
'PDV (…1069:b294) / v1.3.7',
|
|
221
221
|
)
|
|
222
222
|
})
|
|
223
223
|
|
|
@@ -245,7 +245,7 @@ test('prefers the backend device identifier used by the devices page', () => {
|
|
|
245
245
|
},
|
|
246
246
|
},
|
|
247
247
|
}),
|
|
248
|
-
'PDV (
|
|
248
|
+
'PDV (…1069:b294) / v1.3.7',
|
|
249
249
|
)
|
|
250
250
|
|
|
251
251
|
const debugInfo = getRuntimeFooterDebugInfo({
|
|
@@ -272,8 +272,8 @@ test('prefers the backend device identifier used by the devices page', () => {
|
|
|
272
272
|
})
|
|
273
273
|
|
|
274
274
|
assert.equal(debugInfo.versionLabel, 'v1.3.7')
|
|
275
|
-
assert.equal(debugInfo.displayName, 'PDV (
|
|
276
|
-
assert.equal(debugInfo.runtimeDetail, '
|
|
275
|
+
assert.equal(debugInfo.displayName, 'PDV (…1069:b294)')
|
|
276
|
+
assert.equal(debugInfo.runtimeDetail, '…1069:b294')
|
|
277
277
|
assert.equal(debugInfo.runtimeDetailSource, 'device_config.device.device')
|
|
278
278
|
assert.equal(debugInfo.versionCandidates[0]?.source, 'device_config.device.metadata.app.version')
|
|
279
279
|
assert.equal(debugInfo.rawValues.deviceId, 'd41ac8afb9f178eb')
|
|
@@ -384,8 +384,8 @@ test('does not invent a fallback label when the operation mode translation is mi
|
|
|
384
384
|
})
|
|
385
385
|
|
|
386
386
|
assert.equal(debugInfo.operationModeLabel, '')
|
|
387
|
-
assert.equal(debugInfo.displayName, 'PDV (
|
|
388
|
-
assert.equal(debugInfo.primaryText, 'PDV (
|
|
387
|
+
assert.equal(debugInfo.displayName, 'PDV (…1069:b294)')
|
|
388
|
+
assert.equal(debugInfo.primaryText, 'PDV (…1069:b294) / v1.3.7')
|
|
389
389
|
})
|
|
390
390
|
|
|
391
391
|
test('renders totem mode in the runtime footer', () => {
|
|
@@ -500,6 +500,14 @@ test('formats runtime identifier: IPv4 full, non-IPv4 shortened to last two bloc
|
|
|
500
500
|
assert.equal(formatRuntimeFooterIdentifier('abc'), 'abc')
|
|
501
501
|
assert.equal(formatRuntimeFooterIdentifier(''), '')
|
|
502
502
|
assert.equal(formatRuntimeFooterIdentifier(null), '')
|
|
503
|
+
assert.equal(formatRuntimeFooterIdentifier('a1b2c3d4e5f6a7b8'), '…e5f6:a7b8')
|
|
504
|
+
assert.equal(
|
|
505
|
+
formatRuntimeFooterIdentifier('3f2b8c1e-9d4a-4c7b-b1c2-0a9e4f7ab1c2'),
|
|
506
|
+
'…4f7a:b1c2',
|
|
507
|
+
)
|
|
508
|
+
assert.equal(formatRuntimeFooterIdentifier('A1B2C3D4E5F6'), '…C3D4:E5F6')
|
|
509
|
+
assert.equal(formatRuntimeFooterIdentifier('a1b2c3d4'), 'a1b2c3d4')
|
|
510
|
+
assert.equal(formatRuntimeFooterIdentifier('admin.lave-go.com'), 'admin.lave-go.com')
|
|
503
511
|
})
|
|
504
512
|
|
|
505
513
|
test('primary text shortens IPv6 public ip', () => {
|