"use client"; import { AuditorReport } from "@/types"; import { useSendAuditorReport, useCreateAuditorReport } from "@/hooks/use-dashboard"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Skeleton } from "@/components/ui/skeleton"; import { ScrollArea } from "@/components/ui/scroll-area"; import { FileText, Send, Eye, Clock, Plus } from "lucide-react"; import { toast } from "sonner"; interface ReportsPanelProps { reports: AuditorReport[] | undefined; isLoading: boolean; onCreateReport?: () => void; } function formatDate(timestamp: string): string { return new Date(timestamp).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", }); } export function ReportsPanel({ reports, isLoading, onCreateReport }: ReportsPanelProps) { const sendReport = useSendAuditorReport(); const createReport = useCreateAuditorReport(); const handleNewReport = () => { if (onCreateReport) { onCreateReport(); return; } // No parent handler provided — create a draft report directly createReport.mutate( { report_type: "summary", title: `New Report — ${new Date().toLocaleDateString()}`, summary: "Draft report created from the Reports panel.", sections: [], }, { onSuccess: () => toast.success("Draft report created"), onError: () => toast.error("Failed to create report"), } ); }; const handleSend = async (reportId: string) => { try { await sendReport.mutateAsync(reportId); toast.success("Report sent to CEO"); } catch { toast.error("Failed to send report"); } }; return (
Reports
{isLoading ? (
{[...Array(3)].map((_, i) => ( ))}
) : !reports || reports.length === 0 ? (
No reports yet
) : (
{reports.map((report) => { const isDraft = !report.sent_at; return (
{isDraft ? "Draft" : "Sent"} {report.title}
{report.report_type} {formatDate(report.created_at)}
{isDraft && ( )}
); })}
)}
); }