fix(05-04): fetch client email via direct join, improve recipients hint text
This commit is contained in:
@@ -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"
|
className="w-full border rounded px-2 py-1.5 text-sm resize-none"
|
||||||
placeholder="email@example.com"
|
placeholder="email@example.com"
|
||||||
/>
|
/>
|
||||||
{clientName && (
|
|
||||||
<p className="text-xs text-gray-400 mt-0.5">
|
<p className="text-xs text-gray-400 mt-0.5">
|
||||||
{clientName} · add more addresses separated by commas
|
To add more recipients, separate each email with a comma
|
||||||
</p>
|
</p>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { auth } from '@/lib/auth';
|
import { auth } from '@/lib/auth';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import { db } from '@/lib/db';
|
import { db } from '@/lib/db';
|
||||||
import { documents } from '@/lib/db/schema';
|
import { documents, clients } from '@/lib/db/schema';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { PdfViewerWrapper } from './_components/PdfViewerWrapper';
|
import { PdfViewerWrapper } from './_components/PdfViewerWrapper';
|
||||||
@@ -17,10 +17,15 @@ export default async function DocumentPage({
|
|||||||
|
|
||||||
const { docId } = await params;
|
const { docId } = await params;
|
||||||
|
|
||||||
const doc = await db.query.documents.findFirst({
|
const [doc, docClient] = await Promise.all([
|
||||||
where: eq(documents.id, docId),
|
db.query.documents.findFirst({ where: eq(documents.id, docId) }),
|
||||||
with: { client: true },
|
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');
|
if (!doc) redirect('/portal/dashboard');
|
||||||
|
|
||||||
@@ -32,11 +37,11 @@ export default async function DocumentPage({
|
|||||||
href={`/portal/clients/${doc.clientId}`}
|
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"
|
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"
|
||||||
>
|
>
|
||||||
← Back to {doc.client?.name ?? 'Client'}
|
← Back to {docClient?.name ?? 'Client'}
|
||||||
</Link>
|
</Link>
|
||||||
<h1 className="text-2xl font-bold mt-1">{doc.name}</h1>
|
<h1 className="text-2xl font-bold mt-1">{doc.name}</h1>
|
||||||
<p className="text-sm text-gray-500">
|
<p className="text-sm text-gray-500">
|
||||||
{doc.client?.name} · <span className="capitalize">{doc.status}</span>
|
{docClient?.name} · <span className="capitalize">{doc.status}</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -48,8 +53,8 @@ export default async function DocumentPage({
|
|||||||
<div className="lg:col-span-1">
|
<div className="lg:col-span-1">
|
||||||
<PreparePanel
|
<PreparePanel
|
||||||
docId={docId}
|
docId={docId}
|
||||||
defaultEmail={doc.client?.email ?? ''}
|
defaultEmail={docClient?.email ?? ''}
|
||||||
clientName={doc.client?.name ?? ''}
|
clientName={docClient?.name ?? ''}
|
||||||
currentStatus={doc.status}
|
currentStatus={doc.status}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user