import { useEffect, useState } from 'react' import { apiFetch } from '@core/lib/api' interface ActivityItem { id: string title: string data: Record created_at: string type_slug?: string } const TYPE_LABELS: Record = { site_visit: { label: 'Site Visit', color: 'bg-purple-100 text-purple-700' }, marketing_touch: { label: 'Marketing Touch', color: 'bg-yellow-100 text-yellow-700' }, deal: { label: 'Deal', color: 'bg-blue-100 text-blue-700' }, csm_health: { label: 'Health Check', color: 'bg-green-100 text-green-700' }, } export default function ActivityPage() { const [items, setItems] = useState([]) const [loading, setLoading] = useState(true) useEffect(() => { Promise.all([ apiFetch('/api/admin-data?action=list&entity=items&type_slug=site_visit&limit=50').then(r => r.json()), apiFetch('/api/admin-data?action=list&entity=items&type_slug=marketing_touch&limit=50').then(r => r.json()), ]) .then(([vr, tr]) => { const visits = vr?.data ?? vr const touches = tr?.data ?? tr const all = [ ...(visits || []).map((i: ActivityItem) => ({ ...i, type_slug: 'site_visit' })), ...(touches || []).map((i: ActivityItem) => ({ ...i, type_slug: 'marketing_touch' })), ].sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()) setItems(all) }) .catch(() => setItems([])) .finally(() => setLoading(false)) }, []) return (

Activity Feed

Site visits and marketing touches

{loading ? (
Loading activity…
) : items.length === 0 ? (
No activity recorded yet.
) : (
{items.map(item => { const typeInfo = TYPE_LABELS[item.type_slug || ''] || { label: item.type_slug || 'Event', color: 'bg-muted text-muted-foreground' } return (
{typeInfo.label}
{item.title}
{item.type_slug === 'site_visit' && item.data?.url && (
{String(item.data.url)}
)} {item.type_slug === 'marketing_touch' && item.data?.channel && (
via {String(item.data.channel)}{item.data?.campaign ? ` · ${item.data.campaign}` : ''}
)}
{new Date(item.created_at).toLocaleDateString()}
) })}
)}
) }