412 lines
10 KiB
HTML
412 lines
10 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Support Dashboard</title>
|
|
<script src="https://unpkg.com/htmx.org@1.9.12"></script>
|
|
<style>
|
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
:root {
|
|
--bg: #0f1117;
|
|
--surface: #1a1d27;
|
|
--surface2: #20243a;
|
|
--border: #2a2d3a;
|
|
--accent: #6c63ff;
|
|
--accent-dim:#4a44b5;
|
|
--text: #e8e8f0;
|
|
--muted: #6b6e80;
|
|
--customer: #6c63ff;
|
|
--agent: #22c55e;
|
|
--radius: 10px;
|
|
}
|
|
|
|
html, body {
|
|
height: 100%;
|
|
background: var(--bg);
|
|
font-family: 'Inter', system-ui, sans-serif;
|
|
color: var(--text);
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* --- Layout --- */
|
|
.layout {
|
|
display: grid;
|
|
grid-template-columns: 280px 1fr;
|
|
grid-template-rows: 56px 1fr;
|
|
height: 100vh;
|
|
}
|
|
|
|
/* --- Top bar --- */
|
|
.topbar {
|
|
grid-column: 1 / -1;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
padding: 0 1.5rem;
|
|
border-bottom: 1px solid var(--border);
|
|
background: var(--surface);
|
|
}
|
|
|
|
.topbar-logo { font-size: 1.2rem; }
|
|
|
|
.topbar h1 {
|
|
font-size: 1rem;
|
|
font-weight: 700;
|
|
letter-spacing: -0.01em;
|
|
}
|
|
|
|
.topbar-badge {
|
|
margin-left: auto;
|
|
font-size: 0.75rem;
|
|
color: var(--muted);
|
|
background: var(--bg);
|
|
padding: 0.2rem 0.6rem;
|
|
border-radius: 20px;
|
|
border: 1px solid var(--border);
|
|
}
|
|
|
|
/* --- Sidebar --- */
|
|
.sidebar {
|
|
border-right: 1px solid var(--border);
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.sidebar-header {
|
|
padding: 1rem;
|
|
border-bottom: 1px solid var(--border);
|
|
font-size: 0.78rem;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.08em;
|
|
color: var(--muted);
|
|
}
|
|
|
|
#session-list {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 0.5rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.3rem;
|
|
}
|
|
|
|
#session-list::-webkit-scrollbar { width: 4px; }
|
|
#session-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
|
|
|
|
.session-item {
|
|
width: 100%;
|
|
text-align: left;
|
|
background: transparent;
|
|
border: 1px solid transparent;
|
|
border-radius: var(--radius);
|
|
padding: 0.7rem 0.8rem;
|
|
cursor: pointer;
|
|
color: var(--text);
|
|
font-size: 0.88rem;
|
|
transition: background 0.15s, border-color 0.15s;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.3rem;
|
|
}
|
|
|
|
.session-item:hover { background: var(--surface2); border-color: var(--border); }
|
|
.session-item.selected { background: var(--surface2); border-color: var(--accent); }
|
|
|
|
.session-name { font-weight: 600; }
|
|
|
|
.session-meta {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.session-badge {
|
|
font-size: 0.68rem;
|
|
padding: 0.15rem 0.5rem;
|
|
border-radius: 20px;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.04em;
|
|
}
|
|
|
|
.status-waiting { background: rgba(234, 179, 8, 0.15); color: #eab308; }
|
|
.status-active { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
|
|
.status-closed { background: rgba(107, 110, 128, 0.15); color: var(--muted); }
|
|
|
|
.session-count { font-size: 0.75rem; color: var(--muted); }
|
|
.session-id { font-size: 0.7rem; color: var(--muted); font-family: monospace; }
|
|
|
|
.no-sessions {
|
|
padding: 1.5rem 1rem;
|
|
font-size: 0.85rem;
|
|
color: var(--muted);
|
|
text-align: center;
|
|
}
|
|
|
|
/* --- Main panel --- */
|
|
.main-panel {
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.main-header {
|
|
padding: 0.9rem 1.5rem;
|
|
border-bottom: 1px solid var(--border);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
min-height: 56px;
|
|
}
|
|
|
|
#active-session-name {
|
|
font-weight: 700;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
#active-session-meta {
|
|
font-size: 0.8rem;
|
|
color: var(--muted);
|
|
}
|
|
|
|
#agent-messages {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 1.2rem 1.5rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.5rem;
|
|
scroll-behavior: smooth;
|
|
}
|
|
|
|
#agent-messages::-webkit-scrollbar { width: 4px; }
|
|
#agent-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
|
|
|
|
.empty-state {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: var(--muted);
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.empty-state .icon { font-size: 2rem; }
|
|
.empty-state p { font-size: 0.9rem; }
|
|
|
|
/* Message bubbles (same as customer page) */
|
|
.msg-wrap { display: flex; }
|
|
.msg-customer-wrap { justify-content: flex-end; }
|
|
.msg-agent-wrap { justify-content: flex-start; }
|
|
|
|
.msg-customer, .msg-agent {
|
|
max-width: 65%;
|
|
padding: 0.6rem 0.9rem;
|
|
border-radius: 16px;
|
|
font-size: 0.88rem;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.msg-customer { background: var(--customer); color: #fff; border-bottom-right-radius: 4px; }
|
|
.msg-agent { background: var(--border); color: var(--text); border-bottom-left-radius: 4px; }
|
|
|
|
.msg-label {
|
|
display: block;
|
|
font-size: 0.7rem;
|
|
font-weight: 600;
|
|
opacity: 0.7;
|
|
margin-bottom: 2px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
}
|
|
|
|
.msg-text { margin: 0; }
|
|
|
|
.msg-time {
|
|
display: block;
|
|
font-size: 0.68rem;
|
|
opacity: 0.5;
|
|
margin-top: 4px;
|
|
text-align: right;
|
|
}
|
|
|
|
.msg-system-wrap { display: flex; justify-content: center; margin: 0.25rem 0; }
|
|
.msg-system-text {
|
|
font-size: 0.75rem;
|
|
color: var(--muted);
|
|
background: var(--bg);
|
|
padding: 0.25rem 0.75rem;
|
|
border-radius: 20px;
|
|
}
|
|
|
|
/* --- Reply form --- */
|
|
#reply-area {
|
|
border-top: 1px solid var(--border);
|
|
padding: 0.75rem 1.5rem;
|
|
display: none;
|
|
}
|
|
|
|
#reply-area.visible { display: flex; gap: 0.6rem; }
|
|
|
|
#reply-area input[type="text"] {
|
|
flex: 1;
|
|
padding: 0.65rem 1rem;
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
color: var(--text);
|
|
font-size: 0.9rem;
|
|
outline: none;
|
|
transition: border-color 0.2s;
|
|
}
|
|
|
|
#reply-area input[type="text"]:focus { border-color: var(--accent); }
|
|
|
|
#reply-area button {
|
|
padding: 0.65rem 1.2rem;
|
|
background: var(--agent);
|
|
color: #0f1117;
|
|
border: none;
|
|
border-radius: var(--radius);
|
|
font-weight: 700;
|
|
font-size: 0.88rem;
|
|
cursor: pointer;
|
|
transition: opacity 0.2s;
|
|
}
|
|
|
|
#reply-area button:hover { opacity: 0.85; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="layout">
|
|
|
|
<!-- Top bar -->
|
|
<header class="topbar">
|
|
<span class="topbar-logo">🎧</span>
|
|
<h1>Support Dashboard</h1>
|
|
<span class="topbar-badge" id="ws-status">● Connecting…</span>
|
|
</header>
|
|
|
|
<!-- Sidebar: session list -->
|
|
<aside class="sidebar">
|
|
<div class="sidebar-header">Conversations</div>
|
|
<div id="session-list"
|
|
hx-get="/sessions"
|
|
hx-trigger="load, every 5s"
|
|
hx-swap="innerHTML">
|
|
<p class="no-sessions">Loading…</p>
|
|
</div>
|
|
</aside>
|
|
|
|
<!-- Main: message view + reply -->
|
|
<section class="main-panel">
|
|
<div class="main-header">
|
|
<span id="active-session-name" style="color: var(--muted)">Select a conversation</span>
|
|
<span id="active-session-meta"></span>
|
|
</div>
|
|
|
|
<div id="agent-messages">
|
|
<div class="empty-state">
|
|
<span class="icon">💬</span>
|
|
<p>No conversation selected</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="reply-area">
|
|
<input type="text" id="reply-input" placeholder="Reply to customer…" autocomplete="off" />
|
|
<button id="reply-btn">Send</button>
|
|
</div>
|
|
</section>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
let activeSessionId = null;
|
|
|
|
function setActiveSession(sessionId, name) {
|
|
activeSessionId = sessionId;
|
|
document.getElementById('active-session-name').textContent = name;
|
|
document.getElementById('active-session-meta').textContent = '#' + sessionId.slice(0, 8);
|
|
document.getElementById('reply-area').classList.add('visible');
|
|
scrollAgentMessages();
|
|
}
|
|
|
|
function scrollAgentMessages() {
|
|
const el = document.getElementById('agent-messages');
|
|
if (el) el.scrollTop = el.scrollHeight;
|
|
}
|
|
|
|
document.addEventListener('htmx:afterSwap', (e) => {
|
|
if (e.detail.target.id === 'agent-messages') scrollAgentMessages();
|
|
});
|
|
|
|
// Send reply on button click
|
|
document.getElementById('reply-btn').addEventListener('click', () => {
|
|
if (!activeSessionId) return;
|
|
const input = document.getElementById('reply-input');
|
|
const content = input.value.trim();
|
|
if (!content) return;
|
|
|
|
fetch(`/agent/send/${activeSessionId}`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
body: `content=${encodeURIComponent(content)}`
|
|
})
|
|
.then(r => r.text())
|
|
.then(html => {
|
|
const msgs = document.getElementById('agent-messages');
|
|
msgs.insertAdjacentHTML('beforeend', html);
|
|
scrollAgentMessages();
|
|
input.value = '';
|
|
});
|
|
});
|
|
|
|
// Also send on Enter
|
|
document.getElementById('reply-input').addEventListener('keydown', (e) => {
|
|
if (e.key === 'Enter') document.getElementById('reply-btn').click();
|
|
});
|
|
|
|
// WebSocket: get push notifications for new messages / sessions
|
|
function connectAgentWS() {
|
|
const ws = new WebSocket(`ws://${location.host}/ws/agent/dashboard`);
|
|
|
|
ws.onopen = () => {
|
|
document.getElementById('ws-status').textContent = '● Live';
|
|
document.getElementById('ws-status').style.color = '#22c55e';
|
|
};
|
|
|
|
ws.onmessage = (e) => {
|
|
const updatedSessionId = e.data;
|
|
// Refresh session list
|
|
htmx.trigger('#session-list', 'refresh');
|
|
|
|
// If this session is currently open, refresh its messages
|
|
if (updatedSessionId === activeSessionId) {
|
|
fetch(`/messages/${activeSessionId}`)
|
|
.then(r => r.text())
|
|
.then(html => {
|
|
document.getElementById('agent-messages').innerHTML = html;
|
|
scrollAgentMessages();
|
|
});
|
|
}
|
|
};
|
|
|
|
ws.onclose = () => {
|
|
document.getElementById('ws-status').textContent = '● Reconnecting…';
|
|
document.getElementById('ws-status').style.color = '#eab308';
|
|
setTimeout(connectAgentWS, 2000);
|
|
};
|
|
}
|
|
|
|
connectAgentWS();
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|