Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
2a97b5f739
commit
498816dddb
@@ -9,12 +9,12 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { supabase } from "@/integrations/supabase/client";
|
||||
import { ClientFormDialog } from "@/components/clients/client-form-dialog";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import { ArrowLeft, Edit, Plus, Building2, User, MapPin, Mail, Phone, Users, Activity, Briefcase, FileDown, Contact, Receipt, Archive, ArchiveRestore, ListPlus } from "lucide-react";
|
||||
import { ArrowLeft, Edit, Plus, Building2, User, MapPin, Mail, Phone, Users, Activity, Briefcase, FileDown, Contact, Receipt, Archive, ArchiveRestore, ListPlus, Save } from "lucide-react";
|
||||
import { ContactsLinkTab } from "@/components/contacts/contacts-link-tab";
|
||||
import { ClientCustomFieldsTab } from "@/components/clients/client-custom-fields-tab";
|
||||
import { formatCurrency, formatDate, formatDateTime, statusBadgeClass } from "@/lib/format";
|
||||
import { toast } from "sonner";
|
||||
import { downloadStatusReport } from "@/lib/status-pdf";
|
||||
import { downloadStatusReport, saveStatusReportToDb } from "@/lib/status-pdf";
|
||||
|
||||
import { TrustAccountPanel } from "@/components/trust/trust-account-panel";
|
||||
import { setArchived } from "@/lib/archive";
|
||||
@@ -268,29 +268,61 @@ function ClientDetail() {
|
||||
<TabsContent value="status">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<p className="text-xs text-muted-foreground">{statusEntries.length} update{statusEntries.length === 1 ? "" : "s"} across all cases</p>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={statusEntries.length === 0}
|
||||
onClick={() => {
|
||||
downloadStatusReport({
|
||||
title: "Client Status Report",
|
||||
subtitle: client.name,
|
||||
groupByCase: true,
|
||||
entries: statusEntries.map((u) => ({
|
||||
title: u.title,
|
||||
body: u.body,
|
||||
created_at: u.created_at,
|
||||
author_name: u.user?.full_name,
|
||||
author_email: u.user?.email,
|
||||
case_number: u.case?.case_number,
|
||||
case_title: u.case?.title,
|
||||
})),
|
||||
}, `status-report-${client.name.replace(/[^a-z0-9]+/gi, "-")}.pdf`);
|
||||
}}
|
||||
>
|
||||
<FileDown className="h-3.5 w-3.5 mr-1.5" /> Export
|
||||
</Button>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={statusEntries.length === 0}
|
||||
onClick={async () => {
|
||||
if (!user?.id) { toast.error("Not signed in"); return; }
|
||||
const opts = {
|
||||
title: "Client Status Report",
|
||||
subtitle: client.name,
|
||||
groupByCase: true,
|
||||
entries: statusEntries.map((u) => ({
|
||||
title: u.title, body: u.body, created_at: u.created_at,
|
||||
author_name: u.user?.full_name, author_email: u.user?.email,
|
||||
case_number: u.case?.case_number, case_title: u.case?.title,
|
||||
})),
|
||||
};
|
||||
const filename = `status-report-${client.name.replace(/[^a-z0-9]+/gi, "-")}-${new Date().toISOString().slice(0, 10)}.pdf`;
|
||||
try {
|
||||
await saveStatusReportToDb(opts, filename, {
|
||||
userId: user.id,
|
||||
payload: { client_id: client.id, client_name: client.name, entry_count: statusEntries.length, scope: "client" },
|
||||
});
|
||||
toast.success("Saved to Reports");
|
||||
} catch (err: any) {
|
||||
toast.error(err?.message || "Could not save report");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Save className="h-3.5 w-3.5 mr-1.5" /> Save to Reports
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={statusEntries.length === 0}
|
||||
onClick={() => {
|
||||
downloadStatusReport({
|
||||
title: "Client Status Report",
|
||||
subtitle: client.name,
|
||||
groupByCase: true,
|
||||
entries: statusEntries.map((u) => ({
|
||||
title: u.title,
|
||||
body: u.body,
|
||||
created_at: u.created_at,
|
||||
author_name: u.user?.full_name,
|
||||
author_email: u.user?.email,
|
||||
case_number: u.case?.case_number,
|
||||
case_title: u.case?.title,
|
||||
})),
|
||||
}, `status-report-${client.name.replace(/[^a-z0-9]+/gi, "-")}.pdf`);
|
||||
}}
|
||||
>
|
||||
<FileDown className="h-3.5 w-3.5 mr-1.5" /> Export
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
{statusEntries.length === 0 && <p className="text-sm text-muted-foreground">No status updates logged.</p>}
|
||||
<div className="space-y-3 max-h-[480px] overflow-auto">
|
||||
|
||||
Reference in New Issue
Block a user