@controleonline/ui-crm 1.0.78 → 1.0.80
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,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.79",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.0.
|
|
5
|
-
"baseMaster": "
|
|
4
|
+
"branch": "rc/1.0.79-rc.1",
|
|
5
|
+
"baseMaster": "c035f8ef5c06d31cdcada0e7bb17f06b7c529bb8",
|
|
6
6
|
"tasks": [
|
|
7
|
-
|
|
7
|
+
86
|
|
8
8
|
],
|
|
9
9
|
"frozen": true,
|
|
10
10
|
"repositories": {
|
|
11
|
-
"ControleOnline/ui-crm": "
|
|
11
|
+
"ControleOnline/ui-crm": "6d8cfc9c8163d8305abd4f708850c5c5ac6ea88d"
|
|
12
12
|
}
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* @agents Message input, WhatsApp-like: Enter sends (Shift+Enter breaks the line), 📎 attaches a file,
|
|
3
|
-
* 🎤 records a voice note (sent when recording stops).
|
|
3
|
+
* 🎤 records a voice note (sent when recording stops). Sending never blocks typing: the input is cleared
|
|
4
|
+
* at once and `onSend({text, file})` queues the message (ConversationView shows it as pending).
|
|
4
5
|
*/
|
|
5
6
|
import React, {useState} from 'react';
|
|
6
7
|
import {ActivityIndicator, Platform, Text, TextInput, TouchableOpacity, View} from 'react-native';
|
|
@@ -10,23 +11,17 @@ import {selectFile} from './fileApi';
|
|
|
10
11
|
export default function Composer({palette, placeholder, disabled, disabledText, onSend, top, onError}) {
|
|
11
12
|
const [text, setText] = useState('');
|
|
12
13
|
const [file, setFile] = useState(null);
|
|
13
|
-
const
|
|
14
|
+
const sending = false;
|
|
14
15
|
const audio = useAudioRecording();
|
|
15
16
|
|
|
16
|
-
const send =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
} catch (e) {
|
|
26
|
-
onError?.(e?.message || 'Não foi possível enviar');
|
|
27
|
-
} finally {
|
|
28
|
-
setSending(false);
|
|
29
|
-
}
|
|
17
|
+
const send = (payload = {text, file}) => {
|
|
18
|
+
const message = {text: String(payload.text || '').trim(), file: payload.file || null};
|
|
19
|
+
if (!message.text && !message.file) return;
|
|
20
|
+
setText('');
|
|
21
|
+
setFile(null);
|
|
22
|
+
Promise.resolve()
|
|
23
|
+
.then(() => onSend(message))
|
|
24
|
+
.catch(e => onError?.(e?.message || 'Não foi possível enviar'));
|
|
30
25
|
};
|
|
31
26
|
|
|
32
27
|
const attach = async () => {
|
|
@@ -45,7 +40,7 @@ export default function Composer({palette, placeholder, disabled, disabledText,
|
|
|
45
40
|
return;
|
|
46
41
|
}
|
|
47
42
|
const voice = await audio.stop();
|
|
48
|
-
if (voice)
|
|
43
|
+
if (voice) send({text: '', file: voice});
|
|
49
44
|
} catch (e) {
|
|
50
45
|
onError?.(e?.message || 'Não foi possível gravar');
|
|
51
46
|
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* day with WhatsApp-like bubbles, and the composer. Uploads happen here: `onSend({text, fileId})`.
|
|
4
4
|
* `describe(item)` returns {side: 'left'|'right', kind: 'note'|'ai'|'msg'|'hidden', author}.
|
|
5
5
|
*/
|
|
6
|
-
import React, {useMemo, useRef} from 'react';
|
|
7
|
-
import {ActivityIndicator, FlatList, KeyboardAvoidingView, Platform, Text, View} from 'react-native';
|
|
6
|
+
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
|
|
7
|
+
import {ActivityIndicator, FlatList, KeyboardAvoidingView, Platform, Text, TouchableOpacity, View} from 'react-native';
|
|
8
8
|
import Composer from './Composer';
|
|
9
9
|
import MessageBubble from './MessageBubble';
|
|
10
10
|
import useChatPalette from './useChatPalette';
|
|
@@ -28,16 +28,25 @@ export default function ConversationView({
|
|
|
28
28
|
emptyText = 'Nenhuma mensagem ainda.',
|
|
29
29
|
footer = null,
|
|
30
30
|
onError,
|
|
31
|
+
pendingKind = 'msg',
|
|
31
32
|
}) {
|
|
32
33
|
const palette = useChatPalette();
|
|
33
34
|
const listRef = useRef(null);
|
|
35
|
+
// Optimistic messages: shown at once (🕓), sent one by one in the background, removed when the
|
|
36
|
+
// conversation reloads with them; a failed one stays (⚠) and is re-sent with a tap.
|
|
37
|
+
const [pending, setPending] = useState([]);
|
|
38
|
+
const onSendRef = useRef(onSend);
|
|
39
|
+
const queueRef = useRef(Promise.resolve());
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
onSendRef.current = onSend;
|
|
42
|
+
}, [onSend]);
|
|
34
43
|
|
|
35
44
|
const rows = useMemo(() => {
|
|
36
45
|
const out = [];
|
|
37
46
|
let lastDay = '';
|
|
38
47
|
let lastAuthor = '';
|
|
39
|
-
(messages || []).forEach(item => {
|
|
40
|
-
const meta = describe(item);
|
|
48
|
+
[...(messages || []), ...pending].forEach(item => {
|
|
49
|
+
const meta = item?.localId ? {side: 'right', kind: item.kind, author: 'Você'} : describe(item);
|
|
41
50
|
if (meta.kind === 'hidden') return;
|
|
42
51
|
const day = dayLabel(item?.createdAt);
|
|
43
52
|
if (day && day !== lastDay) {
|
|
@@ -50,11 +59,41 @@ export default function ConversationView({
|
|
|
50
59
|
lastAuthor = authorKey;
|
|
51
60
|
});
|
|
52
61
|
return out;
|
|
53
|
-
}, [messages, describe]);
|
|
62
|
+
}, [messages, pending, describe]);
|
|
54
63
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
const deliver = useCallback(
|
|
65
|
+
entry => {
|
|
66
|
+
queueRef.current = queueRef.current.then(async () => {
|
|
67
|
+
setPending(list => list.map(p => (p.localId === entry.localId ? {...p, status: 'pending'} : p)));
|
|
68
|
+
try {
|
|
69
|
+
const fileId = entry.upload ? await uploadAttachment(entry.upload, uploadCompanyId) : null;
|
|
70
|
+
// kind is captured when the message is written (a note stays a note if the mode changes).
|
|
71
|
+
await onSendRef.current({text: entry.text, fileId, kind: entry.kind});
|
|
72
|
+
setPending(list => list.filter(p => p.localId !== entry.localId));
|
|
73
|
+
} catch (e) {
|
|
74
|
+
setPending(list => list.map(p => (p.localId === entry.localId ? {...p, status: 'error'} : p)));
|
|
75
|
+
onError?.(e?.message || 'Não foi possível enviar');
|
|
76
|
+
}
|
|
77
|
+
// Lets React apply state from this send (e.g. a new request id) before the next one.
|
|
78
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
[uploadCompanyId, onError],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const send = ({text, file}) => {
|
|
85
|
+
const entry = {
|
|
86
|
+
localId: `local-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
|
|
87
|
+
text,
|
|
88
|
+
body: [file ? `📎 ${file.name || 'arquivo'}` : '', text].filter(Boolean).join('\n'),
|
|
89
|
+
upload: file || null,
|
|
90
|
+
createdAt: new Date().toISOString(),
|
|
91
|
+
status: 'pending',
|
|
92
|
+
kind: pendingKind,
|
|
93
|
+
};
|
|
94
|
+
setPending(list => [...list, entry]);
|
|
95
|
+
deliver(entry);
|
|
96
|
+
return true;
|
|
58
97
|
};
|
|
59
98
|
|
|
60
99
|
const renderRow = ({item: row}) =>
|
|
@@ -64,6 +103,11 @@ export default function ConversationView({
|
|
|
64
103
|
{row.label}
|
|
65
104
|
</Text>
|
|
66
105
|
</View>
|
|
106
|
+
) : row.item?.localId && row.item.status === 'error' ? (
|
|
107
|
+
<TouchableOpacity onPress={() => deliver(row.item)} accessibilityLabel="Reenviar mensagem">
|
|
108
|
+
<MessageBubble item={row.item} side={row.meta.side} kind={row.meta.kind} author={row.meta.author} showAuthor={row.showAuthor} palette={palette} />
|
|
109
|
+
<Text style={{color: palette.danger, fontSize: 11, textAlign: 'right', paddingHorizontal: 12}}>Não enviada · toque para reenviar</Text>
|
|
110
|
+
</TouchableOpacity>
|
|
67
111
|
) : (
|
|
68
112
|
<MessageBubble item={row.item} side={row.meta.side} kind={row.meta.kind} author={row.meta.author} showAuthor={row.showAuthor} palette={palette} />
|
|
69
113
|
);
|
|
@@ -128,8 +128,9 @@ export default function TicketWorkspace({taskId, extra = null}) {
|
|
|
128
128
|
[providerId, task, meId],
|
|
129
129
|
);
|
|
130
130
|
|
|
131
|
-
const send = async ({text, fileId}) => {
|
|
132
|
-
|
|
131
|
+
const send = async ({text, fileId, kind}) => {
|
|
132
|
+
const visibility = kind ? (kind === 'note' ? 'private' : 'public') : mode;
|
|
133
|
+
await postInteraction(taskId, {text, fileId, visibility});
|
|
133
134
|
await load({quiet: true});
|
|
134
135
|
return true;
|
|
135
136
|
};
|
|
@@ -215,6 +216,7 @@ export default function TicketWorkspace({taskId, extra = null}) {
|
|
|
215
216
|
loading={loading}
|
|
216
217
|
describe={describe}
|
|
217
218
|
onSend={send}
|
|
219
|
+
pendingKind={mode === 'public' ? 'msg' : 'note'}
|
|
218
220
|
uploadCompanyId={providerId}
|
|
219
221
|
placeholder={mode === 'public' ? 'Mensagem para o cliente' : 'Nota visível só para a equipe'}
|
|
220
222
|
canSend={options.canReply}
|