diff --git a/src/routes/documents.index.tsx b/src/routes/documents.index.tsx index ed2a423..70a64f1 100644 --- a/src/routes/documents.index.tsx +++ b/src/routes/documents.index.tsx @@ -4,40 +4,38 @@ import { ProtectedLayout } from "@/components/protected-layout"; import { PageContainer, PageHeader } from "@/components/app-shell"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; -import { Badge } from "@/components/ui/badge"; import { supabase } from "@/integrations/supabase/client"; import { formatDate } from "@/lib/format"; -import { FilePlus2, FileText, Gavel, LayoutTemplate, Plus, Download, Trash2 } from "lucide-react"; +import { FileText, Gavel, Download, Trash2, FilePlus2 } from "lucide-react"; import { toast } from "sonner"; export const Route = createFileRoute("/documents/")({ - component: DocumentsIndex, + component: PleadingsIndex, }); -function DocumentsIndex() { - const [generated, setGenerated] = useState([]); - const [templates, setTemplates] = useState([]); +function PleadingsIndex() { + const [pleadings, setPleadings] = useState([]); const load = async () => { - const [g, t] = await Promise.all([ - supabase.from("generated_documents").select("*").order("created_at", { ascending: false }).limit(20), - supabase.from("document_templates").select("*").order("name"), - ]); - setGenerated(g.data ?? []); - setTemplates(t.data ?? []); + const { data } = await supabase + .from("generated_documents") + .select("*") + .eq("kind", "pleading") + .order("created_at", { ascending: false }); + setPleadings(data ?? []); }; useEffect(() => { load(); }, []); - const removeGenerated = async (row: any) => { + const removePleading = async (row: any) => { if (!confirm(`Delete ${row.name}?`)) return; if (row.storage_path) await supabase.storage.from("generated-documents").remove([row.storage_path]); const { error } = await supabase.from("generated_documents").delete().eq("id", row.id); if (error) toast.error(error.message); else { toast.success("Deleted"); load(); } }; - const downloadGenerated = async (row: any) => { - if (!row.storage_path) { toast.error("No file stored for this document"); return; } + const downloadPleading = async (row: any) => { + if (!row.storage_path) { toast.error("No file stored for this pleading"); return; } const { data, error } = await supabase.storage.from("generated-documents").createSignedUrl(row.storage_path, 60); if (error) { toast.error(error.message); return; } window.open(data.signedUrl, "_blank"); @@ -47,25 +45,18 @@ function DocumentsIndex() { - - - + } /> -
+
@@ -77,58 +68,51 @@ function DocumentsIndex() { - - - -
-
-
New template
-
Define custom merge fields and reuse them.
-
-
-
- - - - -
-
-
Template library
-
{templates.length} template{templates.length === 1 ? "" : "s"} available.
-
-
-
- + + +
+
+
Saved pleadings
+
{pleadings.length} saved ยท open any below as a new template.
+
+
+
- Recent documents + Saved pleadings - {generated.length === 0 ? ( -
No documents yet. Create a pleading or use a template.
+ {pleadings.length === 0 ? ( +
No pleadings yet. Create one to save it as a reusable template.
) : ( - - {generated.map((d) => ( + {pleadings.map((d) => ( - - + ))}
NameType Created Actions
{d.name}
{d.kind} + + + {d.name} + + {formatDate(d.created_at)} + {d.storage_path && ( - + )} - +