feat: add CSV import, activity timeline, and AI insights widget
- CSV Import: modal with file picker, auto column mapping, preview table, import progress - Activity Timeline: new tab on client detail showing all communications, events, status changes - AI Insights Widget: dashboard card showing stale clients, upcoming birthdays, suggested follow-ups - Import button on Clients page header
This commit is contained in:
@@ -2,11 +2,11 @@ import { useEffect, useState } from 'react';
|
||||
import { useParams, useNavigate, Link } from 'react-router-dom';
|
||||
import { useClientsStore } from '@/stores/clients';
|
||||
import { api } from '@/lib/api';
|
||||
import type { Event, Email } from '@/types';
|
||||
import type { Event, Email, ActivityItem } from '@/types';
|
||||
import {
|
||||
ArrowLeft, Edit3, Trash2, Phone, Mail, MapPin, Building2,
|
||||
Briefcase, Gift, Heart, Star, Users, Calendar, Send,
|
||||
CheckCircle2, Sparkles, Clock,
|
||||
CheckCircle2, Sparkles, Clock, Activity, FileText, UserPlus, RefreshCw,
|
||||
} from 'lucide-react';
|
||||
import { cn, formatDate, getRelativeTime, getInitials } from '@/lib/utils';
|
||||
import Badge, { EventTypeBadge, EmailStatusBadge } from '@/components/Badge';
|
||||
@@ -21,7 +21,8 @@ export default function ClientDetailPage() {
|
||||
const { selectedClient, isLoading, fetchClient, updateClient, deleteClient, markContacted } = useClientsStore();
|
||||
const [events, setEvents] = useState<Event[]>([]);
|
||||
const [emails, setEmails] = useState<Email[]>([]);
|
||||
const [activeTab, setActiveTab] = useState<'info' | 'events' | 'emails'>('info');
|
||||
const [activities, setActivities] = useState<ActivityItem[]>([]);
|
||||
const [activeTab, setActiveTab] = useState<'info' | 'activity' | 'events' | 'emails'>('info');
|
||||
const [showEdit, setShowEdit] = useState(false);
|
||||
const [showCompose, setShowCompose] = useState(false);
|
||||
const [deleting, setDeleting] = useState(false);
|
||||
@@ -31,6 +32,7 @@ export default function ClientDetailPage() {
|
||||
fetchClient(id);
|
||||
api.getEvents({ clientId: id }).then(setEvents).catch(() => {});
|
||||
api.getEmails({ clientId: id }).then(setEmails).catch(() => {});
|
||||
api.getClientActivity(id).then(setActivities).catch(() => {});
|
||||
}
|
||||
}, [id, fetchClient]);
|
||||
|
||||
@@ -58,8 +60,9 @@ export default function ClientDetailPage() {
|
||||
setShowEdit(false);
|
||||
};
|
||||
|
||||
const tabs: { key: 'info' | 'events' | 'emails'; label: string; count?: number; icon: typeof Users }[] = [
|
||||
const tabs: { key: 'info' | 'activity' | 'events' | 'emails'; label: string; count?: number; icon: typeof Users }[] = [
|
||||
{ key: 'info', label: 'Info', icon: Users },
|
||||
{ key: 'activity', label: 'Timeline', count: activities.length, icon: Activity },
|
||||
{ key: 'events', label: 'Events', count: events.length, icon: Calendar },
|
||||
{ key: 'emails', label: 'Emails', count: emails.length, icon: Mail },
|
||||
];
|
||||
@@ -228,6 +231,49 @@ export default function ClientDetailPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'activity' && (
|
||||
<div className="bg-white border border-slate-200 rounded-xl">
|
||||
{activities.length === 0 ? (
|
||||
<p className="px-5 py-8 text-center text-sm text-slate-400">No activity recorded yet</p>
|
||||
) : (
|
||||
<div className="relative">
|
||||
{activities.map((item, index) => {
|
||||
const iconMap: Record<string, { icon: typeof Mail; color: string; bg: string }> = {
|
||||
email_sent: { icon: Send, color: 'text-emerald-600', bg: 'bg-emerald-100' },
|
||||
email_drafted: { icon: FileText, color: 'text-amber-600', bg: 'bg-amber-100' },
|
||||
event_created: { icon: Calendar, color: 'text-blue-600', bg: 'bg-blue-100' },
|
||||
client_contacted: { icon: CheckCircle2, color: 'text-emerald-600', bg: 'bg-emerald-100' },
|
||||
client_created: { icon: UserPlus, color: 'text-purple-600', bg: 'bg-purple-100' },
|
||||
client_updated: { icon: RefreshCw, color: 'text-slate-600', bg: 'bg-slate-100' },
|
||||
};
|
||||
const { icon: Icon, color, bg } = iconMap[item.type] || iconMap.client_updated;
|
||||
|
||||
return (
|
||||
<div key={item.id} className="flex gap-4 px-5 py-4 relative">
|
||||
{/* Timeline line */}
|
||||
{index < activities.length - 1 && (
|
||||
<div className="absolute left-[2.15rem] top-14 bottom-0 w-px bg-slate-200" />
|
||||
)}
|
||||
{/* Icon */}
|
||||
<div className={`w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 ${bg} relative z-10`}>
|
||||
<Icon className={`w-4 h-4 ${color}`} />
|
||||
</div>
|
||||
{/* Content */}
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium text-slate-900">{item.title}</p>
|
||||
{item.description && (
|
||||
<p className="text-xs text-slate-500 mt-0.5 line-clamp-2">{item.description}</p>
|
||||
)}
|
||||
<p className="text-xs text-slate-400 mt-1">{formatDate(item.date)}</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'events' && (
|
||||
<div className="bg-white border border-slate-200 rounded-xl divide-y divide-slate-100">
|
||||
{events.length === 0 ? (
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
import { useEffect, useState, useMemo } from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { useClientsStore } from '@/stores/clients';
|
||||
import { Search, Plus, Users, X } from 'lucide-react';
|
||||
import { Search, Plus, Users, X, Upload } from 'lucide-react';
|
||||
import { cn, getRelativeTime, getInitials } from '@/lib/utils';
|
||||
import Badge from '@/components/Badge';
|
||||
import EmptyState from '@/components/EmptyState';
|
||||
import { PageLoader } from '@/components/LoadingSpinner';
|
||||
import Modal from '@/components/Modal';
|
||||
import ClientForm from '@/components/ClientForm';
|
||||
import CSVImportModal from '@/components/CSVImportModal';
|
||||
|
||||
export default function ClientsPage() {
|
||||
const location = useLocation();
|
||||
const { clients, isLoading, searchQuery, selectedTag, setSearchQuery, setSelectedTag, fetchClients, createClient } = useClientsStore();
|
||||
const [showCreate, setShowCreate] = useState(false);
|
||||
const [showImport, setShowImport] = useState(false);
|
||||
const [creating, setCreating] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -72,13 +74,22 @@ export default function ClientsPage() {
|
||||
<h1 className="text-2xl font-bold text-slate-900">Clients</h1>
|
||||
<p className="text-slate-500 text-sm mt-1">{clients.length} contacts in your network</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setShowCreate(true)}
|
||||
className="flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg text-sm font-medium hover:bg-blue-700 transition-colors"
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
Add Client
|
||||
</button>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
onClick={() => setShowImport(true)}
|
||||
className="flex items-center gap-2 px-4 py-2 bg-white border border-slate-200 text-slate-700 rounded-lg text-sm font-medium hover:bg-slate-50 transition-colors"
|
||||
>
|
||||
<Upload className="w-4 h-4" />
|
||||
Import CSV
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setShowCreate(true)}
|
||||
className="flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg text-sm font-medium hover:bg-blue-700 transition-colors"
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
Add Client
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Search + Tags */}
|
||||
@@ -175,6 +186,13 @@ export default function ClientsPage() {
|
||||
<Modal isOpen={showCreate} onClose={() => setShowCreate(false)} title="Add Client" size="lg">
|
||||
<ClientForm onSubmit={handleCreate} loading={creating} />
|
||||
</Modal>
|
||||
|
||||
{/* Import CSV Modal */}
|
||||
<CSVImportModal
|
||||
isOpen={showImport}
|
||||
onClose={() => setShowImport(false)}
|
||||
onComplete={() => fetchClients()}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { api } from '@/lib/api';
|
||||
import type { Client, Event, Email } from '@/types';
|
||||
import { Users, Calendar, Mail, Plus, ArrowRight, Gift, Heart, Clock } from 'lucide-react';
|
||||
import type { Client, Event, Email, InsightsData } from '@/types';
|
||||
import { Users, Calendar, Mail, Plus, ArrowRight, Gift, Heart, Clock, AlertTriangle, Sparkles, UserCheck, PhoneForwarded } from 'lucide-react';
|
||||
import { formatDate, getDaysUntil } from '@/lib/utils';
|
||||
import { EventTypeBadge } from '@/components/Badge';
|
||||
import { PageLoader } from '@/components/LoadingSpinner';
|
||||
@@ -11,6 +11,7 @@ export default function DashboardPage() {
|
||||
const [clients, setClients] = useState<Client[]>([]);
|
||||
const [events, setEvents] = useState<Event[]>([]);
|
||||
const [emails, setEmails] = useState<Email[]>([]);
|
||||
const [insights, setInsights] = useState<InsightsData | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -18,10 +19,12 @@ export default function DashboardPage() {
|
||||
api.getClients().catch(() => []),
|
||||
api.getEvents({ upcoming: 7 }).catch(() => []),
|
||||
api.getEmails({ status: 'draft' }).catch(() => []),
|
||||
]).then(([c, e, em]) => {
|
||||
api.getInsights().catch(() => null),
|
||||
]).then(([c, e, em, ins]) => {
|
||||
setClients(c);
|
||||
setEvents(e);
|
||||
setEmails(em);
|
||||
setInsights(ins as InsightsData | null);
|
||||
setLoading(false);
|
||||
});
|
||||
}, []);
|
||||
@@ -78,6 +81,111 @@ export default function DashboardPage() {
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* AI Insights */}
|
||||
{insights && (insights.staleClients.length > 0 || insights.upcomingBirthdays.length > 0 || insights.suggestedFollowups.length > 0) && (
|
||||
<div className="bg-gradient-to-br from-indigo-50 to-purple-50 border border-indigo-200 rounded-xl p-5 space-y-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<Sparkles className="w-5 h-5 text-indigo-600" />
|
||||
<h2 className="font-semibold text-indigo-900">AI Insights</h2>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
{/* Needs Attention */}
|
||||
{insights.staleClients.length > 0 && (
|
||||
<div className="bg-white/80 rounded-lg p-4 space-y-3">
|
||||
<div className="flex items-center gap-2 text-sm font-medium text-red-700">
|
||||
<AlertTriangle className="w-4 h-4" />
|
||||
Needs Attention
|
||||
</div>
|
||||
<p className="text-xs text-slate-500">
|
||||
{insights.summary.staleCount} client{insights.summary.staleCount !== 1 ? 's' : ''} not contacted in 30+ days
|
||||
{insights.summary.neverContacted > 0 && `, ${insights.summary.neverContacted} never contacted`}
|
||||
</p>
|
||||
<div className="space-y-2">
|
||||
{insights.staleClients.slice(0, 3).map(c => (
|
||||
<Link key={c.id} to={`/clients/${c.id}`} className="flex items-center gap-2 group">
|
||||
<div className="w-6 h-6 bg-red-100 text-red-700 rounded-full flex items-center justify-center text-xs font-bold flex-shrink-0">
|
||||
{c.firstName[0]}{c.lastName[0]}
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<p className="text-xs font-medium text-slate-700 truncate group-hover:text-blue-600">
|
||||
{c.firstName} {c.lastName}
|
||||
</p>
|
||||
<p className="text-xs text-slate-400">
|
||||
{c.daysSinceContact ? `${c.daysSinceContact}d ago` : 'Never contacted'}
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
{insights.staleClients.length > 3 && (
|
||||
<Link to="/clients" className="text-xs text-indigo-600 hover:text-indigo-700">
|
||||
+{insights.staleClients.length - 3} more
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Upcoming Birthdays */}
|
||||
{insights.upcomingBirthdays.length > 0 && (
|
||||
<div className="bg-white/80 rounded-lg p-4 space-y-3">
|
||||
<div className="flex items-center gap-2 text-sm font-medium text-pink-700">
|
||||
<Gift className="w-4 h-4" />
|
||||
Birthdays This Week
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
{insights.upcomingBirthdays.map(c => (
|
||||
<Link key={c.id} to={`/clients/${c.id}`} className="flex items-center gap-2 group">
|
||||
<div className="w-6 h-6 bg-pink-100 text-pink-700 rounded-full flex items-center justify-center text-xs font-bold flex-shrink-0">
|
||||
🎂
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<p className="text-xs font-medium text-slate-700 truncate group-hover:text-blue-600">
|
||||
{c.firstName} {c.lastName}
|
||||
</p>
|
||||
<p className="text-xs text-slate-400">
|
||||
{c.daysUntil === 0 ? 'Today!' : c.daysUntil === 1 ? 'Tomorrow' : `In ${c.daysUntil} days`}
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Suggested Follow-ups */}
|
||||
{insights.suggestedFollowups.length > 0 && (
|
||||
<div className="bg-white/80 rounded-lg p-4 space-y-3">
|
||||
<div className="flex items-center gap-2 text-sm font-medium text-amber-700">
|
||||
<PhoneForwarded className="w-4 h-4" />
|
||||
Suggested Follow-ups
|
||||
</div>
|
||||
<p className="text-xs text-slate-500">
|
||||
Contacted 14-30 days ago — good time to reach out
|
||||
</p>
|
||||
<div className="space-y-2">
|
||||
{insights.suggestedFollowups.slice(0, 3).map(c => (
|
||||
<Link key={c.id} to={`/clients/${c.id}`} className="flex items-center gap-2 group">
|
||||
<div className="w-6 h-6 bg-amber-100 text-amber-700 rounded-full flex items-center justify-center text-xs font-bold flex-shrink-0">
|
||||
{c.firstName[0]}{c.lastName[0]}
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<p className="text-xs font-medium text-slate-700 truncate group-hover:text-blue-600">
|
||||
{c.firstName} {c.lastName}
|
||||
</p>
|
||||
<p className="text-xs text-slate-400">
|
||||
{c.daysSinceContact}d since last contact
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
{/* Upcoming Events */}
|
||||
<div className="bg-white border border-slate-200 rounded-xl">
|
||||
|
||||
Reference in New Issue
Block a user