'use client' import * as React from 'react' import { useRouter } from 'next/navigation' import { toast } from 'react-hot-toast' import { ServerActionResult, ChatListItem } from '@/lib/types' import { cn, 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, IconUsers } from '@/components/ui/icons' import Link from 'next/link' import { badgeVariants } from '@/components/ui/badge' import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' interface SidebarActionsProps { chat: ChatListItem removeChat: (args: { id: string; path: string }) => ServerActionResult shareChat: (chat: ChatListItem) => 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() const copyShareLink = React.useCallback(async (chat: ChatListItem) => { if (!chat.sharePath) { return toast.error('Could not copy share link to clipboard') } const url = new URL(window.location.href) url.pathname = chat.sharePath navigator.clipboard.writeText(url.toString()) setShareDialogOpen(false) toast.success('Share link copied to clipboard', { style: { borderRadius: '10px', background: '#333', color: '#fff', fontSize: '14px' }, iconTheme: { primary: 'white', secondary: 'black' } }) }, []) return ( <>
Share chat Delete chat
Share link to chat Anyone with the URL will be able to view the shared chat.
{chat.title}
{formatDate(chat.createdAt)}
{chat.sharePath && ( {chat.sharePath} )}
Are you absolutely sure? This will permanently delete your chat message and remove your data from our servers. Cancel { event.preventDefault() 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 ) }