Files
pn-new-crm/src/app/(portal)/portal/interests/page.tsx
Matt 689a114aba fix(audit-wave-9): copy/terminology sweep (copy-auditor)
Address the highest-impact items from the copy-auditor's CRITICAL +
HIGH + MEDIUM bands:

**C2 portal raw-status leak**
- Drop the staff-only `leadCategory` chip from the portal interests
  page entirely. Privacy + optics: clients should never see "hot lead"
  in their own portal. `eoiStatus` was already wrapped in
  `portalSigningLabel`; only the categorical chip remained.

**C3 signing-status label drift**
- Add `src/lib/labels/document-status.ts` as the single source of
  truth for the {draft, sent, partially_signed, completed, expired,
  cancelled} lifecycle: labels (CRM + portal variants), StatusPill
  variant, and the "active / in-flight" set.
- Wire it into interest-eoi-tab, interest-contract-tab,
  interest-reservation-tab — they previously redefined identical
  STATUS_LABELS / ACTIVE_STATUSES blocks per-file.

**H1 + M3 verbiage codemod**
- `Save Changes` → `Save changes` (sentence case, matches the
  surrounding admin/CRM pattern).
- `Saving...` (ASCII three dots) → `Saving…` (Unicode ellipsis).
  Matches the project's UTF-8-elsewhere convention and reads
  correctly via screen-readers.

**M1 envelope jargon → signing request**
- smart-archive-dialog: "Leave envelope pending" → "Leave signing
  request pending"; "Void the signing envelope" → "Cancel the signing
  request"; section header updated to match.
- document-detail: "voids the signing envelope" → "cancels the signing
  request".
- bulk-archive-wizard: "leave invoices/signing envelopes alone" →
  "leave invoices/signing requests alone".
- Documenso admin page intentionally keeps `envelope` (dev/integration
  vocabulary).

**M5 Hot Lead casing**
- Normalize `Hot Lead` / `General Interest` / `Specific Qualified` to
  sentence case in `constants.ts` LABEL_OVERRIDES and all per-file
  lead-category maps so the CRM trend (sentence case) is consistent.

**C1 surface-level rename**
- "Linked prospect (optional)" → "Linked interest (optional)" on the
  berth status-change dialog.
- "Deal Documents" tab → "Interest Documents" (URL/route kept as
  `/deal-documents` to avoid breaking deep links; rename deferred).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 12:12:40 +02:00

123 lines
4.8 KiB
TypeScript

import { redirect } from 'next/navigation';
import { Anchor } from 'lucide-react';
import type { Metadata } from 'next';
import { getPortalSession } from '@/lib/portal/auth';
import { getClientInterests } from '@/lib/services/portal.service';
import { Badge } from '@/components/ui/badge';
import { stageLabel, safeStage, type PipelineStage } from '@/lib/constants';
export const metadata: Metadata = { title: 'Interests' };
// Portal-friendly labels for signing-process status fields. The audit
// caught raw enum leak ("waiting_for_signatures" with underscores) at
// the client-facing surface. Map every known value to plain English;
// fall back to a Title-Case rendering for any new states.
const PORTAL_SIGNING_LABELS: Record<string, string> = {
not_started: 'Not started',
draft: 'Drafted',
awaiting_them: 'Awaiting their signature',
awaiting_me: 'Awaiting your signature',
waiting_for_signatures: 'Waiting for signatures',
partially_signed: 'Partially signed',
sent: 'Sent for signing',
signed: 'Signed',
completed: 'Signed',
expired: 'Expired',
cancelled: 'Cancelled',
rejected: 'Rejected',
};
function portalSigningLabel(status: string): string {
if (status in PORTAL_SIGNING_LABELS) return PORTAL_SIGNING_LABELS[status]!;
return status
.split('_')
.map((p) => (p ? p[0]!.toUpperCase() + p.slice(1) : p))
.join(' ');
}
const STAGE_VARIANT: Record<PipelineStage, 'default' | 'secondary' | 'destructive' | 'outline'> = {
open: 'secondary',
details_sent: 'secondary',
in_communication: 'default',
eoi_sent: 'default',
eoi_signed: 'default',
deposit_10pct: 'default',
contract_sent: 'default',
contract_signed: 'default',
completed: 'outline',
};
export default async function PortalInterestsPage() {
const session = await getPortalSession();
if (!session) redirect('/portal/login');
const interests = await getClientInterests(session.clientId, session.portId);
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold text-gray-900">Berth Interests</h1>
<p className="text-sm text-gray-500 mt-1">Your berth enquiries and applications</p>
</div>
{interests.length === 0 ? (
<div className="bg-white rounded-lg border p-12 text-center">
<Anchor className="h-10 w-10 text-gray-300 mx-auto mb-3" />
<p className="text-gray-500 font-medium">No interests on file</p>
<p className="text-sm text-gray-400 mt-1">
Contact your port representative to discuss available berths.
</p>
</div>
) : (
<div className="space-y-3">
{interests.map((interest) => (
<div key={interest.id} className="bg-white rounded-lg border p-5">
<div className="flex items-start justify-between gap-4">
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 mb-1">
{interest.berthMooringNumber ? (
<span className="font-medium text-gray-900">
Berth {interest.berthMooringNumber}
</span>
) : (
<span className="font-medium text-gray-900">General Interest</span>
)}
{interest.berthArea && (
<span className="text-sm text-gray-400">- {interest.berthArea}</span>
)}
</div>
{/* leadCategory ("hot_lead" / "qualified_lead" / etc.)
is a staff classification — never render to clients.
Privacy + optics: we shouldn't be telling the
prospect they're a "hot lead". */}
<div className="flex flex-wrap gap-2 mt-2 text-xs text-gray-400">
{interest.dateFirstContact && (
<span>
First contact:{' '}
{new Date(interest.dateFirstContact).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
})}
</span>
)}
{interest.eoiStatus && (
<span>EOI: {portalSigningLabel(interest.eoiStatus)}</span>
)}
{interest.contractStatus && (
<span>Contract: {portalSigningLabel(interest.contractStatus)}</span>
)}
</div>
</div>
<Badge variant={STAGE_VARIANT[safeStage(interest.pipelineStage)]}>
{stageLabel(interest.pipelineStage)}
</Badge>
</div>
</div>
))}
</div>
)}
</div>
);
}