feat(berths): website auto-promote toggle + manual-override soft-pin priority
- website_berth_autopromote_enabled (default OFF): a website registration for a specific, currently-available berth auto-creates a prospect (client + optional yacht + interest) and links the berth is_specific_interest=true, flipping the public map to Under Offer; general/residence/contact submissions stay capture-only. Marks the submission converted so a rep never double-creates it. - derivePublicStatus now honours a manual pin (soft pin): a manually-set status wins over the interest-derived Under Offer, but a real permanent tenancy or an explicit sold still override it. - berth rules engine respects a manual pin EXCEPT for sale triggers (-> sold), so a confirmed sale still wins but soft auto-changes never stomp a pin. - Reset-to-automatic action (service + API POST /berths/[id]/status/reset + UI) to drop a manual pin; lock badge on every manual override (list + detail); divergence banner prompting reset when a pinned-Available berth has a deal. - migration stage map updated to the §4b signed-off mapping: GQI -> enquiry unless it named a berth/size marker (-> qualified); SQI -> qualified. Tests: +public-berths soft-pin cases, +website-intake-promote helpers, +migration GQI marker rule. 1582 unit/integration green; tsc clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState } from 'react';
|
||||
import { type ColumnDef } from '@tanstack/react-table';
|
||||
import { MoreHorizontal, Pencil, Activity, RefreshCw } from 'lucide-react';
|
||||
import { MoreHorizontal, Pencil, Activity, RefreshCw, Lock } from 'lucide-react';
|
||||
import { useRouter, useParams } from 'next/navigation';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
@@ -150,17 +150,29 @@ function StatusBadge({ status }: { status: string }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* #67 Phase 2: small amber chip beside the status pill flagging rows
|
||||
* whose status was set manually and has no backing interest. These are
|
||||
* the candidates for the catch-up wizard - the rep flipped a berth to
|
||||
* "Under Offer" or "Sold" without ever creating the matching deal.
|
||||
* Chip beside the status pill flagging a manually-pinned status (wins over
|
||||
* automatic derivation). Two variants:
|
||||
* - 'catchup' (amber): manual AND no backing interest - a candidate for the
|
||||
* catch-up wizard (rep flipped to Under Offer/Sold without a matching deal).
|
||||
* - 'pinned' (slate + lock): manual WITH a backing deal - a deliberate pin.
|
||||
*/
|
||||
function ManualBadge() {
|
||||
function ManualBadge({ variant }: { variant: 'catchup' | 'pinned' }) {
|
||||
if (variant === 'catchup') {
|
||||
return (
|
||||
<span
|
||||
className="inline-flex items-center rounded-full border border-amber-300 bg-amber-50 px-1.5 py-0.5 text-xs font-medium uppercase tracking-wide text-amber-800"
|
||||
title="Status set manually with no backing interest - needs catch-up"
|
||||
>
|
||||
Manual
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<span
|
||||
className="inline-flex items-center rounded-full border border-amber-300 bg-amber-50 px-1.5 py-0.5 text-xs font-medium uppercase tracking-wide text-amber-800"
|
||||
title="Status set manually with no backing interest - needs catch-up"
|
||||
className="inline-flex items-center gap-1 rounded-full border border-slate-300 bg-slate-100 px-1.5 py-0.5 text-xs font-medium text-slate-700"
|
||||
title="Status pinned manually - wins over automatic derivation"
|
||||
>
|
||||
<Lock className="h-3 w-3" aria-hidden />
|
||||
Manual
|
||||
</span>
|
||||
);
|
||||
@@ -326,11 +338,12 @@ export const berthColumns: ColumnDef<BerthRow, unknown>[] = [
|
||||
header: 'Status',
|
||||
cell: ({ row }) => {
|
||||
const r = row.original;
|
||||
const isManualUnreconciled = r.statusOverrideMode === 'manual' && !r.latestInterestStage;
|
||||
const isManual = r.statusOverrideMode === 'manual';
|
||||
const isManualUnreconciled = isManual && !r.latestInterestStage;
|
||||
return (
|
||||
<div className="inline-flex items-center gap-1.5">
|
||||
<StatusBadge status={r.status} />
|
||||
{isManualUnreconciled ? <ManualBadge /> : null}
|
||||
{isManual ? <ManualBadge variant={isManualUnreconciled ? 'catchup' : 'pinned'} /> : null}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { Check, ChevronsUpDown, Pencil, RefreshCw } from 'lucide-react';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { Check, ChevronsUpDown, Lock, Pencil, RefreshCw, RotateCcw } from 'lucide-react';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { toast } from 'sonner';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
@@ -84,6 +84,12 @@ export type BerthDetailData = {
|
||||
berthApproved: boolean | null;
|
||||
statusLastChangedReason: string | null;
|
||||
statusLastModified: string | null;
|
||||
/** 'manual' = a human pinned this status (wins over derived signals);
|
||||
* 'automated' = set by the rules engine; null = pure derived. */
|
||||
statusOverrideMode: string | null;
|
||||
/** Pipeline stage of the most recent active interest on this berth, if any.
|
||||
* Used to flag a manual pin that diverges from an active deal. */
|
||||
latestInterestStage: string | null;
|
||||
tags: Array<{ id: string; name: string; color: string }>;
|
||||
};
|
||||
|
||||
@@ -258,9 +264,89 @@ function StatusChangeDialog({
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm dialog for "Reset to automatic" - drops the manual pin so the berth
|
||||
* resumes derived status. A reason is required (audit trail). An optional
|
||||
* `defaultReason` pre-fills the box for the one-click banner path.
|
||||
*/
|
||||
function ResetOverrideDialog({
|
||||
berthId,
|
||||
open,
|
||||
onOpenChange,
|
||||
defaultReason = '',
|
||||
}: {
|
||||
berthId: string;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
defaultReason?: string;
|
||||
}) {
|
||||
const queryClient = useQueryClient();
|
||||
const [reason, setReason] = useState(defaultReason);
|
||||
|
||||
const resetMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
apiFetch(`/api/v1/berths/${berthId}/status/reset`, {
|
||||
method: 'POST',
|
||||
body: { reason: reason.trim() || 'Resumed automatic status' },
|
||||
}),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['berths'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['berth', berthId] });
|
||||
toast.success('Berth reset to automatic status');
|
||||
onOpenChange(false);
|
||||
},
|
||||
onError: (err) => toastError(err),
|
||||
});
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Reset to automatic status</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-3">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
This removes the manual pin so the berth's public status is governed by its
|
||||
interests and tenancies again. The displayed status may change immediately.
|
||||
</p>
|
||||
<div className="space-y-2">
|
||||
<Label>Reason *</Label>
|
||||
<Textarea
|
||||
value={reason}
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
placeholder="Why are you dropping the manual pin?"
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter className="gap-2">
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => resetMutation.mutate()}
|
||||
disabled={resetMutation.isPending || reason.trim().length === 0}
|
||||
>
|
||||
Reset to automatic
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export function BerthDetailHeader({ berth }: BerthDetailHeaderProps) {
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [statusOpen, setStatusOpen] = useState(false);
|
||||
const [resetOpen, setResetOpen] = useState(false);
|
||||
|
||||
const isManualPin = berth.statusOverrideMode === 'manual';
|
||||
// Divergence the rep should resolve: a berth manually pinned "Available"
|
||||
// that nevertheless has an active deal on it - the public map shows
|
||||
// Available even though something is happening. Prompt to resume automatic
|
||||
// (which derives "Under Offer" from the active specific-interest link).
|
||||
const pinDivergesFromDeal =
|
||||
isManualPin && berth.status === 'available' && !!berth.latestInterestStage;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -292,6 +378,19 @@ export function BerthDetailHeader({ berth }: BerthDetailHeaderProps) {
|
||||
>
|
||||
{STATUS_LABELS[berth.status] ?? berth.status}
|
||||
</StatusPill>
|
||||
{isManualPin && (
|
||||
<span
|
||||
className="inline-flex items-center gap-1 rounded-full border border-slate-300 bg-slate-100 px-2 py-0.5 text-xs font-medium text-slate-700"
|
||||
title={
|
||||
berth.statusLastChangedReason
|
||||
? `Manually set status (wins over automatic). Reason: ${berth.statusLastChangedReason}`
|
||||
: 'Manually set status - wins over automatic derivation'
|
||||
}
|
||||
>
|
||||
<Lock className="h-3 w-3" aria-hidden />
|
||||
Manual
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2 sm:shrink-0">
|
||||
@@ -300,6 +399,12 @@ export function BerthDetailHeader({ berth }: BerthDetailHeaderProps) {
|
||||
<RefreshCw className="mr-1.5 h-4 w-4" aria-hidden />
|
||||
Change Status
|
||||
</Button>
|
||||
{isManualPin && (
|
||||
<Button variant="outline" size="sm" onClick={() => setResetOpen(true)}>
|
||||
<RotateCcw className="mr-1.5 h-4 w-4" aria-hidden />
|
||||
Reset to automatic
|
||||
</Button>
|
||||
)}
|
||||
<Button size="sm" onClick={() => setEditOpen(true)}>
|
||||
<Pencil className="mr-1.5 h-4 w-4" aria-hidden />
|
||||
Edit
|
||||
@@ -309,6 +414,26 @@ export function BerthDetailHeader({ berth }: BerthDetailHeaderProps) {
|
||||
</div>
|
||||
</DetailHeaderStrip>
|
||||
|
||||
{pinDivergesFromDeal && (
|
||||
<PermissionGate resource="berths" action="edit">
|
||||
<div className="mt-2 flex flex-col gap-2 rounded-lg border border-amber-300 bg-amber-50 px-4 py-3 text-sm text-amber-900 sm:flex-row sm:items-center sm:justify-between">
|
||||
<span>
|
||||
This berth is manually pinned <strong>Available</strong>, but it has an active deal.
|
||||
The public map will keep showing Available until you reset it.
|
||||
</span>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="shrink-0 border-amber-400 bg-white hover:bg-amber-100"
|
||||
onClick={() => setResetOpen(true)}
|
||||
>
|
||||
<RotateCcw className="mr-1.5 h-4 w-4" aria-hidden />
|
||||
Reset to automatic
|
||||
</Button>
|
||||
</div>
|
||||
</PermissionGate>
|
||||
)}
|
||||
|
||||
<BerthForm berth={berth} open={editOpen} onOpenChange={setEditOpen} />
|
||||
|
||||
<StatusChangeDialog
|
||||
@@ -317,6 +442,13 @@ export function BerthDetailHeader({ berth }: BerthDetailHeaderProps) {
|
||||
open={statusOpen}
|
||||
onOpenChange={setStatusOpen}
|
||||
/>
|
||||
|
||||
<ResetOverrideDialog
|
||||
berthId={berth.id}
|
||||
open={resetOpen}
|
||||
onOpenChange={setResetOpen}
|
||||
defaultReason={pinDivergesFromDeal ? 'Resumed automatic status - active deal present' : ''}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user