'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';
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 = [
{ value: 'website', label: 'Website' },
{ value: 'manual', label: 'Manual' },
{ value: 'referral', label: 'Referral' },
{ value: 'broker', label: 'Broker' },
{ value: 'other', label: 'Other' },
];
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);
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'),
});
const assigneeOptions = (assignableUsers?.data ?? []).map((u) => ({
value: u.id,
label: u.name || u.email,
}));
return (
);
}