feat(pipeline): 9→7 stage refactor + v1.1 hardening wave

Replaces the legacy 9-stage pipeline with 7 canonical stages
(enquiry → qualified → eoi → reservation → deposit_paid → contract →
nurturing) plus three doc sub-status columns (eoi_doc_status,
reservation_doc_status, contract_doc_status) that track sent/signed
within a single stage instead of branching it.

Schema (migration 0062):
- interests gains assigned_to, deposit_expected_amount/currency,
  three doc-status columns, two documenso-id columns, and
  date_reservation_signed.
- New tables: qualification_criteria (per-port admin-configurable),
  interest_qualifications (per-interest state), payments (deposit /
  balance / refund records keyed to interest + client).
- Default qualification criteria seeded for every existing port.
- Dummy-data UPDATEs collapse Sent/Signed pairs and 'completed' into
  the new stage + doc-status + outcome shape.

Migration 0063 adds interest_contact_log.voice_transcript and
template_used columns for v1.1-A/B (quick-template buttons + voice
transcription via Web Speech API).

v1.1 phase work bundled here:
- A/B: Quick-template buttons (Call / Visit / Email) + mic toggle on
       the contact-log compose dialog (useVoiceTranscription hook).
- C:   berth-rules-engine wraps state writes in pg_advisory_xact_lock
       with an idempotent re-read; emits rule_evaluated audit traces.
- D:   Documenso webhook: reservation/contract sub-status stamping
       moved out of the PDF-download try-block so a download failure
       no longer swallows the stamp. New integration test coverage.
- E:   /admin/qualification-criteria CRUD page + admin component.
- F:   default_new_interest_owner exposed in System Settings.
- G:   recentActivityCount + active_engagement deal-pulse signal
       surfaced as a chip on interests + hot-deals card.
- H:   interest_assigned notification on assignedTo change (skips
       self-assign, uses a dedupe key).

Plus the supporting components: AssignedToChip, DealPulseChip,
PaymentsSection, QualificationChecklist, MultiEoiChip,
SkipAheadBanner, WonStatusPanel, InterestBerthStatusBanner,
SupplementalInfoRequestButton, UserPicker.

Tests: 1370/1370 vitest pass (added deal-health unit suite +
expanded constants/validators/pipeline-transitions coverage). tsc
clean, eslint clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-14 03:39:21 +02:00
parent b10bf9bf8e
commit 6b28459c45
110 changed files with 5402 additions and 796 deletions

View File

@@ -2,7 +2,8 @@
import Link from 'next/link';
import { format } from 'date-fns';
import { MoreHorizontal, Pencil, Archive, Mail, MessageCircle, Phone } from 'lucide-react';
import { MoreHorizontal, Pencil, Archive, Mail, Phone } from 'lucide-react';
import { WhatsAppIcon } from '@/components/icons/whatsapp';
import type { ColumnDef } from '@tanstack/react-table';
import { Button } from '@/components/ui/button';
@@ -160,7 +161,7 @@ export function getClientColumns({
title={`WhatsApp ${value}`}
aria-label={`WhatsApp ${value}`}
>
<MessageCircle className="h-3.5 w-3.5" aria-hidden />
<WhatsAppIcon className="h-3.5 w-3.5" />
</a>
)}
</span>

View File

@@ -2,7 +2,8 @@
import { useRouter } from 'next/navigation';
import { useState } from 'react';
import { Archive, Mail, MessageCircle, Phone, RotateCcw, Trash2 } from 'lucide-react';
import { Archive, Mail, Phone, RotateCcw, Trash2 } from 'lucide-react';
import { WhatsAppIcon } from '@/components/icons/whatsapp';
import { format } from 'date-fns';
import { Button } from '@/components/ui/button';
@@ -126,7 +127,7 @@ export function ClientDetailHeader({ client }: ClientDetailHeaderProps) {
rel="noopener noreferrer"
aria-label={`Message ${primaryPhone} on WhatsApp`}
>
<MessageCircle />
<WhatsAppIcon className="h-4 w-4" />
WhatsApp
</a>
</Button>

View File

@@ -236,7 +236,7 @@ export function ClientForm({ open, onOpenChange, client, onUseExistingClient }:
<div className="space-y-3">
{fields.map((field, index) => (
<div key={field.id} className="space-y-3 p-3 rounded-lg border bg-muted/30">
<div className="grid grid-cols-1 gap-3 sm:grid-cols-12 sm:items-end sm:gap-2">
<div className="grid grid-cols-1 gap-3 sm:grid-cols-12 sm:items-start sm:gap-2">
<div className="space-y-1 sm:col-span-3">
<Label className="text-xs">Channel</Label>
<Select

View File

@@ -113,6 +113,9 @@ interface InterestDetail {
dateDepositReceived: string | null;
dateContractSent: string | null;
dateContractSigned: string | null;
eoiDocStatus: string | null;
reservationDocStatus: string | null;
contractDocStatus: string | null;
}
function useInterestDetail(id: string | null) {
@@ -272,12 +275,16 @@ function InterestPreviewSheet({
<ul>
<MilestoneRow
label="EOI sent"
done={reached('eoi_sent') || !!fullDetail?.dateEoiSent}
done={reached('eoi') || !!fullDetail?.dateEoiSent}
date={formatDate(fullDetail?.dateEoiSent)}
/>
<MilestoneRow
label="EOI signed"
done={reached('eoi_signed') || !!fullDetail?.dateEoiSigned}
done={
fullDetail?.eoiDocStatus === 'signed' ||
stageIdx > PIPELINE_STAGES.indexOf('eoi') ||
!!fullDetail?.dateEoiSigned
}
date={formatDate(fullDetail?.dateEoiSigned)}
/>
</ul>
@@ -287,7 +294,7 @@ function InterestPreviewSheet({
<ul>
<MilestoneRow
label="Deposit received"
done={reached('deposit_10pct') || !!fullDetail?.dateDepositReceived}
done={reached('deposit_paid') || !!fullDetail?.dateDepositReceived}
date={formatDate(fullDetail?.dateDepositReceived)}
/>
</ul>
@@ -297,12 +304,14 @@ function InterestPreviewSheet({
<ul>
<MilestoneRow
label="Contract sent"
done={reached('contract_sent') || !!fullDetail?.dateContractSent}
done={reached('contract') || !!fullDetail?.dateContractSent}
date={formatDate(fullDetail?.dateContractSent)}
/>
<MilestoneRow
label="Contract signed"
done={reached('contract_signed') || !!fullDetail?.dateContractSigned}
done={
fullDetail?.contractDocStatus === 'signed' || !!fullDetail?.dateContractSigned
}
date={formatDate(fullDetail?.dateContractSigned)}
/>
</ul>

View File

@@ -78,6 +78,7 @@ export function ClientList() {
setPageSize,
filters,
setFilter,
setAllFilters,
clearFilters,
} = usePaginatedQuery<ClientRow>({
queryKey: ['clients'],
@@ -152,8 +153,11 @@ export function ClientList() {
<SavedViewsDropdown
entityType="clients"
onApplyView={(savedFilters, _savedSort) => {
clearFilters();
Object.entries(savedFilters).forEach(([key, val]) => setFilter(key, val));
// Atomic replace — sequential setFilter() calls dropped all
// but the last value (each one read stale `filters` from
// closure and overwrote). setAllFilters writes the whole
// saved view in one setState.
setAllFilters(savedFilters);
}}
/>
<ColumnPicker

View File

@@ -219,15 +219,12 @@ function OverviewTab({
</dl>
</div>
{/* Tags */}
<div className="space-y-1">
<h3 className="text-sm font-medium mb-2">Tags</h3>
<InlineTagEditor
endpoint={`/api/v1/clients/${clientId}/tags`}
currentTags={client.tags ?? []}
invalidateKey={['clients', clientId]}
/>
</div>
<InlineTagEditor
heading="Tags"
endpoint={`/api/v1/clients/${clientId}/tags`}
currentTags={client.tags ?? []}
invalidateKey={['clients', clientId]}
/>
</div>
</div>
);

View File

@@ -2,16 +2,8 @@
import { useState } from 'react';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import {
Loader2,
Mail,
MessageSquare,
MoreHorizontal,
Phone,
Plus,
Star,
Trash2,
} from 'lucide-react';
import { Loader2, Mail, MoreHorizontal, Phone, Plus, Star, Trash2 } from 'lucide-react';
import { WhatsAppIcon } from '@/components/icons/whatsapp';
import { toast } from 'sonner';
import { Button } from '@/components/ui/button';
@@ -51,7 +43,7 @@ const CHANNEL_OPTIONS = [
const CHANNEL_ICONS: Record<string, React.ComponentType<{ className?: string }>> = {
email: Mail,
phone: Phone,
whatsapp: MessageSquare,
whatsapp: WhatsAppIcon,
other: MoreHorizontal,
};