import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { ChatbotUIContext } from "@/context/context" import { updateChat } from "@/db/chats" import { Tables } from "@/supabase/types" import { IconEdit } from "@tabler/icons-react" import { FC, useContext, useRef, useState } from "react" interface UpdateChatProps { chat: Tables<"chats"> } export const UpdateChat: FC = ({ chat }) => { const { setChats } = useContext(ChatbotUIContext) const buttonRef = useRef(null) const [showChatDialog, setShowChatDialog] = useState(false) const [name, setName] = useState(chat.name) const handleUpdateChat = async (e: React.MouseEvent) => { const updatedChat = await updateChat(chat.id, { name }) setChats(prevState => prevState.map(c => (c.id === chat.id ? updatedChat : c)) ) setShowChatDialog(false) } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter") { buttonRef.current?.click() } } return ( Edit Chat
setName(e.target.value)} />
) }