@controleonline/ui-common 1.2.126 → 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 +8 -7
- package/package.json +1 -1
- package/src/react/components/ManagerPushBridge.native.js +32 -5
- 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/store/connections/customActions.js +40 -0
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.
|
|
3
|
-
"rc":
|
|
4
|
-
"branch": "rc/1.2.
|
|
5
|
-
"baseMaster": "
|
|
2
|
+
"version": "1.2.127",
|
|
3
|
+
"rc": 1,
|
|
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
|
@@ -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;
|
|
@@ -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>
|
|
@@ -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
|
+
};
|