feat(launch-readiness-batch): UAT drains, navigation refactor, launch infra, trackers
Bundles the rest of the in-flight work from this UAT round into one
checkpoint. Each sub-area is independent; see the headings below.
UAT polish (drained 11 findings from active-uat.md):
- Dialog primitive default bumped sm:max-w-xl/lg:max-w-3xl →
sm:max-w-2xl/lg:max-w-4xl so multi-field forms + PDF previews
aren't cramped at 1440-1920px.
- Notes tab badge aggregation: new countFor{Client,Yacht,Company}
Aggregated helpers in notes.service mirror the listFor*Aggregated
symmetric-reach joins. yacht-tabs + company-tabs render the
badge; client-tabs already had badge support.
- Supplemental-info form polish bundle: BrandedAuthShell gains a
`width: 'sm' | 'md'` prop (md uses min-h-dvh scroll instead of
fixed inset-0 pin so long forms scroll naturally). Form picks up
port branding (logoUrl + backgroundUrl + appName) via
loadByToken. Address fields completed (street + city + region +
postal + country). Port name eyebrow + success-state copy added.
- new-document-menu Upload-file landing toast: per-file completion
emits toast.success with action link to the destination entity
or folder.
- interest-tabs OverviewTab "from client" pill on Email + Phone
rows via new EditableRow `inheritedFrom` prop.
- create-document-wizard subject picker → segmented button strip
(5 types visible at once).
Launch infra:
- UTM column wiring (Init 1b step 4): migration
0089_website_submissions_utm.sql adds utm_source/medium/campaign/
term/content + composite index (port_id, utm_source, received_at)
for per-campaign rollups. website-inquiries intake accepts the
five fields. Residential intake intentionally untouched per audit
scope.
- Invoicing module gate (Init 1c spike): new
invoices-module.service + invoices layout guard + registry entry
invoices_module_enabled (default false). Audit conclusion in
launch-readiness.md: payments table is canonical money path;
/invoices flow is parallel infrastructure now hidden by default.
Smart-back navigation refactor:
- Replaced breadcrumb component with history-aware Back button.
New route-labels.ts + use-smart-back hook +
navigation-history-tracker so back falls through to the parent
route when there's no prior page in history.
- Sidebar / topbar / mobile-topbar adopt the new pattern; old
breadcrumb-store kept for back-compat consumers but the
breadcrumbs component is gone.
- 6 detail pages (admin/errors per-id + codes, invoices/
upload-receipts, reports kind, tenancies detail, analytics
metric, client detail) migrated.
Trackers + docs:
- docs/launch-readiness.md — master pre-launch tracker. Includes
the reports gap audit (cross-cutting filter set, Marketing +
Financial blockers, custom builder remaining entities, scheduled
CSV/XLSX, template scope picker).
- docs/superpowers/audits/active-uat.md — 15 findings flipped
OPEN → SHIPPED locally with fix-applied notes; 4 OPEN remaining
(each blocked on user input or cross-repo).
- CLAUDE.md — minor session notes carried forward.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { eq, and, desc, inArray } from 'drizzle-orm';
|
||||
import { eq, and, desc, inArray, sql, isNull } from 'drizzle-orm';
|
||||
|
||||
import { db } from '@/lib/db';
|
||||
import { clientNotes, clients } from '@/lib/db/schema/clients';
|
||||
import { interestNotes, interests } from '@/lib/db/schema/interests';
|
||||
import { yachtNotes, yachts } from '@/lib/db/schema/yachts';
|
||||
import { companyNotes, companies } from '@/lib/db/schema/companies';
|
||||
import { companyNotes, companies, companyMemberships } from '@/lib/db/schema/companies';
|
||||
import {
|
||||
residentialClients,
|
||||
residentialClientNotes,
|
||||
@@ -111,6 +111,218 @@ export interface AggregatedClientNote {
|
||||
pipelineStageAtCreation?: string | null;
|
||||
}
|
||||
|
||||
// ─── Aggregated counts ──────────────────────────────────────────────────────
|
||||
//
|
||||
// Mirror the symmetric-reach unions used by the `listFor*Aggregated`
|
||||
// helpers, but return scalar totals so tab badges on entity detail
|
||||
// pages match what the NotesList renders below them. Each function is
|
||||
// port-scoped (defense-in-depth) and tolerates zero linked-entity ids
|
||||
// by short-circuiting the relevant counts to 0.
|
||||
|
||||
async function scalarCount(query: Promise<Array<{ count: number }>>): Promise<number> {
|
||||
const rows = await query;
|
||||
return rows[0]?.count ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Total note count visible on a client's Notes tab = direct
|
||||
* client_notes + interest_notes (interests where client_id=X) +
|
||||
* yacht_notes (yachts currently owned by this client) +
|
||||
* company_notes (companies the client has an active membership in).
|
||||
*/
|
||||
export async function countForClientAggregated(portId: string, clientId: string): Promise<number> {
|
||||
await verifyParentBelongsToPort('clients', clientId, portId);
|
||||
|
||||
const [interestRows, yachtRows, membershipRows] = await Promise.all([
|
||||
db
|
||||
.select({ id: interests.id })
|
||||
.from(interests)
|
||||
.where(and(eq(interests.clientId, clientId), eq(interests.portId, portId))),
|
||||
db
|
||||
.select({ id: yachts.id })
|
||||
.from(yachts)
|
||||
.where(
|
||||
and(
|
||||
eq(yachts.portId, portId),
|
||||
eq(yachts.currentOwnerType, 'client'),
|
||||
eq(yachts.currentOwnerId, clientId),
|
||||
),
|
||||
),
|
||||
db
|
||||
.select({ companyId: companyMemberships.companyId })
|
||||
.from(companyMemberships)
|
||||
.innerJoin(companies, eq(companies.id, companyMemberships.companyId))
|
||||
.where(
|
||||
and(
|
||||
eq(companyMemberships.clientId, clientId),
|
||||
isNull(companyMemberships.endDate),
|
||||
eq(companies.portId, portId),
|
||||
),
|
||||
),
|
||||
]);
|
||||
|
||||
const interestIds = interestRows.map((r) => r.id);
|
||||
const yachtIds = yachtRows.map((r) => r.id);
|
||||
const companyIds = Array.from(new Set(membershipRows.map((r) => r.companyId)));
|
||||
|
||||
const [clientCount, interestCount, yachtCount, companyCount] = await Promise.all([
|
||||
scalarCount(
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(clientNotes)
|
||||
.where(eq(clientNotes.clientId, clientId)),
|
||||
),
|
||||
interestIds.length > 0
|
||||
? scalarCount(
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(interestNotes)
|
||||
.where(inArray(interestNotes.interestId, interestIds)),
|
||||
)
|
||||
: Promise.resolve(0),
|
||||
yachtIds.length > 0
|
||||
? scalarCount(
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(yachtNotes)
|
||||
.where(inArray(yachtNotes.yachtId, yachtIds)),
|
||||
)
|
||||
: Promise.resolve(0),
|
||||
companyIds.length > 0
|
||||
? scalarCount(
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(companyNotes)
|
||||
.where(inArray(companyNotes.companyId, companyIds)),
|
||||
)
|
||||
: Promise.resolve(0),
|
||||
]);
|
||||
|
||||
return clientCount + interestCount + yachtCount + companyCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Total note count visible on a yacht's Notes tab = direct
|
||||
* yacht_notes + the polymorphic owner-side notes (client_notes when
|
||||
* owner_type='client', company_notes when owner_type='company') +
|
||||
* interest_notes (interests currently linked to this yacht).
|
||||
*/
|
||||
export async function countForYachtAggregated(portId: string, yachtId: string): Promise<number> {
|
||||
await verifyParentBelongsToPort('yachts', yachtId, portId);
|
||||
|
||||
const [yacht] = await db
|
||||
.select({
|
||||
id: yachts.id,
|
||||
ownerType: yachts.currentOwnerType,
|
||||
ownerId: yachts.currentOwnerId,
|
||||
})
|
||||
.from(yachts)
|
||||
.where(and(eq(yachts.id, yachtId), eq(yachts.portId, portId)))
|
||||
.limit(1);
|
||||
if (!yacht) throw new NotFoundError('Yacht');
|
||||
|
||||
const interestRows = await db
|
||||
.select({ id: interests.id })
|
||||
.from(interests)
|
||||
.where(and(eq(interests.yachtId, yachtId), eq(interests.portId, portId)));
|
||||
const interestIds = interestRows.map((r) => r.id);
|
||||
|
||||
const [yachtCount, ownerCount, interestCount] = await Promise.all([
|
||||
scalarCount(
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(yachtNotes)
|
||||
.where(eq(yachtNotes.yachtId, yachtId)),
|
||||
),
|
||||
yacht.ownerType === 'client' && yacht.ownerId
|
||||
? scalarCount(
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(clientNotes)
|
||||
.where(eq(clientNotes.clientId, yacht.ownerId)),
|
||||
)
|
||||
: yacht.ownerType === 'company' && yacht.ownerId
|
||||
? scalarCount(
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(companyNotes)
|
||||
.where(eq(companyNotes.companyId, yacht.ownerId)),
|
||||
)
|
||||
: Promise.resolve(0),
|
||||
interestIds.length > 0
|
||||
? scalarCount(
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(interestNotes)
|
||||
.where(inArray(interestNotes.interestId, interestIds)),
|
||||
)
|
||||
: Promise.resolve(0),
|
||||
]);
|
||||
|
||||
return yachtCount + ownerCount + interestCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Total note count visible on a company's Notes tab = direct
|
||||
* company_notes + yacht_notes (yachts owned by this company) +
|
||||
* interest_notes (interests linked via those yachts). Member-client
|
||||
* personal notes are NOT counted — they live on the client's dossier.
|
||||
*/
|
||||
export async function countForCompanyAggregated(
|
||||
portId: string,
|
||||
companyId: string,
|
||||
): Promise<number> {
|
||||
await verifyParentBelongsToPort('companies', companyId, portId);
|
||||
|
||||
const yachtRows = await db
|
||||
.select({ id: yachts.id })
|
||||
.from(yachts)
|
||||
.where(
|
||||
and(
|
||||
eq(yachts.portId, portId),
|
||||
eq(yachts.currentOwnerType, 'company'),
|
||||
eq(yachts.currentOwnerId, companyId),
|
||||
),
|
||||
);
|
||||
const yachtIds = yachtRows.map((r) => r.id);
|
||||
|
||||
const interestRows =
|
||||
yachtIds.length > 0
|
||||
? await db
|
||||
.select({ id: interests.id })
|
||||
.from(interests)
|
||||
.where(and(inArray(interests.yachtId, yachtIds), eq(interests.portId, portId)))
|
||||
: [];
|
||||
const interestIds = interestRows.map((r) => r.id);
|
||||
|
||||
const [companyCount, yachtCount, interestCount] = await Promise.all([
|
||||
scalarCount(
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(companyNotes)
|
||||
.where(eq(companyNotes.companyId, companyId)),
|
||||
),
|
||||
yachtIds.length > 0
|
||||
? scalarCount(
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(yachtNotes)
|
||||
.where(inArray(yachtNotes.yachtId, yachtIds)),
|
||||
)
|
||||
: Promise.resolve(0),
|
||||
interestIds.length > 0
|
||||
? scalarCount(
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(interestNotes)
|
||||
.where(inArray(interestNotes.interestId, interestIds)),
|
||||
)
|
||||
: Promise.resolve(0),
|
||||
]);
|
||||
|
||||
return companyCount + yachtCount + interestCount;
|
||||
}
|
||||
|
||||
export async function listForClientAggregated(
|
||||
portId: string,
|
||||
clientId: string,
|
||||
|
||||
Reference in New Issue
Block a user