Chat: Korrekturen aus dem Abschlussreview
- Gespraech startet nicht neu, wenn der Kundenname nachlaedt (Entwurf bleibt, kein verwaister Timer) - Neue Nachricht an Kunde: erst die eindeutige Beschriftung Name · E-Mail · Kd.-Nr. oeffnet Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb0b889203
commit
813c6a7e18
4 files changed
+43
-7
No files matched your search
@@ -20,6 +20,9 @@ export default function ChatThread({ customerId, customerName }) {
|
||||
const [error, setError] = useState(null)
|
||||
const [notice, setNotice] = useState('')
|
||||
const [reloadKey, setReloadKey] = useState(0)
|
||||
// Name nur ueber eine Referenz lesen: kommt er spaeter (Liste/Kunden laden noch), startet das Gespraech nicht neu
|
||||
const nameRef = useRef(customerName)
|
||||
nameRef.current = customerName
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true
|
||||
@@ -39,7 +42,7 @@ export default function ChatThread({ customerId, customerName }) {
|
||||
state.shown.add(msg.id)
|
||||
box.appendChild(chat.renderMessage(msg, {
|
||||
mine: msg.sender === 'admin',
|
||||
meta: messageMeta(msg, customerName),
|
||||
meta: messageMeta(msg, nameRef.current),
|
||||
fileUrl: (att) => att.url,
|
||||
}))
|
||||
if (msg.createdAt > state.last) state.last = msg.createdAt
|
||||
@@ -83,7 +86,7 @@ export default function ChatThread({ customerId, customerName }) {
|
||||
dropZone: zoneRef.current,
|
||||
uploadUrl: chatUploadUrl(customerId),
|
||||
requestHeaders: teamAuthHeaders,
|
||||
placeholder: `Antwort an ${customerName || 'Kunde'}…`,
|
||||
placeholder: `Antwort an ${nameRef.current || 'Kunde'}…`,
|
||||
placeholderShort: 'Antwort…',
|
||||
send: async ({ text, attachmentIds }) => {
|
||||
const { message, notice: result } = await sendChatMessage(customerId, { text, attachmentIds })
|
||||
@@ -94,6 +97,8 @@ export default function ChatThread({ customerId, customerName }) {
|
||||
onSent: (message) => append([message]),
|
||||
})
|
||||
await loadAll()
|
||||
// waehrend des Ladens verlassen: keinen Timer mehr anlegen, den das Aufraeumen nicht mehr sieht
|
||||
if (!alive) return
|
||||
timer = setInterval(poll, POLL_MS)
|
||||
} catch (err) {
|
||||
if (alive) setError(err.message || 'Die Unterhaltung konnte nicht geladen werden.')
|
||||
@@ -108,7 +113,7 @@ export default function ChatThread({ customerId, customerName }) {
|
||||
document.removeEventListener('visibilitychange', onVisible)
|
||||
composer?.destroy()
|
||||
}
|
||||
}, [customerId, customerName, reloadKey])
|
||||
}, [customerId, reloadKey])
|
||||
|
||||
return (
|
||||
<div className="woms-chat" ref={zoneRef}>
|
||||
|
||||
Reference in new issue
Block a user