@controleonline/ui-crm 1.0.62 → 1.0.65
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 +6 -5
- package/package.json +1 -1
- package/src/react/pages/crm/components/CrmHeader.js +6 -0
- package/src/react/pages/crm/index.js +1 -0
- package/src/react/pages/mcp/McpPage.js +130 -308
- package/src/react/pages/mcp/McpPage.styles.js +16 -1
- package/src/react/pages/mcp/mcpChatUtils.js +123 -0
- package/src/react/pages/mcp/useMcpChat.js +276 -0
- package/src/react/pages/proposals/ProposalDetails.styles.js +1 -1
- package/src/react/pages/tickets/AssignAiModal.js +51 -0
- package/src/react/pages/tickets/TicketConversationPage.js +171 -0
- package/src/react/pages/tickets/TicketFunnelPage.js +141 -0
- package/src/react/pages/tickets/ticketApi.js +38 -0
- package/src/react/pages/tickets/ticketUtils.js +81 -0
- package/src/react/pages/tickets/tickets.styles.js +61 -0
- package/src/react/pages/tickets/useRealtimeReload.js +28 -0
- package/src/react/router/routes.js +44 -0
- package/src/tests/react/pages/mcp/mcpChatUtils.test.js +73 -0
- package/src/tests/react/pages/tickets/ticketUtils.test.js +43 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Kanban funnel for customer tickets (type relationship = CRM, support = Suporte).
|
|
3
|
+
* First column "Triagem IA" = customer conversations the AI has not classified yet.
|
|
4
|
+
* Cards: move stage, put the AI on the ticket, open the conversation. Live via websocket events.
|
|
5
|
+
*/
|
|
6
|
+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
7
|
+
import {ActivityIndicator, ScrollView, Text, TextInput, TouchableOpacity, View} from 'react-native';
|
|
8
|
+
import {useNavigation} from '@react-navigation/native';
|
|
9
|
+
import {useStore} from '@store';
|
|
10
|
+
import useToastMessage from '../../hooks/useToastMessage';
|
|
11
|
+
import AssignAiModal from './AssignAiModal';
|
|
12
|
+
import useRealtimeReload from './useRealtimeReload';
|
|
13
|
+
import {assignAi, fetchStatuses, fetchTickets, fetchTriage, moveTicket} from './ticketApi';
|
|
14
|
+
import styles from './tickets.styles';
|
|
15
|
+
|
|
16
|
+
const {idOf, conversationChannel} = require('../mcp/mcpChatUtils');
|
|
17
|
+
const {TICKET_TYPES, buildColumns, neighbourStatus, personName, timeAgo} = require('./ticketUtils');
|
|
18
|
+
|
|
19
|
+
const CHANNEL_LABELS = {whatsapp: 'WhatsApp', email: 'E-mail', web: 'Site'};
|
|
20
|
+
|
|
21
|
+
const TicketCard = ({task, columns, onMove, onAssign, onOpen}) => {
|
|
22
|
+
const previous = neighbourStatus(columns, task, -1);
|
|
23
|
+
const next = neighbourStatus(columns, task, 1);
|
|
24
|
+
const channel = conversationChannel(task);
|
|
25
|
+
return (
|
|
26
|
+
<TouchableOpacity style={styles.card} onPress={() => onOpen(task)}>
|
|
27
|
+
<Text style={styles.cardTitle} numberOfLines={2}>{task.name || `#${idOf(task)}`}</Text>
|
|
28
|
+
<Text style={styles.cardMeta} numberOfLines={1}>
|
|
29
|
+
{[personName(task.client), timeAgo(task.alterDate)].filter(Boolean).join(' · ')}
|
|
30
|
+
</Text>
|
|
31
|
+
<View style={styles.badges}>
|
|
32
|
+
{task.aiAgent ? <View style={[styles.badge, styles.badgeAi]}><Text style={styles.badgeText}>IA atendendo</Text></View> : null}
|
|
33
|
+
{CHANNEL_LABELS[channel] ? <View style={styles.badge}><Text style={styles.badgeText}>{CHANNEL_LABELS[channel]}</Text></View> : null}
|
|
34
|
+
</View>
|
|
35
|
+
<View style={styles.cardActions}>
|
|
36
|
+
{previous ? <TouchableOpacity style={styles.iconBtn} onPress={() => onMove(task, previous)}><Text style={styles.iconBtnText}>◀</Text></TouchableOpacity> : null}
|
|
37
|
+
{next ? <TouchableOpacity style={styles.iconBtn} onPress={() => onMove(task, next)}><Text style={styles.iconBtnText}>▶</Text></TouchableOpacity> : null}
|
|
38
|
+
{!task.aiAgent ? <TouchableOpacity style={styles.iconBtn} onPress={() => onAssign(task)}><Text style={styles.iconBtnText}>Atribuir IA</Text></TouchableOpacity> : null}
|
|
39
|
+
</View>
|
|
40
|
+
</TouchableOpacity>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default function TicketFunnelPage({type = 'relationship'}) {
|
|
45
|
+
const navigation = useNavigation();
|
|
46
|
+
const {showError, showSuccess} = useToastMessage();
|
|
47
|
+
const peopleStore = useStore('people');
|
|
48
|
+
const companyId = idOf(peopleStore?.getters?.currentCompany || peopleStore?.getters?.mainCompany);
|
|
49
|
+
const meta = TICKET_TYPES[type] || TICKET_TYPES.relationship;
|
|
50
|
+
|
|
51
|
+
const [statuses, setStatuses] = useState([]);
|
|
52
|
+
const [tickets, setTickets] = useState([]);
|
|
53
|
+
const [triage, setTriage] = useState([]);
|
|
54
|
+
const [loading, setLoading] = useState(true);
|
|
55
|
+
const [search, setSearch] = useState('');
|
|
56
|
+
const [assigning, setAssigning] = useState(null);
|
|
57
|
+
|
|
58
|
+
const load = useCallback(async () => {
|
|
59
|
+
if (!companyId) return;
|
|
60
|
+
try {
|
|
61
|
+
const [s, t, tr] = await Promise.all([fetchStatuses(type), fetchTickets(type, companyId), fetchTriage(companyId)]);
|
|
62
|
+
setStatuses(s);
|
|
63
|
+
setTickets(t);
|
|
64
|
+
setTriage(tr);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
showError(e?.message || 'Falha ao carregar o funil');
|
|
67
|
+
} finally {
|
|
68
|
+
setLoading(false);
|
|
69
|
+
}
|
|
70
|
+
}, [companyId, type, showError]);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
load();
|
|
74
|
+
}, [load]);
|
|
75
|
+
useRealtimeReload(load);
|
|
76
|
+
|
|
77
|
+
const columns = useMemo(() => {
|
|
78
|
+
const q = search.trim().toLowerCase();
|
|
79
|
+
const match = t => !q || `${t.name || ''} ${personName(t.client)}`.toLowerCase().includes(q);
|
|
80
|
+
return buildColumns(statuses, tickets.filter(match), triage.filter(match));
|
|
81
|
+
}, [statuses, tickets, triage, search]);
|
|
82
|
+
|
|
83
|
+
const move = async (task, status) => {
|
|
84
|
+
setTickets(prev => prev.map(t => (idOf(t) === idOf(task) ? {...t, taskStatus: status} : t)));
|
|
85
|
+
try {
|
|
86
|
+
await moveTicket(task, status);
|
|
87
|
+
} catch (e) {
|
|
88
|
+
showError(e?.message || 'Não foi possível mover');
|
|
89
|
+
load();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const confirmAssign = async instructions => {
|
|
94
|
+
try {
|
|
95
|
+
await assignAi(idOf(assigning), companyId, instructions);
|
|
96
|
+
showSuccess('IA atribuída. Ela fará o primeiro contato com o cliente.');
|
|
97
|
+
setAssigning(null);
|
|
98
|
+
load();
|
|
99
|
+
} catch (e) {
|
|
100
|
+
showError(e?.message || 'Não foi possível atribuir a IA');
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const open = task => navigation.navigate('TicketConversation', {taskId: idOf(task)});
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<View style={styles.root}>
|
|
108
|
+
<View style={styles.header}>
|
|
109
|
+
<View style={styles.headerText}>
|
|
110
|
+
<Text style={styles.title}>{meta.title}</Text>
|
|
111
|
+
<Text style={styles.subtitle}>{`${tickets.length} tickets · ${triage.length} em triagem pela IA`}</Text>
|
|
112
|
+
</View>
|
|
113
|
+
<TextInput style={styles.search} value={search} onChangeText={setSearch} placeholder="Buscar cliente ou título" placeholderTextColor="#8b98a5" />
|
|
114
|
+
</View>
|
|
115
|
+
{loading ? (
|
|
116
|
+
<ActivityIndicator style={styles.spinner} />
|
|
117
|
+
) : (
|
|
118
|
+
<ScrollView horizontal style={styles.board} contentContainerStyle={styles.boardContent}>
|
|
119
|
+
{columns.map(column => (
|
|
120
|
+
<View key={column.key} style={[styles.column, {borderTopColor: column.color}]}>
|
|
121
|
+
<View style={styles.columnHeader}>
|
|
122
|
+
<Text style={styles.columnTitle}>{column.title}</Text>
|
|
123
|
+
<Text style={styles.columnCount}>{column.tasks.length}</Text>
|
|
124
|
+
</View>
|
|
125
|
+
<ScrollView style={styles.columnBody}>
|
|
126
|
+
{column.tasks.length === 0 ? <Text style={styles.emptyText}>{meta.empty}</Text> : null}
|
|
127
|
+
{column.tasks.map(task => (
|
|
128
|
+
<TicketCard key={String(idOf(task))} task={task} columns={columns} onMove={move} onAssign={setAssigning} onOpen={open} />
|
|
129
|
+
))}
|
|
130
|
+
</ScrollView>
|
|
131
|
+
</View>
|
|
132
|
+
))}
|
|
133
|
+
</ScrollView>
|
|
134
|
+
)}
|
|
135
|
+
<AssignAiModal visible={Boolean(assigning)} ticketName={assigning?.name} onCancel={() => setAssigning(null)} onConfirm={confirmAssign} />
|
|
136
|
+
</View>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const CrmFunnelPage = () => <TicketFunnelPage type="relationship" />;
|
|
141
|
+
export const SupportFunnelPage = () => <TicketFunnelPage type="support" />;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents API calls shared by funnels and ticket screens.
|
|
3
|
+
*/
|
|
4
|
+
import {api} from '@controleonline/ui-common/src/api';
|
|
5
|
+
|
|
6
|
+
const {idOf} = require('../mcp/mcpChatUtils');
|
|
7
|
+
|
|
8
|
+
export const toItems = res => {
|
|
9
|
+
const items = res?.member || res?.['hydra:member'] || res || [];
|
|
10
|
+
return Array.isArray(items) ? items : [];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const fetchStatuses = async type => toItems(await api.fetch('/statuses', {params: {context: type, itemsPerPage: 100}}));
|
|
14
|
+
|
|
15
|
+
export const fetchTickets = async (type, companyId) =>
|
|
16
|
+
toItems(await api.fetch('/tasks', {params: {type, provider: `/people/${companyId}`, 'order[alterDate]': 'desc', itemsPerPage: 300}}));
|
|
17
|
+
|
|
18
|
+
// Customer conversations the AI is still triaging (internal /ai chats are filtered out by the caller).
|
|
19
|
+
export const fetchTriage = async companyId =>
|
|
20
|
+
toItems(await api.fetch('/tasks', {params: {type: 'ia', provider: `/people/${companyId}`, 'exists[aiAgent]': true, itemsPerPage: 100}}));
|
|
21
|
+
|
|
22
|
+
export const fetchTicket = taskId => api.fetch(`/tasks/${taskId}`);
|
|
23
|
+
|
|
24
|
+
export const fetchTicketMessages = async taskId =>
|
|
25
|
+
toItems(await api.fetch('/task_interations', {params: {'task.id': taskId, type: 'comment', 'order[id]': 'asc', itemsPerPage: 300}}));
|
|
26
|
+
|
|
27
|
+
export const moveTicket = (task, status) =>
|
|
28
|
+
api.put(`/tasks/${idOf(task)}`, {taskStatus: status?.['@id'] || `/statuses/${idOf(status)}`});
|
|
29
|
+
|
|
30
|
+
/** public = goes to the customer through the ticket's connection; private = internal note. */
|
|
31
|
+
export const postTicketMessage = (taskId, body, visibility) =>
|
|
32
|
+
api.post('/task_interations', {task: `/tasks/${taskId}`, body, type: 'comment', visibility});
|
|
33
|
+
|
|
34
|
+
export const assignAi = (taskId, companyId, instructions) =>
|
|
35
|
+
api.post('/mcp/chat/assign', {task_id: taskId, company_id: companyId, instructions});
|
|
36
|
+
|
|
37
|
+
export const takeOverTicket = (taskId, companyId, type) =>
|
|
38
|
+
api.post('/mcp/chat/handoff', {task_id: taskId, company_id: companyId, type});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Pure helpers for CRM / Support funnels and ticket screens.
|
|
3
|
+
* Covered by src/tests/react/pages/tickets/ticketUtils.test.js.
|
|
4
|
+
*/
|
|
5
|
+
const {idOf, isCustomerConversation} = require('../mcp/mcpChatUtils');
|
|
6
|
+
|
|
7
|
+
const TRIAGE_COLUMN = 'triage';
|
|
8
|
+
|
|
9
|
+
const TICKET_TYPES = {
|
|
10
|
+
relationship: {title: 'Funil comercial', label: 'Comercial', empty: 'Nenhuma oportunidade.'},
|
|
11
|
+
support: {title: 'Suporte', label: 'Suporte', empty: 'Nenhum chamado.'},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const statusOrder = status => {
|
|
15
|
+
const real = String(status?.realStatus || '').toLowerCase();
|
|
16
|
+
const rank = {open: 0, pending: 1, closed: 2, canceled: 3};
|
|
17
|
+
return [rank[real] ?? 1, idOf(status) || 0];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Columns: "Triagem IA" (customer conversations still unclassified) + one per status of the context,
|
|
22
|
+
* open stages first and closed/canceled last.
|
|
23
|
+
*/
|
|
24
|
+
const buildColumns = (statuses, tasks, triage = []) => {
|
|
25
|
+
const sorted = [...(statuses || [])].sort((a, b) => {
|
|
26
|
+
const [ra, ia] = statusOrder(a);
|
|
27
|
+
const [rb, ib] = statusOrder(b);
|
|
28
|
+
return ra - rb || ia - ib;
|
|
29
|
+
});
|
|
30
|
+
const columns = [
|
|
31
|
+
{key: TRIAGE_COLUMN, title: 'Triagem IA', color: '#7c3aed', status: null, tasks: (triage || []).filter(isCustomerConversation)},
|
|
32
|
+
];
|
|
33
|
+
sorted.forEach(status => {
|
|
34
|
+
columns.push({
|
|
35
|
+
key: String(idOf(status)),
|
|
36
|
+
title: status.status || status.name || `#${idOf(status)}`,
|
|
37
|
+
color: status.color || '#1d9bf0',
|
|
38
|
+
status,
|
|
39
|
+
tasks: [],
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
const byStatus = new Map(columns.map(c => [c.key, c]));
|
|
43
|
+
(tasks || []).forEach(task => {
|
|
44
|
+
const column = byStatus.get(String(idOf(task.taskStatus)));
|
|
45
|
+
if (column && column.key !== TRIAGE_COLUMN) column.tasks.push(task);
|
|
46
|
+
});
|
|
47
|
+
return columns;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** Neighbour status column for the arrow buttons (never into/out of triage). */
|
|
51
|
+
const neighbourStatus = (columns, task, step) => {
|
|
52
|
+
const stages = columns.filter(c => c.status);
|
|
53
|
+
const index = stages.findIndex(c => c.key === String(idOf(task?.taskStatus)));
|
|
54
|
+
if (index < 0) return null;
|
|
55
|
+
return stages[index + step]?.status || null;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const personName = people => {
|
|
59
|
+
if (!people) return '';
|
|
60
|
+
if (typeof people === 'string') return '';
|
|
61
|
+
return people.name || people.alias || '';
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const timeAgo = (value, now = Date.now()) => {
|
|
65
|
+
const t = new Date(value || 0).getTime();
|
|
66
|
+
if (!t) return '';
|
|
67
|
+
const minutes = Math.max(0, Math.round((now - t) / 60000));
|
|
68
|
+
if (minutes < 60) return `${minutes} min`;
|
|
69
|
+
const hours = Math.round(minutes / 60);
|
|
70
|
+
if (hours < 48) return `${hours} h`;
|
|
71
|
+
return `${Math.round(hours / 24)} d`;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
module.exports = {
|
|
75
|
+
TRIAGE_COLUMN,
|
|
76
|
+
TICKET_TYPES,
|
|
77
|
+
buildColumns,
|
|
78
|
+
neighbourStatus,
|
|
79
|
+
personName,
|
|
80
|
+
timeAgo,
|
|
81
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {StyleSheet} from 'react-native';
|
|
2
|
+
|
|
3
|
+
// Same dark palette as /ai.
|
|
4
|
+
export default StyleSheet.create({
|
|
5
|
+
root: {flex: 1, backgroundColor: '#0f1419'},
|
|
6
|
+
header: {flexDirection: 'row', alignItems: 'center', gap: 8, padding: 12, borderBottomWidth: 1, borderBottomColor: '#2a3441'},
|
|
7
|
+
headerText: {flex: 1, minWidth: 0},
|
|
8
|
+
title: {color: '#e7e9ea', fontSize: 18, fontWeight: '700'},
|
|
9
|
+
subtitle: {color: '#8b98a5', fontSize: 12, marginTop: 2},
|
|
10
|
+
search: {minWidth: 180, maxWidth: 280, flex: 1, borderWidth: 1, borderColor: '#38444d', borderRadius: 10, paddingHorizontal: 10, paddingVertical: 6, color: '#e7e9ea'},
|
|
11
|
+
board: {flex: 1},
|
|
12
|
+
boardContent: {padding: 12, gap: 12},
|
|
13
|
+
column: {width: 290, backgroundColor: '#15202b', borderRadius: 12, borderTopWidth: 3, maxHeight: '100%'},
|
|
14
|
+
columnHeader: {flexDirection: 'row', justifyContent: 'space-between', padding: 10},
|
|
15
|
+
columnTitle: {color: '#e7e9ea', fontWeight: '700', fontSize: 13, textTransform: 'capitalize'},
|
|
16
|
+
columnCount: {color: '#8b98a5', fontSize: 12},
|
|
17
|
+
columnBody: {paddingHorizontal: 8, paddingBottom: 8},
|
|
18
|
+
card: {backgroundColor: '#1e2732', borderRadius: 10, padding: 10, marginBottom: 8},
|
|
19
|
+
cardTitle: {color: '#e7e9ea', fontSize: 13, fontWeight: '600'},
|
|
20
|
+
cardMeta: {color: '#8b98a5', fontSize: 11, marginTop: 4},
|
|
21
|
+
badges: {flexDirection: 'row', flexWrap: 'wrap', gap: 4, marginTop: 6},
|
|
22
|
+
badge: {borderRadius: 6, paddingHorizontal: 6, paddingVertical: 2, backgroundColor: '#2a3441'},
|
|
23
|
+
badgeAi: {backgroundColor: '#4c1d95'},
|
|
24
|
+
badgeText: {color: '#e7e9ea', fontSize: 10, fontWeight: '600'},
|
|
25
|
+
cardActions: {flexDirection: 'row', gap: 6, marginTop: 8},
|
|
26
|
+
iconBtn: {borderWidth: 1, borderColor: '#38444d', borderRadius: 8, paddingHorizontal: 8, paddingVertical: 4},
|
|
27
|
+
iconBtnText: {color: '#e7e9ea', fontSize: 12},
|
|
28
|
+
emptyText: {color: '#8b98a5', fontSize: 12, padding: 8},
|
|
29
|
+
spinner: {marginTop: 24},
|
|
30
|
+
// ticket screen
|
|
31
|
+
messages: {padding: 12, paddingBottom: 24},
|
|
32
|
+
bubble: {maxWidth: '80%', borderRadius: 12, paddingHorizontal: 12, paddingVertical: 8, marginVertical: 4},
|
|
33
|
+
bubbleLeft: {alignSelf: 'flex-start', backgroundColor: '#1f3a2b'},
|
|
34
|
+
bubbleAi: {alignSelf: 'flex-start', backgroundColor: '#212a33'},
|
|
35
|
+
bubbleRight: {alignSelf: 'flex-end', backgroundColor: '#1d9bf0'},
|
|
36
|
+
bubbleNote: {alignSelf: 'center', backgroundColor: '#3a2f12', borderWidth: 1, borderColor: '#8a6d1d'},
|
|
37
|
+
bubbleAuthor: {color: '#c9d1d9', fontSize: 11, fontWeight: '700', marginBottom: 2},
|
|
38
|
+
bubbleText: {color: '#e7e9ea', fontSize: 14, lineHeight: 20},
|
|
39
|
+
bubbleMeta: {color: '#c9d1d9', fontSize: 10, marginTop: 4, opacity: 0.8},
|
|
40
|
+
composer: {padding: 10, borderTopWidth: 1, borderTopColor: '#2a3441', gap: 8},
|
|
41
|
+
modeRow: {flexDirection: 'row', gap: 6},
|
|
42
|
+
modeChip: {borderWidth: 1, borderColor: '#38444d', borderRadius: 14, paddingHorizontal: 10, paddingVertical: 4},
|
|
43
|
+
modeChipActive: {backgroundColor: '#1d9bf0', borderColor: '#1d9bf0'},
|
|
44
|
+
modeChipNote: {backgroundColor: '#8a6d1d', borderColor: '#8a6d1d'},
|
|
45
|
+
modeChipText: {color: '#e7e9ea', fontSize: 12},
|
|
46
|
+
composerRow: {flexDirection: 'row', alignItems: 'flex-end', gap: 8},
|
|
47
|
+
input: {flex: 1, minHeight: 40, maxHeight: 140, borderWidth: 1, borderColor: '#38444d', borderRadius: 12, paddingHorizontal: 12, paddingVertical: 8, color: '#e7e9ea', backgroundColor: '#15202b'},
|
|
48
|
+
primaryBtn: {backgroundColor: '#1d9bf0', borderRadius: 10, paddingHorizontal: 14, paddingVertical: 10, alignItems: 'center', justifyContent: 'center'},
|
|
49
|
+
primaryBtnText: {color: '#fff', fontWeight: '700'},
|
|
50
|
+
ghostBtn: {borderWidth: 1, borderColor: '#1d9bf0', borderRadius: 10, paddingHorizontal: 12, paddingVertical: 8},
|
|
51
|
+
ghostBtnText: {color: '#1d9bf0', fontWeight: '600', fontSize: 12},
|
|
52
|
+
aiBar: {flexDirection: 'row', alignItems: 'center', gap: 8, paddingHorizontal: 12, paddingVertical: 8, backgroundColor: '#1b1530', borderBottomWidth: 1, borderBottomColor: '#2a3441'},
|
|
53
|
+
aiBarText: {flex: 1, color: '#d8ccff', fontSize: 12},
|
|
54
|
+
// modal
|
|
55
|
+
modalBackdrop: {flex: 1, backgroundColor: 'rgba(0,0,0,0.6)', justifyContent: 'center', alignItems: 'center', padding: 16},
|
|
56
|
+
modalCard: {width: '100%', maxWidth: 480, backgroundColor: '#15202b', borderRadius: 14, padding: 16, gap: 10},
|
|
57
|
+
modalTitle: {color: '#e7e9ea', fontSize: 16, fontWeight: '700'},
|
|
58
|
+
modalText: {color: '#8b98a5', fontSize: 13, lineHeight: 18},
|
|
59
|
+
modalInput: {minHeight: 90, flex: 0},
|
|
60
|
+
modalActions: {flexDirection: 'row', justifyContent: 'flex-end', gap: 8},
|
|
61
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents Calls `reload(events)` (debounced) whenever new conversation events arrive on the
|
|
3
|
+
* websocket store. Used by funnels and ticket screens; /ai has its own finer-grained handling.
|
|
4
|
+
*/
|
|
5
|
+
import {useEffect, useRef} from 'react';
|
|
6
|
+
import {useStore} from '@store';
|
|
7
|
+
|
|
8
|
+
const {extractChatEvents} = require('../mcp/mcpChatUtils');
|
|
9
|
+
|
|
10
|
+
export default function useRealtimeReload(reload, {filter = () => true, delay = 500} = {}) {
|
|
11
|
+
const websocketStore = useStore('websocket');
|
|
12
|
+
const messages = websocketStore?.getters?.messages;
|
|
13
|
+
const cursor = useRef(Array.isArray(messages) ? messages.length : 0);
|
|
14
|
+
const timer = useRef(null);
|
|
15
|
+
const reloadRef = useRef(reload);
|
|
16
|
+
reloadRef.current = reload;
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const {events, nextIndex} = extractChatEvents(messages, cursor.current);
|
|
20
|
+
cursor.current = nextIndex;
|
|
21
|
+
const relevant = events.filter(filter);
|
|
22
|
+
if (!relevant.length) return;
|
|
23
|
+
clearTimeout(timer.current);
|
|
24
|
+
timer.current = setTimeout(() => reloadRef.current(relevant), delay);
|
|
25
|
+
}, [messages, filter, delay]);
|
|
26
|
+
|
|
27
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
28
|
+
}
|
|
@@ -8,6 +8,8 @@ import CrmConversation from '../pages/crm/conversation';
|
|
|
8
8
|
import GeneralSettings from '../pages/settings/GeneralSettings';
|
|
9
9
|
import McpPage from '../pages/mcp/McpPage';
|
|
10
10
|
import ProposalDetails from '../pages/proposals/ProposalDetails';
|
|
11
|
+
import {CrmFunnelPage, SupportFunnelPage} from '../pages/tickets/TicketFunnelPage';
|
|
12
|
+
import TicketConversationPage from '../pages/tickets/TicketConversationPage';
|
|
11
13
|
|
|
12
14
|
const crmRoutes = [
|
|
13
15
|
{
|
|
@@ -144,6 +146,48 @@ const crmRoutes = [
|
|
|
144
146
|
title: 'Conversas',
|
|
145
147
|
},
|
|
146
148
|
},
|
|
149
|
+
{
|
|
150
|
+
// Kanban of CRM opportunities (+ AI triage column).
|
|
151
|
+
name: 'CrmFunnel',
|
|
152
|
+
component: CrmFunnelPage,
|
|
153
|
+
path: 'crm/funil',
|
|
154
|
+
options: {
|
|
155
|
+
showCompanyFilter: true,
|
|
156
|
+
showBottomToolBar: true,
|
|
157
|
+
headerShown: true,
|
|
158
|
+
headerBackVisible: true,
|
|
159
|
+
companyFilterMode: 'icon',
|
|
160
|
+
title: 'Funil comercial',
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
// Support tickets funnel (clone of the CRM funnel for type=support).
|
|
165
|
+
name: 'SupportFunnel',
|
|
166
|
+
component: SupportFunnelPage,
|
|
167
|
+
path: 'suporte',
|
|
168
|
+
options: {
|
|
169
|
+
showCompanyFilter: true,
|
|
170
|
+
showBottomToolBar: true,
|
|
171
|
+
headerShown: true,
|
|
172
|
+
headerBackVisible: true,
|
|
173
|
+
companyFilterMode: 'icon',
|
|
174
|
+
title: 'Suporte',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
// One customer ticket (ia/relationship/support): conversation, notes, AI.
|
|
179
|
+
name: 'TicketConversation',
|
|
180
|
+
component: TicketConversationPage,
|
|
181
|
+
path: 'ticket/:taskId',
|
|
182
|
+
options: {
|
|
183
|
+
showCompanyFilter: true,
|
|
184
|
+
showBottomToolBar: true,
|
|
185
|
+
headerShown: true,
|
|
186
|
+
headerBackVisible: true,
|
|
187
|
+
companyFilterMode: 'icon',
|
|
188
|
+
title: 'Atendimento',
|
|
189
|
+
},
|
|
190
|
+
},
|
|
147
191
|
];
|
|
148
192
|
|
|
149
193
|
export default crmRoutes;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const {test} = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
idOf,
|
|
6
|
+
isCustomerConversation,
|
|
7
|
+
customerPhone,
|
|
8
|
+
extractChatEvents,
|
|
9
|
+
mergeConversations,
|
|
10
|
+
messageRole,
|
|
11
|
+
stageLabel,
|
|
12
|
+
conversationChannel,
|
|
13
|
+
} = require('../../../../react/pages/mcp/mcpChatUtils');
|
|
14
|
+
|
|
15
|
+
const webTask = {id: 1, type: 'ia', announce: '{"channel":"mcp","ai_provider":"claude"}', registeredBy: '/people/10', alterDate: '2026-11-14T10:00:00'};
|
|
16
|
+
const otherUserTask = {id: 2, type: 'ia', announce: '{"channel":"mcp"}', registeredBy: '/people/11', alterDate: '2026-11-14T12:00:00'};
|
|
17
|
+
const whatsTask = {id: 3, type: 'relationship', announce: '["5511999998888","conn:4"]', client: '/people/50', registeredBy: '/people/50', alterDate: '2026-11-14T11:00:00'};
|
|
18
|
+
|
|
19
|
+
test('idOf reads numbers, IRIs and entities', () => {
|
|
20
|
+
assert.equal(idOf('/people/42'), 42);
|
|
21
|
+
assert.equal(idOf({'@id': '/tasks/7'}), 7);
|
|
22
|
+
assert.equal(idOf({id: '9'}), 9);
|
|
23
|
+
assert.equal(idOf(null), null);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('internal chats vs customer conversations and their channel', () => {
|
|
27
|
+
assert.equal(conversationChannel(webTask), 'ai');
|
|
28
|
+
assert.equal(conversationChannel(whatsTask), 'whatsapp');
|
|
29
|
+
assert.equal(conversationChannel({type: 'support', announce: '["ana@x.com","conn:9"]'}), 'email');
|
|
30
|
+
assert.equal(isCustomerConversation(webTask), false);
|
|
31
|
+
assert.equal(isCustomerConversation(whatsTask), true);
|
|
32
|
+
assert.equal(customerPhone(whatsTask), '5511999998888');
|
|
33
|
+
assert.equal(stageLabel(whatsTask), 'Comercial');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('extractChatEvents only returns new chat events and flattens batches', () => {
|
|
37
|
+
const store = [
|
|
38
|
+
{event: 'order_update'},
|
|
39
|
+
[{event: 'mcp_chat_reply', task_id: 1, status: 'processing'}, {event: 'mcp_chat_reply', task_id: 1, status: 'done'}],
|
|
40
|
+
];
|
|
41
|
+
const first = extractChatEvents(store, 0);
|
|
42
|
+
assert.deepEqual(first.events.map(e => e.status), ['processing', 'done']);
|
|
43
|
+
assert.equal(first.nextIndex, 2);
|
|
44
|
+
|
|
45
|
+
store.push({event: 'conversation_message', task_id: 3});
|
|
46
|
+
const second = extractChatEvents(store, first.nextIndex);
|
|
47
|
+
assert.deepEqual(second.events.map(e => e.task_id), [3]);
|
|
48
|
+
|
|
49
|
+
// store reset (shorter than our cursor) is re-read from the start
|
|
50
|
+
assert.equal(extractChatEvents([{event: 'mcp_chat_reply'}], 5).events.length, 1);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('mergeConversations hides other people internal chats, keeps customer ones, sorts by activity', () => {
|
|
54
|
+
const merged = mergeConversations([[webTask, otherUserTask], [whatsTask, webTask]], 10);
|
|
55
|
+
assert.deepEqual(merged.map(t => t.id), [3, 1]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('messageRole distinguishes ai, notes, customer and staff', () => {
|
|
59
|
+
const ctx = {companyId: 99, task: whatsTask, currentPeopleId: 10};
|
|
60
|
+
assert.equal(messageRole({registeredBy: '/people/99', visibility: 'public'}, ctx), 'ai');
|
|
61
|
+
assert.equal(messageRole({registeredBy: '/people/99', visibility: 'private'}, ctx), 'note');
|
|
62
|
+
assert.equal(messageRole({registeredBy: '/people/50'}, ctx), 'customer');
|
|
63
|
+
assert.equal(messageRole({registeredBy: '/people/10'}, ctx), 'me', 'my own reply');
|
|
64
|
+
assert.equal(messageRole({registeredBy: '/people/11'}, ctx), 'staff', 'a colleague');
|
|
65
|
+
|
|
66
|
+
const myTicket = {id: 9, type: 'support', announce: '["via:ai"]', client: '/people/10'};
|
|
67
|
+
assert.equal(messageRole({registeredBy: '/people/10'}, {companyId: 99, task: myTicket, currentPeopleId: 10}), 'me');
|
|
68
|
+
|
|
69
|
+
const webCtx = {companyId: 99, task: webTask, currentPeopleId: 10};
|
|
70
|
+
assert.equal(messageRole({registeredBy: '/people/99', visibility: 'private'}, webCtx), 'ai');
|
|
71
|
+
assert.equal(messageRole({registeredBy: '/people/10'}, webCtx), 'me');
|
|
72
|
+
assert.equal(messageRole({id: 'local-1'}, webCtx), 'me');
|
|
73
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const {test} = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
|
|
4
|
+
const {buildColumns, neighbourStatus, personName, timeAgo} = require('../../../../react/pages/tickets/ticketUtils');
|
|
5
|
+
|
|
6
|
+
const statuses = [
|
|
7
|
+
{'@id': '/statuses/30', status: 'ganho', realStatus: 'closed'},
|
|
8
|
+
{'@id': '/statuses/10', status: 'novo', realStatus: 'open'},
|
|
9
|
+
{'@id': '/statuses/20', status: 'proposta', realStatus: 'pending'},
|
|
10
|
+
];
|
|
11
|
+
const tasks = [
|
|
12
|
+
{id: 1, taskStatus: '/statuses/10'},
|
|
13
|
+
{id: 2, taskStatus: {'@id': '/statuses/20'}},
|
|
14
|
+
{id: 3, taskStatus: '/statuses/99'},
|
|
15
|
+
];
|
|
16
|
+
const triage = [
|
|
17
|
+
{id: 7, type: 'ia', announce: '["5511999998888","conn:1"]'},
|
|
18
|
+
{id: 8, type: 'ia', announce: '{"channel":"mcp"}'},
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
test('columns: triage first, open stages, closed last; tasks placed by status', () => {
|
|
22
|
+
const columns = buildColumns(statuses, tasks, triage);
|
|
23
|
+
assert.deepEqual(columns.map(c => c.title), ['Triagem IA', 'novo', 'proposta', 'ganho']);
|
|
24
|
+
assert.deepEqual(columns[0].tasks.map(t => t.id), [7], 'internal /ai chats never show in triage');
|
|
25
|
+
assert.deepEqual(columns[1].tasks.map(t => t.id), [1]);
|
|
26
|
+
assert.deepEqual(columns[2].tasks.map(t => t.id), [2]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('neighbourStatus moves between stages only', () => {
|
|
30
|
+
const columns = buildColumns(statuses, tasks, triage);
|
|
31
|
+
assert.equal(neighbourStatus(columns, tasks[0], 1)['@id'], '/statuses/20');
|
|
32
|
+
assert.equal(neighbourStatus(columns, tasks[0], -1), null);
|
|
33
|
+
assert.equal(neighbourStatus(columns, triage[0], 1), null);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('personName and timeAgo', () => {
|
|
37
|
+
assert.equal(personName({name: 'Maria'}), 'Maria');
|
|
38
|
+
assert.equal(personName('/people/1'), '');
|
|
39
|
+
const now = new Date('2026-11-14T12:00:00Z').getTime();
|
|
40
|
+
assert.equal(timeAgo('2026-11-14T11:30:00Z', now), '30 min');
|
|
41
|
+
assert.equal(timeAgo('2026-11-14T02:00:00Z', now), '10 h');
|
|
42
|
+
assert.equal(timeAgo('2026-11-10T12:00:00Z', now), '4 d');
|
|
43
|
+
});
|