@controleonline/ui-common 1.2.136 → 1.2.137

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.
@@ -1,13 +1,14 @@
1
1
  {
2
- "version": "1.2.136",
2
+ "version": "1.2.137",
3
3
  "rc": 1,
4
- "branch": "rc/1.2.136-rc.1",
5
- "baseMaster": "e9e2c2e18aef6ae9fd7a7b5c81f7abbc4699d412",
4
+ "branch": "rc/1.2.137-rc.1",
5
+ "baseMaster": "8571a3ddc00b6522b47e5fb7aad3bebaa2262017",
6
+ "baseTag": "v1.2.136",
6
7
  "tasks": [
7
- 168
8
+ 1764
8
9
  ],
9
10
  "frozen": true,
10
11
  "repositories": {
11
- "ControleOnline/ui-common": "8bfec2dc492f477e8a1bfe6cfdb17aa8555d4489"
12
+ "ControleOnline/ui-common": "1d73fdcfdc793c22640111ea26647f254f47ec88"
12
13
  }
13
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@controleonline/ui-common",
3
- "version": "1.2.136",
3
+ "version": "1.2.137",
4
4
  "author": "ControleOnline",
5
5
  "description": "ControleOnline Common Quasar UI Component",
6
6
  "license": "MIT",
@@ -0,0 +1,120 @@
1
+ import React, { useCallback, useEffect, useState } from 'react';
2
+ import { ActivityIndicator, Text, TouchableOpacity, View } from 'react-native';
3
+ import Icon from 'react-native-vector-icons/Feather';
4
+ import { useStore } from '@store';
5
+ import { fetchPeopleConfigs } from './fetchPeopleConfigs';
6
+
7
+ // Attendance contexts served by the company's numbers/mailboxes (app-community#1764).
8
+ // With more than one enabled, the customer's first message gets a simple menu (no AI)
9
+ // and the request opens in the context the customer picks.
10
+ export const CONVERSATION_CONTEXTS_KEY = 'conversation-contexts';
11
+ export const CONVERSATION_CONTEXTS = [
12
+ ['support', 'Suporte'],
13
+ ['relationship', 'Comercial'],
14
+ ];
15
+ const DEFAULT_CONTEXTS = ['support'];
16
+
17
+ export const parseConversationContexts = value => {
18
+ let list = value;
19
+ if (typeof value === 'string') {
20
+ try {
21
+ list = JSON.parse(value);
22
+ } catch (e) {
23
+ list = value.split(',');
24
+ }
25
+ }
26
+ const valid = CONVERSATION_CONTEXTS.map(([key]) => key);
27
+ const keys = (Array.isArray(list) ? list : [])
28
+ .map(item => String(item || '').trim())
29
+ .filter((item, index, all) => valid.includes(item) && all.indexOf(item) === index);
30
+ return keys.length ? keys : DEFAULT_CONTEXTS;
31
+ };
32
+
33
+ export default function ConversationContextsCard({ peopleIri, styles, brandColors, showError, showSuccess }) {
34
+ const configsStore = useStore('configs');
35
+ const [enabled, setEnabled] = useState(DEFAULT_CONTEXTS);
36
+ const [loading, setLoading] = useState(true);
37
+ const [saving, setSaving] = useState(false);
38
+
39
+ useEffect(() => {
40
+ let active = true;
41
+ setLoading(true);
42
+ fetchPeopleConfigs({ peopleIri, configKeys: [CONVERSATION_CONTEXTS_KEY] })
43
+ .then(items => {
44
+ if (active) setEnabled(parseConversationContexts(items?.[0]?.configValue));
45
+ })
46
+ .catch(() => {})
47
+ .finally(() => {
48
+ if (active) setLoading(false);
49
+ });
50
+ return () => {
51
+ active = false;
52
+ };
53
+ }, [peopleIri]);
54
+
55
+ const toggle = useCallback(async key => {
56
+ const next = enabled.includes(key) ? enabled.filter(item => item !== key) : [...enabled, key];
57
+ if (!next.length) {
58
+ showError?.('Deixe pelo menos um contexto habilitado.');
59
+ return;
60
+ }
61
+ const ordered = CONVERSATION_CONTEXTS.map(([item]) => item).filter(item => next.includes(item));
62
+ setSaving(true);
63
+ try {
64
+ await configsStore.actions.addConfigs({
65
+ configKey: CONVERSATION_CONTEXTS_KEY,
66
+ configValue: JSON.stringify(ordered),
67
+ people: peopleIri,
68
+ visibility: 'private',
69
+ });
70
+ setEnabled(ordered);
71
+ showSuccess?.('Contextos de atendimento atualizados.');
72
+ } catch (error) {
73
+ showError?.(error?.message || 'Nao foi possivel salvar os contextos.');
74
+ } finally {
75
+ setSaving(false);
76
+ }
77
+ }, [configsStore, enabled, peopleIri, showError, showSuccess]);
78
+
79
+ return (
80
+ <View style={{ marginTop: 16 }}>
81
+ <Text style={styles.inputLabel}>Contextos de atendimento</Text>
82
+ {loading ? (
83
+ <ActivityIndicator color={brandColors.primary} />
84
+ ) : (
85
+ <View style={{ flexDirection: 'row', gap: 8, marginTop: 6, flexWrap: 'wrap' }}>
86
+ {CONVERSATION_CONTEXTS.map(([key, label]) => {
87
+ const active = enabled.includes(key);
88
+ return (
89
+ <TouchableOpacity
90
+ key={key}
91
+ disabled={saving}
92
+ onPress={() => toggle(key)}
93
+ style={{
94
+ flexDirection: 'row',
95
+ alignItems: 'center',
96
+ gap: 6,
97
+ borderWidth: 1,
98
+ borderColor: active ? brandColors.primary : '#CBD5E1',
99
+ backgroundColor: active ? brandColors.primary : 'transparent',
100
+ borderRadius: 14,
101
+ paddingHorizontal: 12,
102
+ paddingVertical: 6,
103
+ opacity: saving ? 0.6 : 1,
104
+ }}>
105
+ <Icon name={active ? 'check-square' : 'square'} size={14} color={active ? '#FFFFFF' : '#334155'} />
106
+ <Text style={{ color: active ? '#FFFFFF' : '#334155', fontSize: 12 }}>{label}</Text>
107
+ </TouchableOpacity>
108
+ );
109
+ })}
110
+ </View>
111
+ )}
112
+ <Text style={styles.helperText}>
113
+ {enabled.length > 1
114
+ ? 'Todos os numeros atendem estes contextos. Na primeira mensagem o cliente recebe um menu e o chamado abre no contexto escolhido.'
115
+ : 'Todos os numeros atendem este contexto: o chamado abre direto nele.'}
116
+ {' '}Com IA configurada, ela atende primeiro e encaminha.
117
+ </Text>
118
+ </View>
119
+ );
120
+ }
@@ -18,14 +18,10 @@ const FIELDS = [
18
18
  ['smtp_host', 'Servidor SMTP', 'smtp.gmail.com'],
19
19
  ['smtp_port', 'Porta SMTP', '587'],
20
20
  ];
21
- const TYPES = [
22
- ['support', 'Suporte'],
23
- ['relationship', 'Comercial'],
24
- ];
25
21
 
26
22
  export default function EmailConnectionModal({visible, peopleIri, onClose, onSaved}) {
27
23
  const connectionsStore = useStore('connections');
28
- const [form, setForm] = useState({imap_port: '993', smtp_port: '587', type: 'support'});
24
+ const [form, setForm] = useState({imap_port: '993', smtp_port: '587'});
29
25
  const [saving, setSaving] = useState(false);
30
26
  const [error, setError] = useState('');
31
27
  const set = key => value => setForm(prev => ({...prev, [key]: value}));
@@ -40,7 +36,7 @@ export default function EmailConnectionModal({visible, peopleIri, onClose, onSav
40
36
  setError('');
41
37
  try {
42
38
  await connectionsStore.actions.saveEmailConnection({...form, people: peopleIri});
43
- setForm({imap_port: '993', smtp_port: '587', type: 'support'});
39
+ setForm({imap_port: '993', smtp_port: '587'});
44
40
  onSaved?.();
45
41
  } catch (e) {
46
42
  setError(e?.message || 'Não foi possível salvar a conexão.');
@@ -59,13 +55,6 @@ export default function EmailConnectionModal({visible, peopleIri, onClose, onSav
59
55
  As respostas saem por este endereço.
60
56
  </Text>
61
57
  <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
58
  {FIELDS.map(([key, label, placeholder]) => (
70
59
  <View key={key} style={s.field}>
71
60
  <Text style={s.label}>{label}</Text>
@@ -20,6 +20,7 @@ import {
20
20
  buildOfficialProviderConfig,
21
21
  } from './whatsAppConnectionHelpers';
22
22
  import WhatsAppProviderForm from './WhatsAppProviderForm';
23
+ import ConversationContextsCard from './ConversationContextsCard';
23
24
  import { isEmbeddedSignupSupported, launchEmbeddedSignup } from './whatsAppEmbeddedSignup';
24
25
  import {
25
26
  resolveThemePalette,
@@ -74,7 +75,6 @@ export default function WhatsAppConnectionPage() {
74
75
  const [accessToken, setAccessToken] = useState('');
75
76
  const [phoneNumberId, setPhoneNumberId] = useState('');
76
77
  const [apiVersion, setApiVersion] = useState('v22.0');
77
- const [connectionType, setConnectionType] = useState('support');
78
78
  const [qrValue, setQrValue] = useState('');
79
79
  const [connectionStatus, setConnectionStatus] = useState('');
80
80
  const [lastRequestedPhone, setLastRequestedPhone] = useState('');
@@ -192,7 +192,6 @@ export default function WhatsAppConnectionPage() {
192
192
  accessToken: token,
193
193
  phoneNumberId: pnid,
194
194
  apiVersion: apiVersion || 'v22.0',
195
- type: connectionType,
196
195
  people: peopleIri,
197
196
  name: `WhatsApp Oficial ${pnid}`,
198
197
  });
@@ -207,7 +206,7 @@ export default function WhatsAppConnectionPage() {
207
206
  } finally {
208
207
  setSubmitting(false);
209
208
  }
210
- }, [accessToken, phoneNumberId, apiVersion, connectionType, connectionsActions, peopleIri, loadConnections, showError, showSuccess]);
209
+ }, [accessToken, phoneNumberId, apiVersion, connectionsActions, peopleIri, loadConnections, showError, showSuccess]);
211
210
 
212
211
  // Meta Embedded Signup only runs in the browser (Facebook JS SDK popup).
213
212
  useEffect(() => {
@@ -236,7 +235,6 @@ export default function WhatsAppConnectionPage() {
236
235
  const response = await connectionsActions.completeWhatsappEmbeddedSignup({
237
236
  ...session,
238
237
  coexistence,
239
- type: connectionType,
240
238
  people: peopleIri,
241
239
  });
242
240
  showSuccess(
@@ -254,7 +252,7 @@ export default function WhatsAppConnectionPage() {
254
252
  } finally {
255
253
  setSubmitting(false);
256
254
  }
257
- }, [embeddedSignupConfig, connectionsActions, connectionType, peopleIri, loadConnections, showError, showSuccess]);
255
+ }, [embeddedSignupConfig, connectionsActions, peopleIri, loadConnections, showError, showSuccess]);
258
256
 
259
257
  const handlePrimaryAction = useCallback(async () => {
260
258
  if (providerMode === PROVIDER_OFFICIAL) {
@@ -419,27 +417,13 @@ export default function WhatsAppConnectionPage() {
419
417
  onEmbeddedSignup={handleEmbeddedSignup}
420
418
  />
421
419
 
422
- <View style={{ flexDirection: 'row', gap: 8, marginTop: 8 }}>
423
- {[['support', 'Suporte'], ['relationship', 'Comercial']].map(([value, label]) => (
424
- <TouchableOpacity
425
- key={value}
426
- onPress={() => setConnectionType(value)}
427
- style={{
428
- borderWidth: 1,
429
- borderColor: connectionType === value ? brandColors.primary : '#CBD5E1',
430
- backgroundColor: connectionType === value ? brandColors.primary : 'transparent',
431
- borderRadius: 14,
432
- paddingHorizontal: 12,
433
- paddingVertical: 6,
434
- }}>
435
- <Text style={{ color: connectionType === value ? '#FFFFFF' : '#334155', fontSize: 12 }}>{label}</Text>
436
- </TouchableOpacity>
437
- ))}
438
- </View>
439
- <Text style={styles.helperText}>
440
- Sem IA configurada, as conversas deste numero vao para {connectionType === 'support' ? 'Suporte' : 'o CRM'}.
441
- Com IA, ela atende primeiro e encaminha.
442
- </Text>
420
+ <ConversationContextsCard
421
+ peopleIri={peopleIri}
422
+ styles={styles}
423
+ brandColors={brandColors}
424
+ showError={showError}
425
+ showSuccess={showSuccess}
426
+ />
443
427
  {providerMode === PROVIDER_OFFICIAL ? (
444
428
  <Text style={styles.helperText}>
445
429
  Webhook no app Meta: https://api.controleonline.com/webhook/whatsapp-cloud (campo messages).
@@ -516,10 +500,6 @@ export default function WhatsAppConnectionPage() {
516
500
  <Text style={styles.connectionMetaLabel}>Telefone</Text>
517
501
  <Text style={styles.connectionMetaValue}>{item.phoneLabel}</Text>
518
502
  </View>
519
- <View style={styles.connectionMetaItem}>
520
- <Text style={styles.connectionMetaLabel}>Tipo</Text>
521
- <Text style={styles.connectionMetaValue}>{item.type}</Text>
522
- </View>
523
503
  </View>
524
504
 
525
505
  <View style={styles.connectionMetaRow}>
@@ -56,7 +56,6 @@ export const normalizeConnection = item => {
56
56
  ? item?.status?.status || item?.status?.name
57
57
  : item?.status) || 'Pendente',
58
58
  statusIri: resolveStatusIri(item?.status),
59
- type: item?.type || 'Nenhum',
60
59
  channel,
61
60
  provider: channel,
62
61
  phone: item?.phone || {},
@@ -34,7 +34,6 @@ export const saveOfficialWhatsappConnection = ({ commit }, params = {}) => {
34
34
  const body = {
35
35
  name: params.name || `WA Oficial ${params.phoneNumberId || ""}`.trim().slice(0, 50),
36
36
  channel: "whatsapp_official",
37
- type: params.type || "relationship",
38
37
  people: params.people,
39
38
  channelConfig: JSON.stringify({
40
39
  access_token: params.accessToken,
@@ -81,7 +80,6 @@ export const saveEmailConnection = ({ commit }, params = {}) => {
81
80
  const body = {
82
81
  name: params.name || `E-mail ${params.from_address || ''}`.trim(),
83
82
  channel: 'email',
84
- type: params.type || 'support',
85
83
  people: params.people,
86
84
  channelConfig: JSON.stringify({
87
85
  from_address: params.from_address,
@@ -134,7 +132,6 @@ export const completeWhatsappEmbeddedSignup = ({ commit }, params = {}) => {
134
132
  waba_id: params.wabaId,
135
133
  phone_number_id: params.phoneNumberId,
136
134
  coexistence: !!params.coexistence,
137
- type: params.type || null,
138
135
  connection: params.connection || null,
139
136
  },
140
137
  })