'use client'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import type { DetailTab } from '@/components/shared/detail-layout'; import { InlineEditableField } from '@/components/shared/inline-editable-field'; import { NotesList } from '@/components/shared/notes-list'; import { EntityActivityFeed } from '@/components/shared/entity-activity-feed'; import { apiFetch } from '@/lib/api/client'; import { useFeatureFlag } from '@/hooks/use-feature-flag'; import { SOURCES } from '@/lib/constants'; interface ResidentialInterest { id: string; residentialClientId: string; pipelineStage: string; source: string | null; notes: string | null; preferences: string | null; assignedTo: string | null; } interface Args { interestId: string; interest: ResidentialInterest; currentUserId?: string; stageOptions: Array<{ value: string; label: string }>; } const SOURCE_OPTIONS = SOURCES.map((s) => ({ value: s.value, label: s.label })); function Row({ label, children }: { label: string; children: React.ReactNode }) { return (
{label}
{children}
); } export function getResidentialInterestTabs({ interestId, interest, currentUserId, stageOptions, }: Args): DetailTab[] { return [ { id: 'overview', label: 'Overview', content: ( ), }, { id: 'notes', label: 'Notes', content: ( ), }, { id: 'activity', label: 'Activity', content: ( ), }, ]; } function useInterestPatch(interestId: string) { const qc = useQueryClient(); return useMutation({ mutationFn: (patch: Record) => apiFetch(`/api/v1/residential/interests/${interestId}`, { method: 'PATCH', body: patch }), onSuccess: () => qc.invalidateQueries({ queryKey: ['residential-interest', interestId] }), }); } function OverviewTab({ interestId, interest, stageOptions, }: { interestId: string; interest: ResidentialInterest; stageOptions: Array<{ value: string; label: string }>; }) { const update = useInterestPatch(interestId); // CM-5: residential assignment row hidden when the per-port toggle is off. const assignmentEnabled = useFeatureFlag('assignment_enabled', false); const save = (field: string) => async (next: string | null) => { await update.mutateAsync({ [field]: next }); }; // Pull users with residential access for the Assigned-to dropdown. const { data: assignableUsers } = useQuery<{ data: Array<{ id: string; name: string; email: string }>; }>({ queryKey: ['residential-assignable-users'], queryFn: () => apiFetch('/api/v1/residential/assignable-users'), enabled: assignmentEnabled, }); const assigneeOptions = (assignableUsers?.data ?? []).map((u) => ({ value: u.id, label: u.name || u.email, })); return (

Pipeline

{assignmentEnabled ? ( ) : null}

Details

); }