'use client'; import Link from 'next/link'; import { useParams } from 'next/navigation'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { ArrowLeft } from 'lucide-react'; import { InlineEditableField } from '@/components/shared/inline-editable-field'; import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation'; import { apiFetch } from '@/lib/api/client'; import { PIPELINE_STAGES } from '@/lib/validators/residential'; interface ResidentialInterestDetail { id: string; residentialClientId: string; pipelineStage: string; source: string | null; notes: string | null; preferences: string | null; assignedTo: string | null; client: { id: string; fullName: string } | null; } const STAGE_LABELS: Record = { new: 'New', contacted: 'Contacted', viewing_scheduled: 'Viewing scheduled', offer_made: 'Offer made', offer_accepted: 'Offer accepted', closed_won: 'Closed — won', closed_lost: 'Closed — lost', }; const STAGE_OPTIONS = PIPELINE_STAGES.map((s) => ({ value: s, label: STAGE_LABELS[s] ?? s, })); const SOURCE_OPTIONS = [ { value: 'website', label: 'Website' }, { value: 'manual', label: 'Manual' }, { value: 'referral', label: 'Referral' }, { value: 'broker', label: 'Broker' }, ]; export function ResidentialInterestDetail({ interestId }: { interestId: string }) { const params = useParams<{ portSlug: string }>(); const portSlug = params?.portSlug ?? ''; const qc = useQueryClient(); const { data, isLoading } = useQuery<{ data: ResidentialInterestDetail }>({ queryKey: ['residential-interest', interestId], queryFn: () => apiFetch(`/api/v1/residential/interests/${interestId}`), }); useRealtimeInvalidation({ 'residential_interest:updated': [['residential-interest', interestId]], }); const update = useMutation({ mutationFn: (patch: Record) => apiFetch(`/api/v1/residential/interests/${interestId}`, { method: 'PATCH', body: patch, }), onSuccess: () => qc.invalidateQueries({ queryKey: ['residential-interest', interestId] }), }); const save = (field: string) => async (next: string | null) => { await update.mutateAsync({ [field]: next }); }; if (isLoading || !data) { return
Loading…
; } const interest = data.data; return (
All residential interests

Residential interest

{interest.client && (

{interest.client.fullName}

)}

Pipeline

Details

); } function Row({ label, children }: { label: string; children: React.ReactNode }) { return (
{label}
{children}
); }