From 37489aa8661635a76defe3a353e53b286539cd63 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 30 Sep 2026 18:51:57 +0000 Subject: [PATCH] Admin-Chat: neue Unterhaltung mit jedem Kunden starten Ueber der Chat-Liste sucht ein Feld alle Kunden (Name, E-Mail, Kd.-Nr.) und oeffnet einen leeren Chat, auch wenn der Kunde noch nie geschrieben hat. Der Server konnte das schon. Co-Authored-By: Claude Opus 5.5 --- public/admin.html | 10 ++++++++-- public/admin.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/public/admin.html b/public/admin.html index 1170bb1..6b44e58 100644 --- a/public/admin.html +++ b/public/admin.html @@ -64,6 +64,7 @@ } .chat-layout { display: grid; grid-template-columns: 280px 1fr; gap: 14px; min-height: 480px; } @media (max-width: 760px) { .chat-layout { grid-template-columns: 1fr; } } + .chat-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; } .chat-list { border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; overflow-y: auto; max-height: 560px; } .chat-list-item { padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,0.07); cursor: pointer; } .chat-list-item:hover { background: rgba(255,255,255,0.05); } @@ -220,8 +221,13 @@
-
-
Lade Unterhaltungen…
+
+ + +
+
Lade Unterhaltungen…
+
Unterhaltung links auswählen
diff --git a/public/admin.js b/public/admin.js index b16f4f9..a98c51f 100644 --- a/public/admin.js +++ b/public/admin.js @@ -382,6 +382,33 @@ async function pollAdminChatBadge() { } } +// Neue Unterhaltung: jeden Kunden anschreiben, auch wenn er noch nie geschrieben hat +const chatCustomerLabel = (c) => + [c.name || '(ohne Name)', c.email, c.code ? `Kd.-Nr. ${c.code}` : ''].filter(Boolean).join(' · ') + +async function setupNewChatPicker() { + const input = document.getElementById('admin-chat-new') + if (!input) return + let byLabel = new Map() + try { + const { customers } = await api('/api/portal-admin/customers') + byLabel = new Map(customers.map((c) => [chatCustomerLabel(c), c])) + document.getElementById('admin-chat-new-list').innerHTML = customers + .map((c) => ``).join('') + } catch (err) { + input.placeholder = `Kunden konnten nicht geladen werden: ${err.message}` + return + } + const pick = () => { + const customer = byLabel.get(input.value.trim()) + if (!customer) return + input.value = '' + openChatThread(customer.id, customer.name || customer.email || 'Kunde') + } + input.addEventListener('change', pick) + input.addEventListener('input', pick) +} + async function loadChatList() { const list = document.getElementById('admin-chat-list') try { @@ -1313,6 +1340,7 @@ async function initAdminPage() { if (tab.dataset.tab === 'chat' && !chatListLoaded) { chatListLoaded = true loadChatList() + setupNewChatPicker() } if (tab.dataset.tab === 'credits' && !creditsLoaded) { creditsLoaded = true