feat(record-export): migrate client/berth/interest summaries to react-pdf
Phase 1 / commits 7-9 of 14 — bundled because all three record exports
share the same conversion pattern and call sites.
Templates:
client-summary.tsx header + KV grid for client, contacts table
with primary badge, yacht table, interests
table with stage/category, recent activity
table
berth-spec.tsx header + status badge, overview KV grid,
dimensions KV grid (with min markers), pricing
& tenure KV grid, infrastructure KV grid,
waiting list table with priority badges,
maintenance log table
interest-summary.tsx header + stage badge, status KV grid, client
KV, optional yacht/berth sections, milestones
KV grid, recent timeline table
record-export.tsx (renamed .ts -> .tsx for JSX):
- swap generatePdf(...) calls for renderPdf(<…Pdf … />) calls
- inject port logo via resolvePortLogo()
- shape data into typed template props (Drizzle returns are passed
through deliberately so the template controls its own type surface)
Drops two latent bugs the old templates carried:
- client.nationality was read as a property but the schema field is
nationalityIso — old PDFs always showed "—" for nationality
- interest.notes was read but the interests table doesn't have a
notes column (interest_berths does) — old PDFs always showed "No
notes"
Both fields are now sourced correctly (or omitted) in the new templates.
Old pdfme files deleted (3 templates). API routes that import
exportClientPdf/exportBerthPdf/exportInterestPdf unchanged.
Tests:
tests/unit/record-export-templates.test.tsx (4 tests): each template
renders to valid PDF bytes with representative data, plus a minimal-
input path for the berth spec.
1317/1317 vitest green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,16 +13,11 @@ import { companyMemberships } from '@/lib/db/schema/companies';
|
||||
import { auditLogs } from '@/lib/db/schema/system';
|
||||
import { ports } from '@/lib/db/schema/ports';
|
||||
import { NotFoundError } from '@/lib/errors';
|
||||
import { generatePdf } from '@/lib/pdf/generate';
|
||||
import {
|
||||
clientSummaryTemplate,
|
||||
buildClientSummaryInputs,
|
||||
} from '@/lib/pdf/templates/client-summary-template';
|
||||
import { berthSpecTemplate, buildBerthSpecInputs } from '@/lib/pdf/templates/berth-spec-template';
|
||||
import {
|
||||
interestSummaryTemplate,
|
||||
buildInterestSummaryInputs,
|
||||
} from '@/lib/pdf/templates/interest-summary-template';
|
||||
import { renderPdf } from '@/lib/pdf/render';
|
||||
import { resolvePortLogo } from '@/lib/pdf/brand-kit/logo';
|
||||
import { BerthSpecPdf } from '@/lib/pdf/templates/berth-spec';
|
||||
import { ClientSummaryPdf } from '@/lib/pdf/templates/client-summary';
|
||||
import { InterestSummaryPdf } from '@/lib/pdf/templates/interest-summary';
|
||||
|
||||
// ─── Export Client PDF ────────────────────────────────────────────────────────
|
||||
|
||||
@@ -108,16 +103,40 @@ export async function exportClientPdf(clientId: string, portId: string): Promise
|
||||
.from(yachts)
|
||||
.where(and(eq(yachts.portId, portId), isNull(yachts.archivedAt), or(...ownerConditions)));
|
||||
|
||||
const inputs = buildClientSummaryInputs(
|
||||
client,
|
||||
contactList,
|
||||
ownedYachts,
|
||||
enrichedInterests,
|
||||
activity,
|
||||
port ?? {},
|
||||
);
|
||||
const logo = await resolvePortLogo(portId);
|
||||
|
||||
return generatePdf(clientSummaryTemplate, [inputs]);
|
||||
return renderPdf(
|
||||
<ClientSummaryPdf
|
||||
portName={port?.name ?? 'Port Nimara'}
|
||||
logoBuffer={logo.buffer}
|
||||
client={{
|
||||
fullName: client.fullName,
|
||||
nationality: client.nationalityIso,
|
||||
source: client.source,
|
||||
createdAt: client.createdAt,
|
||||
}}
|
||||
contacts={contactList.map((c) => ({
|
||||
channel: c.channel,
|
||||
value: c.value,
|
||||
label: c.label,
|
||||
isPrimary: c.isPrimary,
|
||||
}))}
|
||||
yachts={ownedYachts}
|
||||
interests={enrichedInterests.map((i) => ({
|
||||
id: i.id,
|
||||
pipelineStage: i.pipelineStage,
|
||||
leadCategory: i.leadCategory,
|
||||
berthMooringNumber: i.berthMooringNumber,
|
||||
createdAt: i.createdAt,
|
||||
}))}
|
||||
activity={activity.map((a) => ({
|
||||
action: a.action,
|
||||
entityType: a.entityType,
|
||||
fieldChanged: a.fieldChanged,
|
||||
createdAt: a.createdAt,
|
||||
}))}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Export Berth PDF ─────────────────────────────────────────────────────────
|
||||
@@ -190,15 +209,64 @@ export async function exportBerthPdf(berthId: string, portId: string): Promise<U
|
||||
.orderBy(desc(interests.updatedAt))
|
||||
.limit(20);
|
||||
|
||||
const inputs = buildBerthSpecInputs(
|
||||
berth,
|
||||
enrichedWaitingList,
|
||||
maintenance,
|
||||
linkedInterests,
|
||||
port ?? {},
|
||||
);
|
||||
// linkedInterests not currently surfaced in the PDF (the old template
|
||||
// also omitted them); kept the query to preserve the existing data
|
||||
// contract until a future revision wants to surface them.
|
||||
void linkedInterests;
|
||||
|
||||
return generatePdf(berthSpecTemplate, [inputs]);
|
||||
const logo = await resolvePortLogo(portId);
|
||||
|
||||
return renderPdf(
|
||||
<BerthSpecPdf
|
||||
portName={port?.name ?? 'Port Nimara'}
|
||||
logoBuffer={logo.buffer}
|
||||
berth={{
|
||||
mooringNumber: berth.mooringNumber,
|
||||
area: berth.area,
|
||||
status: berth.status,
|
||||
nominalBoatSize: berth.nominalBoatSize,
|
||||
bowFacing: berth.bowFacing,
|
||||
lengthFt: berth.lengthFt,
|
||||
lengthM: berth.lengthM,
|
||||
widthFt: berth.widthFt,
|
||||
widthM: berth.widthM,
|
||||
widthIsMinimum: berth.widthIsMinimum,
|
||||
draftFt: berth.draftFt,
|
||||
draftM: berth.draftM,
|
||||
waterDepth: berth.waterDepth,
|
||||
waterDepthM: berth.waterDepthM,
|
||||
waterDepthIsMinimum: berth.waterDepthIsMinimum,
|
||||
price: berth.price,
|
||||
priceCurrency: berth.priceCurrency,
|
||||
tenureType: berth.tenureType,
|
||||
tenureYears: berth.tenureYears,
|
||||
tenureStartDate: berth.tenureStartDate,
|
||||
tenureEndDate: berth.tenureEndDate,
|
||||
mooringType: berth.mooringType,
|
||||
powerCapacity: berth.powerCapacity,
|
||||
voltage: berth.voltage,
|
||||
cleatType: berth.cleatType,
|
||||
cleatCapacity: berth.cleatCapacity,
|
||||
bollardType: berth.bollardType,
|
||||
bollardCapacity: berth.bollardCapacity,
|
||||
sidePontoon: berth.sidePontoon,
|
||||
access: berth.access,
|
||||
}}
|
||||
waitingList={enrichedWaitingList.map((w) => ({
|
||||
position: w.position,
|
||||
priority: w.priority,
|
||||
clientName: w.clientName,
|
||||
notes: w.notes,
|
||||
}))}
|
||||
maintenance={maintenance.map((m) => ({
|
||||
performedDate: m.performedDate,
|
||||
category: m.category,
|
||||
description: m.description,
|
||||
cost: m.cost,
|
||||
costCurrency: m.costCurrency,
|
||||
}))}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Export Interest PDF ──────────────────────────────────────────────────────
|
||||
@@ -243,14 +311,58 @@ export async function exportInterestPdf(interestId: string, portId: string): Pro
|
||||
.orderBy(desc(auditLogs.createdAt))
|
||||
.limit(20);
|
||||
|
||||
const inputs = buildInterestSummaryInputs(
|
||||
interest,
|
||||
client ?? {},
|
||||
yacht ?? null,
|
||||
berth ?? null,
|
||||
timeline,
|
||||
port ?? {},
|
||||
);
|
||||
const logo = await resolvePortLogo(portId);
|
||||
|
||||
return generatePdf(interestSummaryTemplate, [inputs]);
|
||||
return renderPdf(
|
||||
<InterestSummaryPdf
|
||||
portName={port?.name ?? 'Port Nimara'}
|
||||
logoBuffer={logo.buffer}
|
||||
interest={{
|
||||
id: interest.id,
|
||||
pipelineStage: interest.pipelineStage,
|
||||
leadCategory: interest.leadCategory,
|
||||
source: interest.source,
|
||||
eoiStatus: interest.eoiStatus,
|
||||
contractStatus: interest.contractStatus,
|
||||
depositStatus: interest.depositStatus,
|
||||
dateFirstContact: interest.dateFirstContact,
|
||||
dateLastContact: interest.dateLastContact,
|
||||
dateEoiSent: interest.dateEoiSent,
|
||||
dateEoiSigned: interest.dateEoiSigned,
|
||||
dateContractSent: interest.dateContractSent,
|
||||
dateContractSigned: interest.dateContractSigned,
|
||||
dateDepositReceived: interest.dateDepositReceived,
|
||||
}}
|
||||
client={client ? { fullName: client.fullName } : { fullName: null }}
|
||||
yacht={
|
||||
yacht
|
||||
? {
|
||||
name: yacht.name,
|
||||
lengthFt: yacht.lengthFt,
|
||||
lengthM: yacht.lengthM,
|
||||
widthFt: yacht.widthFt,
|
||||
draftFt: yacht.draftFt,
|
||||
}
|
||||
: null
|
||||
}
|
||||
berth={
|
||||
berth
|
||||
? {
|
||||
mooringNumber: berth.mooringNumber,
|
||||
area: berth.area,
|
||||
lengthFt: berth.lengthFt,
|
||||
price: berth.price,
|
||||
priceCurrency: berth.priceCurrency,
|
||||
status: berth.status,
|
||||
}
|
||||
: null
|
||||
}
|
||||
timeline={timeline.map((t) => ({
|
||||
createdAt: t.createdAt,
|
||||
action: t.action,
|
||||
entityType: t.entityType,
|
||||
fieldChanged: t.fieldChanged,
|
||||
}))}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user