diff --git a/teressa-copeland-homes/src/app/portal/(protected)/dashboard/page.tsx b/teressa-copeland-homes/src/app/portal/(protected)/dashboard/page.tsx new file mode 100644 index 0000000..dfc072b --- /dev/null +++ b/teressa-copeland-homes/src/app/portal/(protected)/dashboard/page.tsx @@ -0,0 +1,55 @@ +import { auth } from "@/lib/auth"; +import { db } from "@/lib/db"; +import { documents, clients } from "@/lib/db/schema"; +import { eq, desc } from "drizzle-orm"; +import { DocumentsTable } from "../../_components/DocumentsTable"; +import { DashboardFilters } from "../../_components/DashboardFilters"; + +const VALID_STATUSES = ["Draft", "Sent", "Viewed", "Signed"] as const; +type ValidStatus = (typeof VALID_STATUSES)[number]; + +export default async function DashboardPage({ + searchParams, +}: { + searchParams: Promise<{ status?: string }>; +}) { + const session = await auth(); + const { status } = await searchParams; + + const allRows = await db + .select({ + id: documents.id, + name: documents.name, + status: documents.status, + sentAt: documents.sentAt, + clientName: clients.name, + clientId: documents.clientId, + }) + .from(documents) + .leftJoin(clients, eq(documents.clientId, clients.id)) + .orderBy(desc(documents.createdAt)); + + const filteredRows = + status && (VALID_STATUSES as readonly string[]).includes(status) + ? allRows.filter((r) => r.status === (status as ValidStatus)) + : allRows; + + const firstName = session?.user?.email?.split("@")[0] ?? "Agent"; + + return ( +