'use client' import * as React from 'react' import Link from 'next/link' import { usePathname, useRouter } from 'next/navigation' import { cn } from '@/lib/utils' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog' import { Button, buttonVariants } from '@/components/ui/button' import { IconMessage, IconSpinner, IconTrash } from '@/components/ui/icons' interface SidebarItemProps { title: string href: string id: string removeChat: (args: { id: string; path: string }) => Promise } export function SidebarItem({ title, href, id, removeChat }: SidebarItemProps) { const [open, setIsOpen] = React.useState(false) const pathname = usePathname() const router = useRouter() const [isPending, startTransition] = React.useTransition() const isActive = pathname === href if (!id) return null return ( <>
{title}
{isActive && ( )} Are you absolutely sure? This will permanently delete your chat message and remove your data from our servers. Cancel { event.preventDefault() startTransition(async () => { await removeChat({ id, path: href }) setIsOpen(false) router.push('/') }) }} > {isPending && } Delete ) }