fix(05-04): fetch client email via direct join, improve recipients hint text

This commit is contained in:
Chandler Copeland
2026-03-20 00:53:46 -06:00
parent 1319d4310e
commit 0a719c9d60
2 changed files with 17 additions and 14 deletions

View File

@@ -87,11 +87,9 @@ export function PreparePanel({ docId, defaultEmail, clientName, currentStatus }:
className="w-full border rounded px-2 py-1.5 text-sm resize-none"
placeholder="email@example.com"
/>
{clientName && (
<p className="text-xs text-gray-400 mt-0.5">
{clientName} · add more addresses separated by commas
</p>
)}
<p className="text-xs text-gray-400 mt-0.5">
To add more recipients, separate each email with a comma
</p>
</div>
<div>

View File

@@ -1,7 +1,7 @@
import { auth } from '@/lib/auth';
import { redirect } from 'next/navigation';
import { db } from '@/lib/db';
import { documents } from '@/lib/db/schema';
import { documents, clients } from '@/lib/db/schema';
import { eq } from 'drizzle-orm';
import Link from 'next/link';
import { PdfViewerWrapper } from './_components/PdfViewerWrapper';
@@ -17,10 +17,15 @@ export default async function DocumentPage({
const { docId } = await params;
const doc = await db.query.documents.findFirst({
where: eq(documents.id, docId),
with: { client: true },
});
const [doc, docClient] = await Promise.all([
db.query.documents.findFirst({ where: eq(documents.id, docId) }),
db.select({ email: clients.email, name: clients.name })
.from(clients)
.innerJoin(documents, eq(documents.clientId, clients.id))
.where(eq(documents.id, docId))
.limit(1)
.then(r => r[0] ?? null),
]);
if (!doc) redirect('/portal/dashboard');
@@ -32,11 +37,11 @@ export default async function DocumentPage({
href={`/portal/clients/${doc.clientId}`}
className="inline-flex items-center gap-1 px-3 py-1.5 text-sm font-medium text-blue-600 border border-blue-200 rounded-md bg-blue-50 hover:bg-blue-100 hover:border-blue-300 transition-colors"
>
&larr; Back to {doc.client?.name ?? 'Client'}
&larr; Back to {docClient?.name ?? 'Client'}
</Link>
<h1 className="text-2xl font-bold mt-1">{doc.name}</h1>
<p className="text-sm text-gray-500">
{doc.client?.name} &middot; <span className="capitalize">{doc.status}</span>
{docClient?.name} &middot; <span className="capitalize">{doc.status}</span>
</p>
</div>
</div>
@@ -48,8 +53,8 @@ export default async function DocumentPage({
<div className="lg:col-span-1">
<PreparePanel
docId={docId}
defaultEmail={doc.client?.email ?? ''}
clientName={doc.client?.name ?? ''}
defaultEmail={docClient?.email ?? ''}
clientName={docClient?.name ?? ''}
currentStatus={doc.status}
/>
</div>