'use client' import * as React from 'react' import { useRouter } from 'next/navigation' import { toast } from 'react-hot-toast' import { Share, type Chat, ServerActionResult } from '@/lib/types' import { formatDate } from '@/lib/utils' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { IconShare, IconSpinner, IconTrash } from '@/components/ui/icons' interface SidebarActionsProps { chat: Chat removeChat: (args: { id: string; path: string }) => Promise shareChat: (chat: Chat) => ServerActionResult } export function SidebarActions({ chat, removeChat, shareChat }: SidebarActionsProps) { const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false) const [shareDialogOpen, setShareDialogOpen] = React.useState(false) const [isRemovePending, startRemoveTransition] = React.useTransition() const [isSharePending, startShareTransition] = React.useTransition() const router = useRouter() return ( <>
Share link to chat Messages you send after creating your link won't be shared. Anyone with the URL will be able to view the shared chat.
{chat.title}
{formatDate(chat.createdAt)}

Any link you have shared before will be deleted.

Are you absolutely sure? This will permanently delete your chat message and remove your data from our servers. Cancel { event.preventDefault() startRemoveTransition(async () => { await removeChat({ id: chat.id, path: chat.path }) setDeleteDialogOpen(false) router.push('/') }) }} > {isRemovePending && } Delete ) }