|
|
@@ -5,7 +5,7 @@
|
|
|
import { useState, useRef, useEffect, useMemo } from "react";
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
import { trpc } from "@/lib/trpc";
|
|
|
-import { Bot, X, Send, Loader2, User, Headphones, Sparkles, ChevronDown, MoreVertical, Star } from "lucide-react";
|
|
|
+import { Bot, X, Send, Loader2, User, Headphones, Sparkles, ChevronDown, Star } from "lucide-react";
|
|
|
import { Streamdown } from "streamdown";
|
|
|
|
|
|
const QUICK_REPLIES = [
|
|
|
@@ -20,7 +20,7 @@ export default function ChatbotWidgetLive() {
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
const [inputText, setInputText] = useState("");
|
|
|
const [sessionId, setSessionId] = useState<string | null>(null);
|
|
|
- const [localMessages, setLocalMessages] = useState<Array<{ id: number; sender: string; content: string; createdAt: string }>>([]);
|
|
|
+ const [localMessages, setLocalMessages] = useState<Array<{ id: number | string; sender: string; content: string; createdAt: string }>>([]);
|
|
|
const [isTyping, setIsTyping] = useState(false);
|
|
|
const [showQuickReplies, setShowQuickReplies] = useState(true);
|
|
|
const [pendingMessage, setPendingMessage] = useState<string | null>(null);
|
|
|
@@ -121,7 +121,7 @@ export default function ChatbotWidgetLive() {
|
|
|
|
|
|
// Optimistically add user message
|
|
|
setLocalMessages(prev => [...prev, {
|
|
|
- id: Date.now(),
|
|
|
+ id: crypto.randomUUID(),
|
|
|
sender: "visitor",
|
|
|
content,
|
|
|
createdAt: new Date().toISOString(),
|
|
|
@@ -136,7 +136,7 @@ export default function ChatbotWidgetLive() {
|
|
|
setIsTyping(true);
|
|
|
isNearBottomRef.current = true;
|
|
|
setLocalMessages(prev => [...prev, {
|
|
|
- id: Date.now(), sender: "visitor", content: text, createdAt: new Date().toISOString(),
|
|
|
+ id: crypto.randomUUID(), sender: "visitor", content: text, createdAt: new Date().toISOString(),
|
|
|
}]);
|
|
|
if (sessionId) {
|
|
|
sendMessage.mutate({ sessionId, content: text });
|
|
|
@@ -197,9 +197,6 @@ export default function ChatbotWidgetLive() {
|
|
|
</div>
|
|
|
</div>
|
|
|
<div className="flex items-center gap-1">
|
|
|
- <button className="p-1.5 rounded-lg hover:bg-white/10 transition-colors">
|
|
|
- <MoreVertical className="w-4 h-4 text-white/70" />
|
|
|
- </button>
|
|
|
<button onClick={() => setIsOpen(false)} className="p-1.5 rounded-lg hover:bg-white/10 transition-colors">
|
|
|
<ChevronDown className="w-4 h-4 text-white/70" />
|
|
|
</button>
|
|
|
@@ -385,7 +382,7 @@ export default function ChatbotWidgetLive() {
|
|
|
placeholder={t("widget.placeholder")}
|
|
|
className="flex-1 px-3 py-2 rounded-xl text-sm border"
|
|
|
style={{ borderColor: "#e7e0d5", fontFamily: "'Source Sans 3', sans-serif", background: "#fff" }}
|
|
|
- disabled={isTyping || startSession.isPending}
|
|
|
+ disabled={!sessionId || isTyping || startSession.isPending}
|
|
|
/>
|
|
|
<button
|
|
|
onClick={() => handleSend()}
|