'use client'; import Link from 'next/link'; import { format } from 'date-fns'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Eye, FileText, Trash2 } from 'lucide-react'; import type { Document } from '@/firebase/firestore/data'; import { useFirebase } from '@/firebase'; import { deleteDocumentAndSubcollections } from '@/firebase/firestore/data'; import { useRouter } from 'next/navigation'; import { useToast } from '@/hooks/use-toast'; function DeleteButton({ id }: { id: string }) { const { firestore, user } = useFirebase(); const router = useRouter(); const { toast } = useToast(); const handleDelete = async () => { if (firestore && user) { try { await deleteDocumentAndSubcollections(firestore, user.uid, id); toast({ title: 'Document deleted', description: 'The document has been successfully deleted.', }); router.refresh(); } catch (error) { console.error('Failed to delete document:', error); toast({ title: 'Error', description: 'Failed to delete the document.', variant: 'destructive', }); } } }; return ( ); } export function DocumentTable({ documents }: { documents: Document[] }) { if (documents.length === 0) { return ( No Documents Yet

Upload your first document to see it here.

); } return ( Recent Summaries Name Created At Actions {documents.map((doc) => ( {doc.name} {format(new Date(doc.createdAt), 'PPP')}
))}
); }