import { Description, Dialog, DialogBackdrop, DialogPanel, DialogTitle, Transition, TransitionChild, } from '@headlessui/react'; import { Fragment, useState } from 'react'; import { toast } from 'sonner'; import { Chat } from '@/app/library/page'; interface BatchDeleteChatsProps { chatIds: string[]; chats: Chat[]; setChats: (chats: Chat[]) => void; onComplete: () => void; isOpen: boolean; setIsOpen: (isOpen: boolean) => void; } const BatchDeleteChats = ({ chatIds, chats, setChats, onComplete, isOpen, setIsOpen, }: BatchDeleteChatsProps) => { const [loading, setLoading] = useState(false); const handleDelete = async () => { if (chatIds.length === 0) return; setLoading(true); try { for (const chatId of chatIds) { await fetch(`/api/chats/${chatId}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', }, }); } const newChats = chats.filter(chat => !chatIds.includes(chat.id)); setChats(newChats); toast.success(`${chatIds.length} thread${chatIds.length > 1 ? 's' : ''} deleted`); onComplete(); } catch (err: any) { toast.error('Failed to delete threads'); } finally { setIsOpen(false); setLoading(false); } }; return ( { if (!loading) { setIsOpen(false); } }} >
Delete Confirmation Are you sure you want to delete {chatIds.length} selected thread{chatIds.length !== 1 ? 's' : ''}?
); }; export default BatchDeleteChats;