Files
pn-new-crm/src/components/residential/residential-interest-tabs.tsx
Matt 4dc0bdd8c4
All checks were successful
Build & Push Docker Images / lint (push) Successful in 2m51s
Build & Push Docker Images / build-and-push (push) Successful in 9m16s
feat(crm): client-meeting batch — contact-pill cleanup, assignment toggle, receipt manual mode
CM-4: remove Email/Call/WhatsApp deep-link pills from the client + interest
  detail headers; relocate GDPR export into the client-header action cluster
  as a compact icon. Keeps the interest "Log contact" quick action.
CM-5: gate the interest assignment feature behind a per-port `assignment_enabled`
  setting (default OFF for single-rep ports). Hides the AssignedToChip +
  residential assigned-to row and skips tier-2/3 auto-assign on create; the
  column + data are preserved and reversible. Tests cover the auto-assign guard.
CM-6: add a per-port `manualEntry` receipt mode (skip all parsing → empty form).
  Threaded through ocr-config.service, the admin OCR form, the scan-receipt
  route, and the scanner shell (skips Tesseract + the server call). Tests cover
  the save/resolve round-trip.

Verified: tsc clean, lint 0 errors, 1631 vitest pass, prod build green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 21:42:36 +02:00

166 lines
4.9 KiB
TypeScript

'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 (
<div className="flex gap-2 py-1.5 border-b last:border-0 items-center">
<dt className="w-44 shrink-0 text-sm text-muted-foreground">{label}</dt>
<dd className="flex-1 min-w-0">{children}</dd>
</div>
);
}
export function getResidentialInterestTabs({
interestId,
interest,
currentUserId,
stageOptions,
}: Args): DetailTab[] {
return [
{
id: 'overview',
label: 'Overview',
content: (
<OverviewTab interestId={interestId} interest={interest} stageOptions={stageOptions} />
),
},
{
id: 'notes',
label: 'Notes',
content: (
<NotesList
entityType="residential_interests"
entityId={interestId}
currentUserId={currentUserId}
parentInvalidateKey={['residential-interest', interestId]}
/>
),
},
{
id: 'activity',
label: 'Activity',
content: (
<EntityActivityFeed
endpoint={`/api/v1/residential/interests/${interestId}/activity`}
emptyText="No activity recorded for this residential interest yet."
/>
),
},
];
}
function useInterestPatch(interestId: string) {
const qc = useQueryClient();
return useMutation({
mutationFn: (patch: Record<string, unknown>) =>
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 (
<div className="rounded-lg border bg-card p-6 space-y-6">
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div className="space-y-1">
<h3 className="text-sm font-medium mb-2">Pipeline</h3>
<Row label="Stage">
<InlineEditableField
variant="select"
options={stageOptions}
value={interest.pipelineStage}
onSave={save('pipelineStage')}
/>
</Row>
<Row label="Source">
<InlineEditableField
variant="select"
options={SOURCE_OPTIONS}
value={interest.source}
onSave={save('source')}
/>
</Row>
{assignmentEnabled ? (
<Row label="Assigned to">
<InlineEditableField
variant="select"
options={assigneeOptions}
value={interest.assignedTo}
onSave={save('assignedTo')}
placeholder="Unassigned"
/>
</Row>
) : null}
</div>
<div className="space-y-1">
<h3 className="text-sm font-medium mb-2">Details</h3>
<Row label="Preferences">
<InlineEditableField
variant="textarea"
value={interest.preferences}
onSave={save('preferences')}
/>
</Row>
</div>
</div>
</div>
);
}