'use client' import React from 'react' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '@/components/ui/dialog' import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' import { IconArrowElbow, IconEdit, IconTrash } from '@/components/ui/icons' import { Input } from '@/components/ui/input' import { updateChat } from '@/lib/stores/chat-actions' import { Button } from './ui/button' interface EditChatTitleDialogProps { initialValue: string | undefined chatId: string children?: React.ReactNode } export const EditChatTitleDialog = ({ children, initialValue, chatId }: EditChatTitleDialogProps) => { const [open, setOpen] = React.useState(false) const formRef = React.useRef(null) const [input, setInput] = React.useState(initialValue) const handleSubmit: React.FormEventHandler = async e => { e.preventDefault() if (!input?.trim()) { return } updateChat(chatId, { title: input }) setOpen(false) } const onKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { formRef.current?.requestSubmit() e.preventDefault() } } return ( Edit Edit Chat Title
setInput(e.target.value)} onKeyDown={onKeyDown} />
Edit Title
) }