ifixkart-admin/New admin panel/ikixkart-dashboard/app/(admin)/crm-leads/contacted/page.tsx
Adithiyan bbd3a3e959 feat: initial commit — full platform snapshot
- Backend: FastAPI app with all models, services, schemas, routes
- Admin Panel: Next.js dashboard with all modules
  (CRM, POS, repairs, warranties, billing, notifications, etc.)
- Ecommerce: storefront (submodule) + product catalog
- AI Agents: .agents/ skill library for Antigravity IDE
- Docs: architecture, billing, notification gateway markdown
- Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
2026-10-13 12:59:47 +05:30

224 lines
10 KiB
TypeScript

'use client';
import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import { crmService, CrmLead } from '@/services/api/crmService';
import { Phone, Mail, ArrowRight, MessageSquare, Clock, Sparkles, LayoutGrid, List } from 'lucide-react';
import { toast } from 'sonner';
export default function ContactedLeadsPage() {
const router = useRouter();
const [leads, setLeads] = useState<CrmLead[]>([]);
const [loading, setLoading] = useState(true);
const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid');
useEffect(() => {
loadLeads();
}, []);
const loadLeads = async () => {
try {
setLoading(true);
const data = await crmService.getLeads('CONTACTED');
setLeads(data || []);
} catch (err) {
setLeads([]);
} finally {
setLoading(false);
}
};
const handleAdvanceToQualified = async (lead: CrmLead) => {
try {
await crmService.updateLeadStatus(lead.lead_id, 'QUALIFIED');
toast.success(`Moved lead "${lead.title || lead.phone}" to Qualified stage!`);
router.push('/crm-leads/qualified');
} catch (err) {
toast.error('Failed to update lead status');
}
};
return (
<div className="p-6 space-y-6 max-w-7xl mx-auto">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 border-b border-border pb-4">
<div>
<div className="flex items-center gap-2">
<span className="px-2.5 py-1 rounded-full text-xs font-bold bg-amber-500/10 text-amber-600 border border-amber-500/20">
Stage 2 of 5
</span>
<h1 className="text-2xl font-bold text-foreground">2. Contacted Leads</h1>
</div>
<p className="text-xs text-muted-foreground mt-1">
Leads where staff have initiated outreach via Call or WhatsApp Web
</p>
</div>
<div className="flex items-center gap-1 bg-muted p-1 rounded-lg border border-border">
<button
onClick={() => setViewMode('grid')}
className={`p-1.5 rounded-md text-xs font-semibold flex items-center gap-1 transition-colors ${
viewMode === 'grid'
? 'bg-background text-foreground shadow-xs'
: 'text-muted-foreground hover:text-foreground'
}`}
title="Grid View"
>
<LayoutGrid className="w-4 h-4" />
<span className="hidden sm:inline">Grid</span>
</button>
<button
onClick={() => setViewMode('list')}
className={`p-1.5 rounded-md text-xs font-semibold flex items-center gap-1 transition-colors ${
viewMode === 'list'
? 'bg-background text-foreground shadow-xs'
: 'text-muted-foreground hover:text-foreground'
}`}
title="List View"
>
<List className="w-4 h-4" />
<span className="hidden sm:inline">List</span>
</button>
</div>
</div>
{loading ? (
<div className="py-20 text-center text-muted-foreground animate-pulse text-sm">
Loading Contacted Leads...
</div>
) : leads.length === 0 ? (
<div className="py-16 text-center bg-card border border-border rounded-xl">
<Sparkles className="w-10 h-10 text-amber-500 mx-auto mb-2 opacity-50" />
<h3 className="text-sm font-semibold text-foreground">No contacted leads currently in this stage</h3>
<p className="text-xs text-muted-foreground mt-1">
Move new inquiries here after reaching out on WhatsApp or phone call.
</p>
</div>
) : viewMode === 'grid' ? (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{leads.map((lead) => {
const cleanPhone = lead.phone ? lead.phone.replace(/[^0-9]/g, '') : '';
return (
<div key={lead.lead_id} className="bg-card border border-border hover:border-amber-500/50 rounded-xl p-4 shadow-xs space-y-3 flex flex-col justify-between transition-all">
<div className="space-y-2">
<div className="flex items-start justify-between gap-2">
<h3 className="font-semibold text-sm text-foreground">
{lead.title || lead.first_name || 'Contacted Inquiry'}
</h3>
<span className="px-2 py-0.5 rounded-md text-[10px] font-bold bg-amber-500/10 text-amber-600">
CONTACTED
</span>
</div>
<div className="space-y-1 text-xs">
{lead.phone && (
<div className="flex items-center justify-between text-foreground font-medium">
<span className="flex items-center gap-1.5">
<Phone className="w-3.5 h-3.5 text-muted-foreground" />
{lead.phone}
</span>
{cleanPhone && (
<button
onClick={() => router.push(`/whatsapp-web?phone=${cleanPhone}&name=${encodeURIComponent(lead.title || lead.first_name || 'Lead Customer')}`)}
className="inline-flex items-center gap-1 text-[10px] font-bold bg-emerald-500/10 text-emerald-600 border border-emerald-500/20 px-2 py-1 rounded-md hover:bg-emerald-600 hover:text-white transition-colors cursor-pointer"
>
<MessageSquare className="w-3.5 h-3.5" />
OpenWA Web Chat
</button>
)}
</div>
)}
{lead.email && (
<div className="flex items-center gap-1.5 text-muted-foreground truncate">
<Mail className="w-3.5 h-3.5 shrink-0" />
<span className="truncate">{lead.email}</span>
</div>
)}
</div>
<div className="flex items-center justify-between text-[10px] text-muted-foreground pt-1">
<span className="bg-muted px-2 py-0.5 rounded-md font-semibold">
Source: {lead.source}
</span>
<span className="flex items-center gap-1">
<Clock className="w-3 h-3" />
{new Date(lead.created_at).toLocaleDateString()}
</span>
</div>
</div>
<div className="pt-3 border-t border-border flex items-center justify-between">
<span className="text-[11px] text-muted-foreground">Verify details & budget</span>
<button
onClick={() => handleAdvanceToQualified(lead)}
className="inline-flex items-center gap-1 text-xs font-semibold bg-amber-600 text-white hover:bg-amber-700 px-3 py-1.5 rounded-lg shadow-xs transition-colors"
>
<span>Move to Qualified</span>
<ArrowRight className="w-3.5 h-3.5" />
</button>
</div>
</div>
);
})}
</div>
) : (
<div className="overflow-x-auto border border-border rounded-xl bg-card shadow-xs">
<table className="w-full text-left border-collapse text-xs">
<thead>
<tr className="border-b border-border bg-muted/50 text-muted-foreground font-semibold">
<th className="p-3.5">Inquiry Title / Customer</th>
<th className="p-3.5">Phone / OpenWA Chat</th>
<th className="p-3.5">Email Address</th>
<th className="p-3.5">Source</th>
<th className="p-3.5">Contacted Date</th>
<th className="p-3.5 text-right">Action</th>
</tr>
</thead>
<tbody className="divide-y divide-border">
{leads.map((lead) => {
const cleanPhone = lead.phone ? lead.phone.replace(/[^0-9]/g, '') : '';
return (
<tr key={lead.lead_id} className="hover:bg-muted/30 transition-colors">
<td className="p-3.5 font-semibold text-foreground">
{lead.title || lead.first_name || 'Contacted Inquiry'}
</td>
<td className="p-3.5">
<div className="flex items-center gap-2">
<span className="font-medium text-foreground">{lead.phone || '—'}</span>
{cleanPhone && (
<button
onClick={() => router.push(`/whatsapp-web?phone=${cleanPhone}&name=${encodeURIComponent(lead.title || lead.first_name || 'Lead Customer')}`)}
className="inline-flex items-center gap-1 text-[10px] font-bold bg-emerald-500/10 text-emerald-600 border border-emerald-500/20 px-2 py-0.5 rounded-md hover:bg-emerald-600 hover:text-white transition-colors cursor-pointer"
>
<MessageSquare className="w-3 h-3" />
OpenWA Web Chat
</button>
)}
</div>
</td>
<td className="p-3.5 text-muted-foreground">{lead.email || '—'}</td>
<td className="p-3.5">
<span className="bg-muted px-2 py-0.5 rounded-md font-semibold text-[10px] text-muted-foreground">
{lead.source}
</span>
</td>
<td className="p-3.5 text-muted-foreground">
{new Date(lead.created_at).toLocaleDateString()}
</td>
<td className="p-3.5 text-right">
<button
onClick={() => handleAdvanceToQualified(lead)}
className="inline-flex items-center gap-1 text-xs font-semibold bg-amber-600 text-white hover:bg-amber-700 px-3 py-1.5 rounded-lg shadow-xs transition-colors"
>
<span>Move to Qualified</span>
<ArrowRight className="w-3.5 h-3.5" />
</button>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
)}
</div>
);
}