From 2a97b5f7392e35c14aee0022b0eabea37c90b6dd Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 19 Apr 2026 18:22:44 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/components/cases/status-tab.tsx | 49 +++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/src/components/cases/status-tab.tsx b/src/components/cases/status-tab.tsx index ea79d19..9d6f8e9 100644 --- a/src/components/cases/status-tab.tsx +++ b/src/components/cases/status-tab.tsx @@ -6,10 +6,10 @@ import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { supabase } from "@/integrations/supabase/client"; import { useAuth } from "@/lib/auth"; -import { Plus, Trash2, Loader2, FileDown, Pencil } from "lucide-react"; +import { Plus, Trash2, Loader2, FileDown, Pencil, Save } from "lucide-react"; import { formatDateTime } from "@/lib/format"; import { toast } from "sonner"; -import { downloadStatusReport } from "@/lib/status-pdf"; +import { downloadStatusReport, saveStatusReportToDb } from "@/lib/status-pdf"; export function CaseStatusTab({ caseId, caseLabel }: { caseId: string; caseLabel?: string }) { const { user, isAdmin } = useAuth(); @@ -79,24 +79,47 @@ export function CaseStatusTab({ caseId, caseLabel }: { caseId: string; caseLabel if (error) toast.error(error.message); else { toast.success("Deleted"); load(); } }; + const buildReportOpts = () => ({ + title: "Case Status Report", + subtitle: caseLabel, + entries: items.map((u) => ({ + title: u.title, + body: u.body, + created_at: u.created_at, + author_name: u.user?.full_name, + author_email: u.user?.email, + })), + }); + const exportPdf = () => { if (items.length === 0) { toast.error("No status updates to export"); return; } - downloadStatusReport({ - title: "Case Status Report", - subtitle: caseLabel, - entries: items.map((u) => ({ - title: u.title, - body: u.body, - created_at: u.created_at, - author_name: u.user?.full_name, - author_email: u.user?.email, - })), - }, `status-report-${(caseLabel || caseId).replace(/[^a-z0-9]+/gi, "-")}.pdf`); + downloadStatusReport( + buildReportOpts(), + `status-report-${(caseLabel || caseId).replace(/[^a-z0-9]+/gi, "-")}.pdf`, + ); + }; + + const saveReport = async () => { + if (items.length === 0) { toast.error("No status updates to save"); return; } + if (!user?.id) { toast.error("Not signed in"); return; } + const filename = `status-report-${(caseLabel || caseId).replace(/[^a-z0-9]+/gi, "-")}-${new Date().toISOString().slice(0, 10)}.pdf`; + try { + await saveStatusReportToDb(buildReportOpts(), filename, { + userId: user.id, + payload: { case_id: caseId, case_label: caseLabel ?? null, entry_count: items.length, scope: "case" }, + }); + toast.success("Saved to Reports"); + } catch (err: any) { + toast.error(err?.message || "Could not save report"); + } }; return (