'use client' import { useRouter } from 'next/navigation' import * as React from 'react' import { toast } from 'react-hot-toast' import { ServerActionResult, type Chat } from '@/lib/types' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog' import { Button } from '@/components/ui/button' import { IconShare, IconSpinner, IconTrash } from '@/components/ui/icons' import { ChatShareDialog } from '@/components/chat-share-dialog' import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' interface SidebarActionsProps { chat: Chat removeChat: (args: { id: string; path: string }) => ServerActionResult shareChat: (id: string) => ServerActionResult } export function SidebarActions({ chat, removeChat, shareChat }: SidebarActionsProps) { const router = useRouter() const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false) const [shareDialogOpen, setShareDialogOpen] = React.useState(false) const [isRemovePending, startRemoveTransition] = React.useTransition() return ( <>
Share chat Delete chat
setShareDialogOpen(false)} /> Are you absolutely sure? This will permanently delete your chat message and remove your data from our servers. Cancel { event.preventDefault() // @ts-ignore startRemoveTransition(async () => { const result = await removeChat({ id: chat.id, path: chat.path }) if (result && 'error' in result) { toast.error(result.error) return } setDeleteDialogOpen(false) router.refresh() router.push('/') toast.success('Chat deleted') }) }} > {isRemovePending && } Delete ) }