@controleonline/ui-crm 1.0.69 → 1.0.74
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 -7
- package/package.json +4 -3
- package/src/react/components/conversation/Attachment.js +61 -0
- package/src/react/components/conversation/AudioPlayer.native.js +28 -0
- package/src/react/components/conversation/AudioPlayer.web.js +9 -0
- package/src/react/components/conversation/Composer.js +134 -0
- package/src/react/components/conversation/ConversationView.js +91 -0
- package/src/react/components/conversation/MessageBubble.js +68 -0
- package/src/react/components/conversation/OptionPicker.js +62 -0
- package/src/react/components/conversation/RichText.js +34 -0
- package/src/react/components/conversation/fileApi.js +78 -0
- package/src/react/components/conversation/formatText.js +61 -0
- package/src/react/components/conversation/requestApi.js +91 -0
- package/src/react/components/conversation/useAudioRecording.native.js +31 -0
- package/src/react/components/conversation/useAudioRecording.web.js +54 -0
- package/src/react/components/conversation/useChatPalette.js +41 -0
- package/src/react/pages/crm/conversation.js +25 -326
- package/src/react/pages/mcp/McpPage.js +134 -130
- package/src/react/pages/mcp/useRequests.js +127 -0
- package/src/react/pages/settings/GeneralSettings.js +8 -0
- package/src/react/pages/settings/sections/TicketSettingsSection.js +124 -0
- package/src/react/pages/tickets/TicketConversationPage.js +5 -164
- package/src/react/pages/tickets/TicketFunnelPage.js +5 -1
- package/src/react/pages/tickets/TicketWorkspace.js +245 -0
- package/src/react/router/routes.js +7 -7
- package/src/tests/react/components/conversation/formatText.test.js +40 -0
- package/src/react/pages/crm/conversation.styles.js +0 -206
- package/src/react/pages/mcp/McpPage.styles.js +0 -132
- package/src/react/pages/mcp/useMcpChat.js +0 -277
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.73",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.0.
|
|
5
|
-
"baseMaster": "
|
|
4
|
+
"branch": "rc/1.0.73-rc.1",
|
|
5
|
+
"baseMaster": "49763e090fb2b5faabd8e088f82a5281902095a1",
|
|
6
6
|
"tasks": [
|
|
7
|
-
|
|
8
|
-
72
|
|
7
|
+
71
|
|
9
8
|
],
|
|
10
9
|
"frozen": true,
|
|
11
10
|
"repositories": {
|
|
12
|
-
"ControleOnline/ui-crm": "
|
|
13
|
-
}
|
|
11
|
+
"ControleOnline/ui-crm": "bebd5242d1254c2a170572d765b92694db2a789c"
|
|
12
|
+
},
|
|
13
|
+
"note": "Restores master to 1.0.70 content + /ai<->/support swap; 1.0.72 RC wrongly carried dev history."
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@controleonline/ui-crm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.74",
|
|
4
4
|
"author": "ControleOnline",
|
|
5
5
|
"description": "ControleOnline CRM Quasar UI Component",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/react/index.js",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "npm run test:crm-empty-state && npm run test:opportunity-status-filter && npm run test:general-settings && npm run test:opportunity-editor-references && npm run test:royalties-payable && npm run test:royalties-receivable && npm run test:income-statements && npm run test:seller-commissions && npm run test:proposal-product-selection && npm run test:proposal-products-navigation && npm run test:shop-franchise-visibility && npm run test:marketing-events",
|
|
9
|
+
"test": "npm run test:crm-empty-state && npm run test:opportunity-status-filter && npm run test:general-settings && npm run test:opportunity-editor-references && npm run test:royalties-payable && npm run test:royalties-receivable && npm run test:income-statements && npm run test:seller-commissions && npm run test:proposal-product-selection && npm run test:proposal-products-navigation && npm run test:shop-franchise-visibility && npm run test:marketing-events && npm run test:conversation",
|
|
10
10
|
"test:crm-empty-state": "node --test src/tests/react/utils/opportunityEmptyState.test.js",
|
|
11
11
|
"test:opportunity-status-filter": "node --test src/tests/react/utils/opportunityStatusFilter.test.cjs",
|
|
12
12
|
"test:general-settings": "node --test src/tests/react/pages/settings/generalSettings.shared.test.js",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"test:proposal-product-selection": "node --test src/tests/react/utils/proposalProductSelection.test.js src/tests/react/utils/proposalCreateHelpers.test.js",
|
|
20
20
|
"test:proposal-products-navigation": "node --test src/tests/react/pages/proposals/navigation.test.js src/tests/react/pages/proposals/proposalListHelpers.test.js",
|
|
21
21
|
"test:shop-franchise-visibility": "node --test src/tests/react/pages/settings/sections/shop/shopFranchiseVisibility.test.js",
|
|
22
|
-
"test:marketing-events": "node --test src/tests/react/pages/crm/marketingEventsHelpers.test.cjs"
|
|
22
|
+
"test:marketing-events": "node --test src/tests/react/pages/crm/marketingEventsHelpers.test.cjs",
|
|
23
|
+
"test:conversation": "node --test src/tests/react/components/conversation/formatText.test.js src/tests/react/pages/mcp/mcpChatUtils.test.js"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"c8": "^10.1.3"
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Attachment inside a bubble: image preview, voice note player or file chip (web download).
|
|
3
|
+
* Files are private, so they are loaded with the API token (fileApi.fileSource).
|
|
4
|
+
*/
|
|
5
|
+
import React, {useEffect, useState} from 'react';
|
|
6
|
+
import {ActivityIndicator, Image, Linking, Platform, Text, TouchableOpacity, View} from 'react-native';
|
|
7
|
+
import AudioPlayer from './AudioPlayer';
|
|
8
|
+
import {fetchFileMeta, fileIdOf, fileSource, kindOf} from './fileApi';
|
|
9
|
+
|
|
10
|
+
export default function Attachment({file, color}) {
|
|
11
|
+
const id = fileIdOf(file);
|
|
12
|
+
const [state, setState] = useState({loading: true});
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
let alive = true;
|
|
16
|
+
if (!id) return undefined;
|
|
17
|
+
Promise.all([fetchFileMeta(id), fileSource(id).catch(() => null)]).then(([meta, source]) => {
|
|
18
|
+
if (alive) setState({loading: false, meta, source, kind: kindOf(meta, source?.type)});
|
|
19
|
+
});
|
|
20
|
+
return () => {
|
|
21
|
+
alive = false;
|
|
22
|
+
};
|
|
23
|
+
}, [id]);
|
|
24
|
+
|
|
25
|
+
if (!id) return null;
|
|
26
|
+
if (state.loading) return <ActivityIndicator color={color} style={{marginVertical: 6}} />;
|
|
27
|
+
|
|
28
|
+
const name = state.meta?.fileName || 'Arquivo';
|
|
29
|
+
if (state.kind === 'image' && state.source) {
|
|
30
|
+
return (
|
|
31
|
+
<TouchableOpacity onPress={() => Platform.OS === 'web' && window.open(state.source.uri, '_blank')}>
|
|
32
|
+
<Image source={state.source} style={{width: 240, height: 180, borderRadius: 8, marginBottom: 4}} resizeMode="cover" />
|
|
33
|
+
</TouchableOpacity>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (state.kind === 'audio' && state.source) {
|
|
37
|
+
return <AudioPlayer source={state.source} color={color} />;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const open = () => {
|
|
41
|
+
if (!state.source?.uri) return;
|
|
42
|
+
if (Platform.OS === 'web') {
|
|
43
|
+
const a = document.createElement('a');
|
|
44
|
+
a.href = state.source.uri;
|
|
45
|
+
a.download = name;
|
|
46
|
+
a.click();
|
|
47
|
+
} else {
|
|
48
|
+
Linking.openURL(state.source.uri);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return (
|
|
52
|
+
<TouchableOpacity onPress={open}>
|
|
53
|
+
<View style={{flexDirection: 'row', alignItems: 'center', gap: 8, paddingVertical: 6}}>
|
|
54
|
+
<Text style={{fontSize: 22, color}}>📄</Text>
|
|
55
|
+
<Text style={{color, textDecorationLine: 'underline', maxWidth: 220}} numberOfLines={1}>
|
|
56
|
+
{name}
|
|
57
|
+
</Text>
|
|
58
|
+
</View>
|
|
59
|
+
</TouchableOpacity>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Native playback of a voice note (expo-audio) with play/pause.
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import {Text, TouchableOpacity, View} from 'react-native';
|
|
6
|
+
import {useAudioPlayer, useAudioPlayerStatus} from 'expo-audio';
|
|
7
|
+
|
|
8
|
+
export default function AudioPlayer({source, color}) {
|
|
9
|
+
const player = useAudioPlayer(source?.uri ? source : null);
|
|
10
|
+
const status = useAudioPlayerStatus(player);
|
|
11
|
+
const playing = Boolean(status?.playing);
|
|
12
|
+
const secs = Math.round(status?.duration || 0);
|
|
13
|
+
return (
|
|
14
|
+
<TouchableOpacity onPress={() => {
|
|
15
|
+
if (playing) {
|
|
16
|
+
player.pause();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (status?.didJustFinish) player.seekTo(0);
|
|
20
|
+
player.play();
|
|
21
|
+
}}>
|
|
22
|
+
<View style={{flexDirection: 'row', alignItems: 'center', gap: 8, paddingVertical: 4}}>
|
|
23
|
+
<Text style={{color, fontSize: 20}}>{playing ? '❚❚' : '▶'}</Text>
|
|
24
|
+
<Text style={{color}}>{`Áudio${secs ? ` · ${Math.floor(secs / 60)}:${String(secs % 60).padStart(2, '0')}` : ''}`}</Text>
|
|
25
|
+
</View>
|
|
26
|
+
</TouchableOpacity>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Web playback of a voice note (native <audio> controls, themed container).
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
export default function AudioPlayer({source}) {
|
|
7
|
+
if (!source?.uri) return null;
|
|
8
|
+
return React.createElement('audio', {src: source.uri, controls: true, preload: 'metadata', style: {width: 240, maxWidth: '100%'}});
|
|
9
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/*
|
|
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). `onSend({text, file})` resolves true on success.
|
|
4
|
+
*/
|
|
5
|
+
import React, {useState} from 'react';
|
|
6
|
+
import {ActivityIndicator, Platform, Text, TextInput, TouchableOpacity, View} from 'react-native';
|
|
7
|
+
import useAudioRecording from './useAudioRecording';
|
|
8
|
+
import {selectFile} from './fileApi';
|
|
9
|
+
|
|
10
|
+
export default function Composer({palette, placeholder, disabled, disabledText, onSend, top, onError}) {
|
|
11
|
+
const [text, setText] = useState('');
|
|
12
|
+
const [file, setFile] = useState(null);
|
|
13
|
+
const [sending, setSending] = useState(false);
|
|
14
|
+
const audio = useAudioRecording();
|
|
15
|
+
|
|
16
|
+
const send = async (payload = {text, file}) => {
|
|
17
|
+
if (sending || (!String(payload.text || '').trim() && !payload.file)) return;
|
|
18
|
+
setSending(true);
|
|
19
|
+
try {
|
|
20
|
+
const ok = await onSend({text: String(payload.text || '').trim(), file: payload.file || null});
|
|
21
|
+
if (ok !== false && payload !== null) {
|
|
22
|
+
setText('');
|
|
23
|
+
setFile(null);
|
|
24
|
+
}
|
|
25
|
+
} catch (e) {
|
|
26
|
+
onError?.(e?.message || 'Não foi possível enviar');
|
|
27
|
+
} finally {
|
|
28
|
+
setSending(false);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const attach = async () => {
|
|
33
|
+
try {
|
|
34
|
+
const picked = await selectFile('*/*');
|
|
35
|
+
if (picked) setFile(picked);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
onError?.(e?.message || 'Não foi possível anexar');
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const toggleRecording = async () => {
|
|
42
|
+
try {
|
|
43
|
+
if (!audio.recording) {
|
|
44
|
+
await audio.start();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const voice = await audio.stop();
|
|
48
|
+
if (voice) await send({text: '', file: voice});
|
|
49
|
+
} catch (e) {
|
|
50
|
+
onError?.(e?.message || 'Não foi possível gravar');
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const onKeyPress = event => {
|
|
55
|
+
const e = event?.nativeEvent || {};
|
|
56
|
+
if (Platform.OS === 'web' && e.key === 'Enter' && !e.shiftKey) {
|
|
57
|
+
event.preventDefault?.();
|
|
58
|
+
send();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
if (disabled) {
|
|
63
|
+
return (
|
|
64
|
+
<View style={{padding: 12, borderTopWidth: 1, borderTopColor: palette.border, backgroundColor: palette.panel}}>
|
|
65
|
+
<Text style={{color: palette.muted, textAlign: 'center'}}>{disabledText}</Text>
|
|
66
|
+
</View>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const iconBtn = {width: 40, height: 40, borderRadius: 20, alignItems: 'center', justifyContent: 'center'};
|
|
71
|
+
const hasContent = Boolean(text.trim() || file);
|
|
72
|
+
return (
|
|
73
|
+
<View style={{borderTopWidth: 1, borderTopColor: palette.border, backgroundColor: palette.panel, paddingHorizontal: 8, paddingVertical: 6}}>
|
|
74
|
+
{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}
|
|
83
|
+
<View style={{flexDirection: 'row', alignItems: 'flex-end', gap: 6}}>
|
|
84
|
+
<TouchableOpacity style={iconBtn} onPress={attach} disabled={sending || audio.recording} accessibilityLabel="Anexar arquivo">
|
|
85
|
+
<Text style={{fontSize: 20, color: palette.muted}}>📎</Text>
|
|
86
|
+
</TouchableOpacity>
|
|
87
|
+
{audio.recording ? (
|
|
88
|
+
<View style={{flex: 1, minHeight: 40, borderRadius: 20, justifyContent: 'center', paddingHorizontal: 14, backgroundColor: palette.input}}>
|
|
89
|
+
<Text style={{color: palette.danger}}>● Gravando… toque em ■ para enviar</Text>
|
|
90
|
+
</View>
|
|
91
|
+
) : (
|
|
92
|
+
<TextInput
|
|
93
|
+
style={{
|
|
94
|
+
flex: 1,
|
|
95
|
+
minHeight: 40,
|
|
96
|
+
maxHeight: 140,
|
|
97
|
+
borderRadius: 20,
|
|
98
|
+
borderWidth: 1,
|
|
99
|
+
borderColor: palette.inputBorder,
|
|
100
|
+
backgroundColor: palette.input,
|
|
101
|
+
color: palette.inputText,
|
|
102
|
+
paddingHorizontal: 14,
|
|
103
|
+
paddingVertical: 9,
|
|
104
|
+
fontSize: 15,
|
|
105
|
+
}}
|
|
106
|
+
value={text}
|
|
107
|
+
onChangeText={setText}
|
|
108
|
+
onKeyPress={onKeyPress}
|
|
109
|
+
placeholder={placeholder}
|
|
110
|
+
placeholderTextColor={palette.placeholder}
|
|
111
|
+
multiline
|
|
112
|
+
editable={!sending}
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
{audio.recording ? (
|
|
116
|
+
<TouchableOpacity style={[iconBtn, {backgroundColor: palette.chip}]} onPress={() => audio.cancel()} accessibilityLabel="Cancelar gravação">
|
|
117
|
+
<Text style={{color: palette.danger, fontWeight: '700'}}>✕</Text>
|
|
118
|
+
</TouchableOpacity>
|
|
119
|
+
) : null}
|
|
120
|
+
<TouchableOpacity
|
|
121
|
+
style={[iconBtn, {backgroundColor: palette.chipActive}]}
|
|
122
|
+
onPress={hasContent && !audio.recording ? () => send() : toggleRecording}
|
|
123
|
+
disabled={sending}
|
|
124
|
+
accessibilityLabel={hasContent ? 'Enviar' : audio.recording ? 'Parar e enviar áudio' : 'Gravar áudio'}>
|
|
125
|
+
{sending ? (
|
|
126
|
+
<ActivityIndicator color={palette.chipActiveText} />
|
|
127
|
+
) : (
|
|
128
|
+
<Text style={{color: palette.chipActiveText, fontSize: 18}}>{hasContent && !audio.recording ? '➤' : audio.recording ? '■' : '🎤'}</Text>
|
|
129
|
+
)}
|
|
130
|
+
</TouchableOpacity>
|
|
131
|
+
</View>
|
|
132
|
+
</View>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Shared conversation (requests screen, Support and CRM): header slot, messages grouped by
|
|
3
|
+
* day with WhatsApp-like bubbles, and the composer. Uploads happen here: `onSend({text, fileId})`.
|
|
4
|
+
* `describe(item)` returns {side: 'left'|'right', kind: 'note'|'ai'|'msg'|'hidden', author}.
|
|
5
|
+
*/
|
|
6
|
+
import React, {useMemo, useRef} from 'react';
|
|
7
|
+
import {ActivityIndicator, FlatList, KeyboardAvoidingView, Platform, Text, View} from 'react-native';
|
|
8
|
+
import Composer from './Composer';
|
|
9
|
+
import MessageBubble from './MessageBubble';
|
|
10
|
+
import useChatPalette from './useChatPalette';
|
|
11
|
+
import {uploadAttachment} from './fileApi';
|
|
12
|
+
|
|
13
|
+
const {dayLabel} = require('./formatText');
|
|
14
|
+
|
|
15
|
+
const keyOf = item => String(item?.id || item?.['@id'] || item?.localId);
|
|
16
|
+
|
|
17
|
+
export default function ConversationView({
|
|
18
|
+
header,
|
|
19
|
+
messages,
|
|
20
|
+
loading,
|
|
21
|
+
describe,
|
|
22
|
+
onSend,
|
|
23
|
+
uploadCompanyId,
|
|
24
|
+
placeholder = 'Mensagem',
|
|
25
|
+
canSend = true,
|
|
26
|
+
disabledText = '',
|
|
27
|
+
composerTop = null,
|
|
28
|
+
emptyText = 'Nenhuma mensagem ainda.',
|
|
29
|
+
footer = null,
|
|
30
|
+
onError,
|
|
31
|
+
}) {
|
|
32
|
+
const palette = useChatPalette();
|
|
33
|
+
const listRef = useRef(null);
|
|
34
|
+
|
|
35
|
+
const rows = useMemo(() => {
|
|
36
|
+
const out = [];
|
|
37
|
+
let lastDay = '';
|
|
38
|
+
let lastAuthor = '';
|
|
39
|
+
(messages || []).forEach(item => {
|
|
40
|
+
const meta = describe(item);
|
|
41
|
+
if (meta.kind === 'hidden') return;
|
|
42
|
+
const day = dayLabel(item?.createdAt);
|
|
43
|
+
if (day && day !== lastDay) {
|
|
44
|
+
out.push({type: 'day', key: `day-${day}-${keyOf(item)}`, label: day});
|
|
45
|
+
lastDay = day;
|
|
46
|
+
lastAuthor = '';
|
|
47
|
+
}
|
|
48
|
+
const authorKey = `${meta.side}|${meta.author}|${meta.kind}`;
|
|
49
|
+
out.push({type: 'msg', key: keyOf(item), item, meta, showAuthor: authorKey !== lastAuthor});
|
|
50
|
+
lastAuthor = authorKey;
|
|
51
|
+
});
|
|
52
|
+
return out;
|
|
53
|
+
}, [messages, describe]);
|
|
54
|
+
|
|
55
|
+
const send = async ({text, file}) => {
|
|
56
|
+
const fileId = file ? await uploadAttachment(file, uploadCompanyId) : null;
|
|
57
|
+
return onSend({text, fileId});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const renderRow = ({item: row}) =>
|
|
61
|
+
row.type === 'day' ? (
|
|
62
|
+
<View style={{alignItems: 'center', marginVertical: 8}}>
|
|
63
|
+
<Text style={{backgroundColor: palette.chip, color: palette.chipText, fontSize: 12, paddingHorizontal: 10, paddingVertical: 3, borderRadius: 8}}>
|
|
64
|
+
{row.label}
|
|
65
|
+
</Text>
|
|
66
|
+
</View>
|
|
67
|
+
) : (
|
|
68
|
+
<MessageBubble item={row.item} side={row.meta.side} kind={row.meta.kind} author={row.meta.author} showAuthor={row.showAuthor} palette={palette} />
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<KeyboardAvoidingView style={{flex: 1, minHeight: 0, backgroundColor: palette.background}} behavior={Platform.OS === 'ios' ? 'padding' : undefined} keyboardVerticalOffset={80}>
|
|
73
|
+
{header}
|
|
74
|
+
{loading ? (
|
|
75
|
+
<ActivityIndicator style={{marginTop: 24}} color={palette.primary} />
|
|
76
|
+
) : (
|
|
77
|
+
<FlatList
|
|
78
|
+
ref={listRef}
|
|
79
|
+
data={rows}
|
|
80
|
+
keyExtractor={row => row.key}
|
|
81
|
+
renderItem={renderRow}
|
|
82
|
+
contentContainerStyle={{paddingVertical: 8, flexGrow: 1}}
|
|
83
|
+
onContentSizeChange={() => listRef.current?.scrollToEnd?.({animated: false})}
|
|
84
|
+
ListEmptyComponent={<Text style={{color: palette.muted, textAlign: 'center', marginTop: 32, paddingHorizontal: 16}}>{emptyText}</Text>}
|
|
85
|
+
/>
|
|
86
|
+
)}
|
|
87
|
+
{footer}
|
|
88
|
+
<Composer palette={palette} placeholder={placeholder} disabled={!canSend} disabledText={disabledText} onSend={send} top={composerTop} onError={onError} />
|
|
89
|
+
</KeyboardAvoidingView>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents One message, WhatsApp-like: avatar + name for others, own messages on the right with
|
|
3
|
+
* time and delivery ticks, internal notes highlighted. Text uses RichText; files use Attachment.
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import {Text, View} from 'react-native';
|
|
7
|
+
import Attachment from './Attachment';
|
|
8
|
+
import RichText from './RichText';
|
|
9
|
+
|
|
10
|
+
const {initialsOf, timeLabel} = require('./formatText');
|
|
11
|
+
|
|
12
|
+
const TICKS = {pending: '🕓', processing: '🕓', done: '✓✓', error: '⚠'};
|
|
13
|
+
|
|
14
|
+
export default function MessageBubble({item, side, kind, author, showAuthor, palette}) {
|
|
15
|
+
const mine = side === 'right';
|
|
16
|
+
const note = kind === 'note';
|
|
17
|
+
const bg = note ? palette.noteBubble : mine ? palette.mineBubble : palette.otherBubble;
|
|
18
|
+
const fg = mine && !note ? palette.mineText : palette.otherText;
|
|
19
|
+
const body = String(item?.body || '');
|
|
20
|
+
// "Anexo" / "Anexo: name" only describes the file shown above it.
|
|
21
|
+
const isFileLabel = item?.file && /^Anexo(:|$)/.test(body);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<View style={{flexDirection: 'row', justifyContent: mine ? 'flex-end' : 'flex-start', marginVertical: 2, paddingHorizontal: 8}}>
|
|
25
|
+
{!mine ? (
|
|
26
|
+
<View
|
|
27
|
+
style={{
|
|
28
|
+
width: 32,
|
|
29
|
+
height: 32,
|
|
30
|
+
borderRadius: 16,
|
|
31
|
+
marginRight: 6,
|
|
32
|
+
marginTop: 2,
|
|
33
|
+
alignItems: 'center',
|
|
34
|
+
justifyContent: 'center',
|
|
35
|
+
backgroundColor: showAuthor ? palette.chipActive : 'transparent',
|
|
36
|
+
}}>
|
|
37
|
+
{showAuthor ? <Text style={{color: palette.chipActiveText, fontWeight: '700', fontSize: 12}}>{initialsOf(author)}</Text> : null}
|
|
38
|
+
</View>
|
|
39
|
+
) : null}
|
|
40
|
+
<View
|
|
41
|
+
style={{
|
|
42
|
+
maxWidth: '78%',
|
|
43
|
+
minWidth: 80,
|
|
44
|
+
backgroundColor: bg,
|
|
45
|
+
borderRadius: 12,
|
|
46
|
+
borderTopLeftRadius: !mine && showAuthor ? 2 : 12,
|
|
47
|
+
borderTopRightRadius: mine && showAuthor ? 2 : 12,
|
|
48
|
+
borderWidth: note ? 1 : 0,
|
|
49
|
+
borderColor: palette.noteBorder,
|
|
50
|
+
paddingHorizontal: 10,
|
|
51
|
+
paddingTop: 6,
|
|
52
|
+
paddingBottom: 4,
|
|
53
|
+
}}>
|
|
54
|
+
{showAuthor && (!mine || note) ? (
|
|
55
|
+
<Text style={{color: note ? palette.noteBorder : palette.chipActive, fontWeight: '700', fontSize: 12, marginBottom: 2}}>
|
|
56
|
+
{note ? `${author} · nota interna` : author}
|
|
57
|
+
</Text>
|
|
58
|
+
) : null}
|
|
59
|
+
{item?.file ? <Attachment file={item.file} color={fg} /> : null}
|
|
60
|
+
{body && !isFileLabel ? <RichText value={body} style={{color: fg, fontSize: 15, lineHeight: 20}} linkColor={fg} /> : null}
|
|
61
|
+
<View style={{flexDirection: 'row', justifyContent: 'flex-end', alignItems: 'center', gap: 4, marginTop: 2}}>
|
|
62
|
+
<Text style={{color: fg, opacity: 0.7, fontSize: 11}}>{timeLabel(item?.createdAt)}</Text>
|
|
63
|
+
{mine && !note ? <Text style={{color: item?.status === 'error' ? palette.danger : fg, opacity: 0.8, fontSize: 11}}>{TICKS[item?.status] || '✓'}</Text> : null}
|
|
64
|
+
</View>
|
|
65
|
+
</View>
|
|
66
|
+
</View>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Compact themed select: shows "Label: value"; opens a modal list. Read-only when no onChange.
|
|
3
|
+
*/
|
|
4
|
+
import React, {useState} from 'react';
|
|
5
|
+
import {Modal, Pressable, ScrollView, Text, TouchableOpacity, View} from 'react-native';
|
|
6
|
+
import useChatPalette from './useChatPalette';
|
|
7
|
+
|
|
8
|
+
export default function OptionPicker({label, value, options, onChange, placeholder = '—', disabled}) {
|
|
9
|
+
const palette = useChatPalette();
|
|
10
|
+
const [open, setOpen] = useState(false);
|
|
11
|
+
const current = options?.find(o => String(o.value) === String(value));
|
|
12
|
+
const editable = Boolean(onChange) && !disabled;
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<>
|
|
16
|
+
<TouchableOpacity
|
|
17
|
+
disabled={!editable}
|
|
18
|
+
onPress={() => setOpen(true)}
|
|
19
|
+
style={{
|
|
20
|
+
flexDirection: 'row',
|
|
21
|
+
alignItems: 'center',
|
|
22
|
+
gap: 4,
|
|
23
|
+
paddingHorizontal: 10,
|
|
24
|
+
paddingVertical: 5,
|
|
25
|
+
borderRadius: 14,
|
|
26
|
+
borderWidth: 1,
|
|
27
|
+
borderColor: palette.border,
|
|
28
|
+
backgroundColor: palette.chip,
|
|
29
|
+
marginRight: 6,
|
|
30
|
+
marginBottom: 6,
|
|
31
|
+
}}>
|
|
32
|
+
<Text style={{color: palette.muted, fontSize: 12}}>{label}:</Text>
|
|
33
|
+
<Text style={{color: palette.text, fontSize: 12, fontWeight: '600'}} numberOfLines={1}>
|
|
34
|
+
{current?.label || placeholder}
|
|
35
|
+
</Text>
|
|
36
|
+
{editable ? <Text style={{color: palette.muted, fontSize: 10}}>▾</Text> : null}
|
|
37
|
+
</TouchableOpacity>
|
|
38
|
+
<Modal visible={open} transparent animationType="fade" onRequestClose={() => setOpen(false)}>
|
|
39
|
+
<Pressable style={{flex: 1, backgroundColor: 'rgba(0,0,0,0.45)', justifyContent: 'center', padding: 24}} onPress={() => setOpen(false)}>
|
|
40
|
+
<Pressable style={{backgroundColor: palette.panel, borderRadius: 12, maxHeight: '75%', paddingVertical: 8, borderWidth: 1, borderColor: palette.border}}>
|
|
41
|
+
<Text style={{color: palette.text, fontWeight: '700', fontSize: 16, paddingHorizontal: 16, paddingVertical: 8}}>{label}</Text>
|
|
42
|
+
<ScrollView>
|
|
43
|
+
{(options || []).map(option => (
|
|
44
|
+
<TouchableOpacity
|
|
45
|
+
key={String(option.value)}
|
|
46
|
+
onPress={() => {
|
|
47
|
+
setOpen(false);
|
|
48
|
+
if (String(option.value) !== String(value)) onChange(option.value, option);
|
|
49
|
+
}}
|
|
50
|
+
style={{paddingHorizontal: 16, paddingVertical: 12, backgroundColor: String(option.value) === String(value) ? palette.chip : 'transparent'}}>
|
|
51
|
+
<Text style={{color: palette.text}}>{option.label}</Text>
|
|
52
|
+
{option.hint ? <Text style={{color: palette.muted, fontSize: 12}}>{option.hint}</Text> : null}
|
|
53
|
+
</TouchableOpacity>
|
|
54
|
+
))}
|
|
55
|
+
{!options?.length ? <Text style={{color: palette.muted, padding: 16}}>Nenhuma opção disponível.</Text> : null}
|
|
56
|
+
</ScrollView>
|
|
57
|
+
</Pressable>
|
|
58
|
+
</Pressable>
|
|
59
|
+
</Modal>
|
|
60
|
+
</>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Renders a message body with WhatsApp-like formatting (see formatText.js).
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import {Linking, Platform, Text} from 'react-native';
|
|
6
|
+
|
|
7
|
+
const {parseRichText} = require('./formatText');
|
|
8
|
+
|
|
9
|
+
export default function RichText({value, style, linkColor}) {
|
|
10
|
+
const lines = parseRichText(value);
|
|
11
|
+
return (
|
|
12
|
+
<Text style={style} selectable>
|
|
13
|
+
{lines.map((parts, li) => (
|
|
14
|
+
<Text key={li}>
|
|
15
|
+
{parts.map((p, pi) => (
|
|
16
|
+
<Text
|
|
17
|
+
key={pi}
|
|
18
|
+
onPress={p.link ? () => Linking.openURL(p.link) : undefined}
|
|
19
|
+
style={[
|
|
20
|
+
p.bold && {fontWeight: '700'},
|
|
21
|
+
p.italic && {fontStyle: 'italic'},
|
|
22
|
+
p.strike && {textDecorationLine: 'line-through'},
|
|
23
|
+
p.code && {fontFamily: Platform.OS === 'ios' ? 'Menlo' : 'monospace'},
|
|
24
|
+
p.link && {color: linkColor, textDecorationLine: 'underline'},
|
|
25
|
+
]}>
|
|
26
|
+
{p.text}
|
|
27
|
+
</Text>
|
|
28
|
+
))}
|
|
29
|
+
{li < lines.length - 1 ? '\n' : null}
|
|
30
|
+
</Text>
|
|
31
|
+
))}
|
|
32
|
+
</Text>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Attachments of the conversation: upload through /files/upload (owner = company) and
|
|
3
|
+
* authenticated download (files are private: an <img> cannot send the API token, so web reads a blob).
|
|
4
|
+
*/
|
|
5
|
+
import {Platform} from 'react-native';
|
|
6
|
+
import {env as APP_ENV} from '@env';
|
|
7
|
+
import {api} from '@controleonline/ui-common/src/api';
|
|
8
|
+
import {selectFile, uploadFileToApi} from '@controleonline/ui-default/src/react/components/upload/fileUpload';
|
|
9
|
+
|
|
10
|
+
export {selectFile};
|
|
11
|
+
|
|
12
|
+
export const fileIdOf = value => {
|
|
13
|
+
if (!value && value !== 0) return null;
|
|
14
|
+
if (typeof value === 'number') return value;
|
|
15
|
+
const raw = typeof value === 'string' ? value : value?.['@id'] || value?.id;
|
|
16
|
+
const match = String(raw || '').match(/(\d+)$/);
|
|
17
|
+
return match ? Number(match[1]) : null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const uploadAttachment = async (file, companyId) => {
|
|
21
|
+
const result = await uploadFileToApi({file, context: 'tasks', peopleId: companyId});
|
|
22
|
+
const id = fileIdOf(result?.['@id'] || result?.id || result?.file);
|
|
23
|
+
if (!id) throw new Error('Falha no upload do arquivo.');
|
|
24
|
+
return id;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const session = () => {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(localStorage.getItem('session') || '{}');
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const authHeaders = () => ({
|
|
36
|
+
'API-TOKEN': session()?.api_key || session()?.token || '',
|
|
37
|
+
'App-Domain': APP_ENV?.DOMAIN || (typeof location !== 'undefined' ? location.host : ''),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const downloadUrl = id => `${String(APP_ENV?.API_ENTRYPOINT || '').replace(/\/$/, '')}/files/${id}/download`;
|
|
41
|
+
|
|
42
|
+
const metaCache = new Map();
|
|
43
|
+
|
|
44
|
+
/** {fileName, fileType, extension} — cached; null when the user cannot read it. */
|
|
45
|
+
export const fetchFileMeta = async id => {
|
|
46
|
+
if (!id) return null;
|
|
47
|
+
if (!metaCache.has(id)) {
|
|
48
|
+
metaCache.set(id, api.fetch(`/files/${id}`).catch(() => null));
|
|
49
|
+
}
|
|
50
|
+
return metaCache.get(id);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const blobCache = new Map();
|
|
54
|
+
|
|
55
|
+
/** Web: object URL of the file (cached per id). Native: {uri, headers} source. */
|
|
56
|
+
export const fileSource = async id => {
|
|
57
|
+
if (Platform.OS !== 'web') return {uri: downloadUrl(id), headers: authHeaders()};
|
|
58
|
+
if (!blobCache.has(id)) {
|
|
59
|
+
blobCache.set(
|
|
60
|
+
id,
|
|
61
|
+
fetch(downloadUrl(id), {headers: authHeaders()})
|
|
62
|
+
.then(res => (res.ok ? res.blob() : Promise.reject(new Error(`HTTP ${res.status}`))))
|
|
63
|
+
.then(blob => ({uri: URL.createObjectURL(blob), type: blob.type}))
|
|
64
|
+
.catch(error => {
|
|
65
|
+
blobCache.delete(id);
|
|
66
|
+
throw error;
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return blobCache.get(id);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const kindOf = (meta, mime = '') => {
|
|
74
|
+
const type = String(meta?.fileType || mime.split('/')[0] || '').toLowerCase();
|
|
75
|
+
if (type === 'image') return 'image';
|
|
76
|
+
if (type === 'audio' || /\.(webm|m4a|mp3|ogg|wav|aac)$/i.test(meta?.fileName || '')) return 'audio';
|
|
77
|
+
return 'file';
|
|
78
|
+
};
|