'use client'; import { format } from 'date-fns'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import type { DetailTab } from '@/components/shared/detail-layout'; import { NotesList } from '@/components/shared/notes-list'; import { InlineEditableField } from '@/components/shared/inline-editable-field'; import { InlineTagEditor } from '@/components/shared/inline-tag-editor'; import { RecommendationList } from '@/components/interests/recommendation-list'; import { InterestTimeline } from '@/components/interests/interest-timeline'; import { LEAD_CATEGORIES } from '@/lib/constants'; import { apiFetch } from '@/lib/api/client'; type InterestPatchField = 'leadCategory' | 'source' | 'notes'; const LEAD_CATEGORY_OPTIONS = LEAD_CATEGORIES.map((c) => ({ value: c, label: c.replace(/_/g, ' ').replace(/\b\w/g, (m) => m.toUpperCase()), })); interface InterestTabsOptions { interestId: string; currentUserId?: string; interest: { leadCategory: string | null; source: string | null; eoiStatus: string | null; contractStatus: string | null; depositStatus: string | null; reservationStatus: string | null; dateFirstContact: string | null; dateLastContact: string | null; dateEoiSent: string | null; dateEoiSigned: string | null; dateContractSent: string | null; dateContractSigned: string | null; dateDepositReceived: string | null; reminderEnabled: boolean; reminderDays: number | null; reminderLastFired: string | null; notes: string | null; tags?: Array<{ id: string; name: string; color: string }>; }; } function useInterestPatch(interestId: string) { const qc = useQueryClient(); return useMutation({ mutationFn: async (patch: Partial>) => apiFetch(`/api/v1/interests/${interestId}`, { method: 'PATCH', body: patch, }), onSuccess: () => { qc.invalidateQueries({ queryKey: ['interests', interestId] }); }, }); } function EditableRow({ label, children }: { label: string; children: React.ReactNode }) { return (
{label}
{children}
); } function InfoRow({ label, value }: { label: string; value?: string | null }) { if (!value) return null; return (
{label}
{value}
); } function formatDate(date: string | null) { if (!date) return null; return format(new Date(date), 'MMM d, yyyy'); } function OverviewTab({ interestId, interest, }: { interestId: string; interest: InterestTabsOptions['interest']; }) { const mutation = useInterestPatch(interestId); const save = (field: InterestPatchField) => async (next: string | null) => { await mutation.mutateAsync({ [field]: next }); }; return (
{/* Lead & Source (editable) */}

Lead

{/* EOI & Contract Status (read-only — derived) */}

Status

{/* Key Dates (read-only — set by workflow events) */}

Key Dates

{/* Reminder */} {interest.reminderEnabled && (

Reminder

)} {/* Notes (editable, multiline) */}

Notes

{/* Tags */}

Tags

); } export function getInterestTabs({ interestId, currentUserId, interest, }: InterestTabsOptions): DetailTab[] { return [ { id: 'overview', label: 'Overview', content: , }, { id: 'notes', label: 'Notes', content: ( ), }, { id: 'documents', label: 'Documents', content: (

Documents tab available after document system is built

), }, { id: 'files', label: 'Files', content: (

Files tab available after file system is built

), }, { id: 'recommendations', label: 'Recommendations', content: , }, { id: 'activity', label: 'Activity', content: , }, ]; }