"use client"; import { useEffect, useState } from 'react'; import { useParams } from 'next/navigation'; import { ChartBarIcon, UsersIcon, FunnelIcon, ArrowTrendingUpIcon, ArrowTrendingDownIcon, EnvelopeIcon, PhoneIcon, TagIcon, UserPlusIcon, } from '@heroicons/react/24/outline'; interface Lead { id: string; name: string; email: string; phone: string; source: string; status: string; tags: string[]; created_at: string; } interface SharedData { customer: { name: string; company: string; }; leads: Lead[]; stats: { total: number; novo: number; qualificado: number; negociacao: number; convertido: number; perdido: number; bySource: Record; conversionRate: number; thisMonth: number; lastMonth: number; }; } const STATUS_OPTIONS = [ { value: 'novo', label: 'Novo', color: 'bg-blue-100 text-blue-800' }, { value: 'qualificado', label: 'Qualificado', color: 'bg-green-100 text-green-800' }, { value: 'negociacao', label: 'Em Negociação', color: 'bg-yellow-100 text-yellow-800' }, { value: 'convertido', label: 'Convertido', color: 'bg-purple-100 text-purple-800' }, { value: 'perdido', label: 'Perdido', color: 'bg-red-100 text-red-800' }, ]; export default function SharedLeadsPage() { const params = useParams(); const token = params?.token as string; const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { if (token) { fetchSharedData(); } }, [token]); const fetchSharedData = async () => { try { const response = await fetch(`/api/crm/share/${token}`); if (!response.ok) { throw new Error('Link inválido ou expirado'); } const result = await response.json(); setData(result); } catch (err) { setError(err instanceof Error ? err.message : 'Erro ao carregar dados'); } finally { setLoading(false); } }; const getStatusColor = (status: string) => { return STATUS_OPTIONS.find(s => s.value === status)?.color || 'bg-gray-100 text-gray-800'; }; if (loading) { return (

Carregando dados...

); } if (error || !data) { return (

Link Inválido

{error || 'Não foi possível acessar os dados compartilhados.'}

); } return (
{/* Header */}

Dashboard de Leads

{data.customer.company || data.customer.name}

Atualizado em

{new Date().toLocaleDateString('pt-BR')}

{/* Cards de Métricas */}

Total de Leads

{data.stats.total}

{data.stats.thisMonth >= data.stats.lastMonth ? ( ) : ( )} = data.stats.lastMonth ? 'text-green-600' : 'text-red-600'}> {data.stats.thisMonth} este mês

Taxa de Conversão

{data.stats.conversionRate.toFixed(1)}%

{data.stats.convertido} convertidos

Novos Leads

{data.stats.novo}

Aguardando qualificação

Em Negociação

{data.stats.negociacao}

Potencial de conversão

{/* Distribuição por Status */}

Distribuição por Status

{STATUS_OPTIONS.map(status => { const count = data.stats[status.value as keyof typeof data.stats] as number || 0; const percentage = data.stats.total > 0 ? (count / data.stats.total) * 100 : 0; return (
{status.label} {count} ({percentage.toFixed(1)}%)
); })}
{/* Leads por Origem */}

Leads por Origem

{Object.entries(data.stats.bySource).map(([source, count]) => (

{source}

{count}

))}
{/* Lista de Leads */}

Todos os Leads ({data.leads.length})

{data.leads.map((lead) => (

{lead.name || 'Sem nome'}

{STATUS_OPTIONS.find(s => s.value === lead.status)?.label || lead.status}
{lead.email && (
{lead.email}
)} {lead.phone && (
{lead.phone}
)} {lead.tags && lead.tags.length > 0 && (
{lead.tags.map((tag, idx) => ( {tag} ))}
)}
Origem: {lead.source || 'manual'}
))}
{/* Footer */}

Dados atualizados em tempo real

Powered by Aggios CRM

); }