@controleonline/ui-crm 1.0.78 → 1.0.82
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 +5 -5
- package/package.json +1 -1
- package/src/react/components/conversation/AttachmentPreview.js +95 -0
- package/src/react/components/conversation/Composer.js +17 -27
- package/src/react/components/conversation/ConversationView.js +52 -8
- package/src/react/pages/tickets/TicketWorkspace.js +4 -2
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.81",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.0.
|
|
5
|
-
"baseMaster": "
|
|
4
|
+
"branch": "rc/1.0.81-rc.1",
|
|
5
|
+
"baseMaster": "b96041bba3797409d02e6f95437aca568547dfaf",
|
|
6
6
|
"tasks": [
|
|
7
|
-
|
|
7
|
+
89
|
|
8
8
|
],
|
|
9
9
|
"frozen": true,
|
|
10
10
|
"repositories": {
|
|
11
|
-
"ControleOnline/ui-crm": "
|
|
11
|
+
"ControleOnline/ui-crm": "92c56c7f73ab065f470877d7838d2a3a9ee7236b"
|
|
12
12
|
}
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents WhatsApp-like attachment preview: opens right after a file is picked, shows the image (or the
|
|
3
|
+
* file name), takes an optional caption and sends with ➤ (Enter on web) or discards with ✕.
|
|
4
|
+
*/
|
|
5
|
+
import React, {useEffect, useMemo, useState} from 'react';
|
|
6
|
+
import {Image, Modal, Platform, Text, TextInput, TouchableOpacity, View} from 'react-native';
|
|
7
|
+
|
|
8
|
+
const mimeOf = file => String(file?.type || file?.mimeType || '').toLowerCase();
|
|
9
|
+
|
|
10
|
+
export default function AttachmentPreview({file, palette, onCancel, onSend}) {
|
|
11
|
+
const [caption, setCaption] = useState('');
|
|
12
|
+
const isImage = mimeOf(file).startsWith('image/') || /\.(png|jpe?g|gif|webp)$/i.test(String(file?.name || ''));
|
|
13
|
+
|
|
14
|
+
// Web files need an object URL for the preview; native pickers already give a uri.
|
|
15
|
+
const uri = useMemo(() => {
|
|
16
|
+
if (!file || !isImage) return null;
|
|
17
|
+
if (file.uri) return file.uri;
|
|
18
|
+
if (Platform.OS === 'web' && typeof URL !== 'undefined' && file instanceof Blob) return URL.createObjectURL(file);
|
|
19
|
+
return null;
|
|
20
|
+
}, [file, isImage]);
|
|
21
|
+
useEffect(() => () => {
|
|
22
|
+
if (uri && Platform.OS === 'web' && uri.startsWith('blob:')) URL.revokeObjectURL(uri);
|
|
23
|
+
}, [uri]);
|
|
24
|
+
useEffect(() => setCaption(''), [file]);
|
|
25
|
+
|
|
26
|
+
if (!file) return null;
|
|
27
|
+
const send = () => onSend({text: caption.trim(), file});
|
|
28
|
+
const onKeyPress = event => {
|
|
29
|
+
const e = event?.nativeEvent || {};
|
|
30
|
+
if (Platform.OS === 'web' && e.key === 'Enter' && !e.shiftKey) {
|
|
31
|
+
event.preventDefault?.();
|
|
32
|
+
send();
|
|
33
|
+
}
|
|
34
|
+
if (Platform.OS === 'web' && e.key === 'Escape') onCancel();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Modal transparent animationType="fade" visible onRequestClose={onCancel}>
|
|
39
|
+
<View style={{flex: 1, backgroundColor: 'rgba(0,0,0,0.6)', alignItems: 'center', justifyContent: 'center', padding: 16}}>
|
|
40
|
+
<View style={{width: '100%', maxWidth: 520, borderRadius: 14, overflow: 'hidden', backgroundColor: palette.panel}}>
|
|
41
|
+
<View style={{flexDirection: 'row', alignItems: 'center', paddingHorizontal: 12, paddingVertical: 10, borderBottomWidth: 1, borderBottomColor: palette.border}}>
|
|
42
|
+
<TouchableOpacity onPress={onCancel} accessibilityLabel="Descartar anexo" style={{padding: 4, marginRight: 8}}>
|
|
43
|
+
<Text style={{color: palette.muted, fontSize: 18, fontWeight: '700'}}>✕</Text>
|
|
44
|
+
</TouchableOpacity>
|
|
45
|
+
<Text style={{color: palette.text, fontWeight: '700', flex: 1}} numberOfLines={1}>
|
|
46
|
+
{file.name || 'Anexo'}
|
|
47
|
+
</Text>
|
|
48
|
+
</View>
|
|
49
|
+
<View style={{alignItems: 'center', justifyContent: 'center', padding: 16, backgroundColor: palette.background, minHeight: 160}}>
|
|
50
|
+
{uri ? (
|
|
51
|
+
<Image source={{uri}} style={{width: '100%', height: 300}} resizeMode="contain" />
|
|
52
|
+
) : (
|
|
53
|
+
<View style={{alignItems: 'center'}}>
|
|
54
|
+
<Text style={{fontSize: 48}}>📄</Text>
|
|
55
|
+
<Text style={{color: palette.text, marginTop: 8, textAlign: 'center'}} numberOfLines={2}>
|
|
56
|
+
{file.name || 'Arquivo'}
|
|
57
|
+
</Text>
|
|
58
|
+
</View>
|
|
59
|
+
)}
|
|
60
|
+
</View>
|
|
61
|
+
<View style={{flexDirection: 'row', alignItems: 'flex-end', gap: 8, padding: 10}}>
|
|
62
|
+
<TextInput
|
|
63
|
+
style={{
|
|
64
|
+
flex: 1,
|
|
65
|
+
minHeight: 40,
|
|
66
|
+
maxHeight: 120,
|
|
67
|
+
borderRadius: 20,
|
|
68
|
+
borderWidth: 1,
|
|
69
|
+
borderColor: palette.inputBorder,
|
|
70
|
+
backgroundColor: palette.input,
|
|
71
|
+
color: palette.inputText,
|
|
72
|
+
paddingHorizontal: 14,
|
|
73
|
+
paddingVertical: 9,
|
|
74
|
+
fontSize: 15,
|
|
75
|
+
}}
|
|
76
|
+
value={caption}
|
|
77
|
+
onChangeText={setCaption}
|
|
78
|
+
onKeyPress={onKeyPress}
|
|
79
|
+
placeholder="Adicione uma legenda (opcional)"
|
|
80
|
+
placeholderTextColor={palette.placeholder}
|
|
81
|
+
multiline
|
|
82
|
+
autoFocus
|
|
83
|
+
/>
|
|
84
|
+
<TouchableOpacity
|
|
85
|
+
onPress={send}
|
|
86
|
+
accessibilityLabel="Enviar anexo"
|
|
87
|
+
style={{width: 44, height: 44, borderRadius: 22, alignItems: 'center', justifyContent: 'center', backgroundColor: palette.chipActive}}>
|
|
88
|
+
<Text style={{color: palette.chipActiveText, fontSize: 18}}>➤</Text>
|
|
89
|
+
</TouchableOpacity>
|
|
90
|
+
</View>
|
|
91
|
+
</View>
|
|
92
|
+
</View>
|
|
93
|
+
</Modal>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -1,32 +1,29 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @agents Message input, WhatsApp-like: Enter sends (Shift+Enter breaks the line), 📎
|
|
3
|
-
*
|
|
2
|
+
* @agents Message input, WhatsApp-like: Enter sends (Shift+Enter breaks the line), 📎 picks a file and opens
|
|
3
|
+
* a preview with caption (AttachmentPreview),
|
|
4
|
+
* 🎤 records a voice note (sent when recording stops). Sending never blocks typing: the input is cleared
|
|
5
|
+
* at once and `onSend({text, file})` queues the message (ConversationView shows it as pending).
|
|
4
6
|
*/
|
|
5
7
|
import React, {useState} from 'react';
|
|
6
8
|
import {ActivityIndicator, Platform, Text, TextInput, TouchableOpacity, View} from 'react-native';
|
|
9
|
+
import AttachmentPreview from './AttachmentPreview';
|
|
7
10
|
import useAudioRecording from './useAudioRecording';
|
|
8
11
|
import {selectFile} from './fileApi';
|
|
9
12
|
|
|
10
13
|
export default function Composer({palette, placeholder, disabled, disabledText, onSend, top, onError}) {
|
|
11
14
|
const [text, setText] = useState('');
|
|
12
15
|
const [file, setFile] = useState(null);
|
|
13
|
-
const
|
|
16
|
+
const sending = false;
|
|
14
17
|
const audio = useAudioRecording();
|
|
15
18
|
|
|
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
|
-
}
|
|
19
|
+
const send = (payload = {text, file: null}) => {
|
|
20
|
+
const message = {text: String(payload.text || '').trim(), file: payload.file || null};
|
|
21
|
+
if (!message.text && !message.file) return;
|
|
22
|
+
if (message.file) setFile(null);
|
|
23
|
+
else setText('');
|
|
24
|
+
Promise.resolve()
|
|
25
|
+
.then(() => onSend(message))
|
|
26
|
+
.catch(e => onError?.(e?.message || 'Não foi possível enviar'));
|
|
30
27
|
};
|
|
31
28
|
|
|
32
29
|
const attach = async () => {
|
|
@@ -45,7 +42,7 @@ export default function Composer({palette, placeholder, disabled, disabledText,
|
|
|
45
42
|
return;
|
|
46
43
|
}
|
|
47
44
|
const voice = await audio.stop();
|
|
48
|
-
if (voice)
|
|
45
|
+
if (voice) send({text: '', file: voice});
|
|
49
46
|
} catch (e) {
|
|
50
47
|
onError?.(e?.message || 'Não foi possível gravar');
|
|
51
48
|
}
|
|
@@ -68,18 +65,11 @@ export default function Composer({palette, placeholder, disabled, disabledText,
|
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
const iconBtn = {width: 40, height: 40, borderRadius: 20, alignItems: 'center', justifyContent: 'center'};
|
|
71
|
-
const hasContent = Boolean(text.trim()
|
|
68
|
+
const hasContent = Boolean(text.trim());
|
|
72
69
|
return (
|
|
73
70
|
<View style={{borderTopWidth: 1, borderTopColor: palette.border, backgroundColor: palette.panel, paddingHorizontal: 8, paddingVertical: 6}}>
|
|
74
71
|
{top}
|
|
75
|
-
{file
|
|
76
|
-
<View style={{flexDirection: 'row', alignItems: 'center', gap: 8, padding: 6, marginBottom: 4, borderRadius: 8, backgroundColor: palette.chip}}>
|
|
77
|
-
<Text style={{color: palette.chipText, flex: 1}} numberOfLines={1}>{`📎 ${file.name || 'arquivo'}`}</Text>
|
|
78
|
-
<TouchableOpacity onPress={() => setFile(null)}>
|
|
79
|
-
<Text style={{color: palette.danger, fontWeight: '700'}}>✕</Text>
|
|
80
|
-
</TouchableOpacity>
|
|
81
|
-
</View>
|
|
82
|
-
) : null}
|
|
72
|
+
<AttachmentPreview file={file} palette={palette} onCancel={() => setFile(null)} onSend={send} />
|
|
83
73
|
<View style={{flexDirection: 'row', alignItems: 'flex-end', gap: 6}}>
|
|
84
74
|
<TouchableOpacity style={iconBtn} onPress={attach} disabled={sending || audio.recording} accessibilityLabel="Anexar arquivo">
|
|
85
75
|
<Text style={{fontSize: 20, color: palette.muted}}>📎</Text>
|
|
@@ -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}
|