'use client' import * as React from 'react' import { useRouter } from 'next/navigation' import { toast } from 'react-hot-toast' import { ServerActionResult } from '@/lib/types' import { Button } from '@/components/ui/button' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog' import { IconSpinner } from '@/components/ui/icons' interface ClearHistoryProps { isEnabled: boolean clearChats: () => ServerActionResult } export function ClearHistory({ isEnabled = false, clearChats }: ClearHistoryProps) { const [open, setOpen] = React.useState(false) const [isPending, startTransition] = React.useTransition() const router = useRouter() return ( Are you absolutely sure? This will permanently delete your chat history and remove your data from our servers. Cancel { event.preventDefault() startTransition(() => { clearChats().then(result => { if (result && 'error' in result) { toast.error(result.error) return } setOpen(false) router.push('/') }) }) }} > {isPending && } Delete ) }