'use client'; import { Mail, MessageCircle, Phone } from 'lucide-react'; import * as React from 'react'; import { LeadStatusBadge } from '@/components/leads/lead-status-badge'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Select } from '@/components/ui/select'; import { useDeleteLead, useUpdateLeadStatus } from '@/lib/hooks/use-leads'; import { LEAD_STATUSES, LEAD_SOURCES, type LeadReadDto, type LeadStatus } from '@/lib/leads-api'; interface LeadDetailDialogProps { lead: LeadReadDto | null; open: boolean; onOpenChange: (open: boolean) => void; } const STATUS_OPTIONS = Object.entries(LEAD_STATUSES) as [LeadStatus, { label: string }][]; function getSourceLabel(source: string): string { const found = LEAD_SOURCES.find((s) => s.value === source); return found?.label ?? source; } export function LeadDetailDialog({ lead, open, onOpenChange }: LeadDetailDialogProps) { const updateStatus = useUpdateLeadStatus(); const deleteLead = useDeleteLead(); const [confirmDelete, setConfirmDelete] = React.useState(false); if (!lead) return null; const handleStatusChange = (newStatus: LeadStatus) => { updateStatus.mutate( { id: lead.id, status: newStatus }, { onSuccess: () => { onOpenChange(false); }, }, ); }; const handleDelete = () => { if (!confirmDelete) { setConfirmDelete(true); return; } deleteLead.mutate(lead.id, { onSuccess: () => { setConfirmDelete(false); onOpenChange(false); }, }); }; const createdDate = new Date(lead.createdAt).toLocaleDateString('vi-VN', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', }); const updatedDate = new Date(lead.updatedAt).toLocaleDateString('vi-VN', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', }); const notes = lead.notes && typeof lead.notes === 'object' && 'text' in lead.notes ? String(lead.notes['text']) : null; return ( { onOpenChange(v); setConfirmDelete(false); }}> Chi tiết lead {lead.name}
{/* Contact info */}
{lead.name}

SĐT: {lead.phone}

{lead.email &&

Email: {lead.email}

}

Nguồn: {getSourceLabel(lead.source)}

{lead.score !== null &&

Điểm: {lead.score}/100

}
{/* Timeline */}

Lịch sử

Tạo lúc: {createdDate}
{lead.createdAt !== lead.updatedAt && (
Cập nhật lúc: {updatedDate}
)}
{/* Notes */} {notes && (

Ghi chú

{notes}
)} {/* Score bar */} {lead.score !== null && (

Điểm lead

{lead.score}/100

)} {/* Quick actions */}

Liên hệ nhanh

{/* Status change */}

Chuyển trạng thái

); }