import { Delete, Trash } from 'lucide-react'; import { Dialog, Transition } from '@headlessui/react'; import { Fragment, useState } from 'react'; import { toast } from 'sonner'; import { Chat } from '@/app/library/page'; const DeleteChat = ({ chatId, chats, setChats, }: { chatId: string; chats: Chat[]; setChats: (chats: Chat[]) => void; }) => { const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false); const [loading, setLoading] = useState(false); const handleDelete = async () => { setLoading(true); try { const res = await fetch( `${process.env.NEXT_PUBLIC_API_URL}/chats/${chatId}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', }, }, ); if (res.status != 200) { throw new Error('Failed to delete chat'); } const newChats = chats.filter((chat) => chat.id !== chatId); setChats(newChats); } catch (err: any) { toast.error(err.message); } finally { setConfirmationDialogOpen(false); setLoading(false); } }; return ( <> { if (!loading) { setConfirmationDialogOpen(false); } }} >
Delete Confirmation Are you sure you want to delete this chat?
); }; export default DeleteChat;