Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | 9x 188x 7x 7x 3x 1x 188x 7x 7x 6x 4x 4x 3x 14x 14x 14x 14x 14x 6x 4x 2x 8x 6x 4x 2x 188x 188x 188x 188x 188x 1x 1x 1x 1x 5x 5x 5x 4x 4x 4x | import { Link } from "@tanstack/react-router";
import {
Phone,
MessageCircle,
FileText,
Bell,
MapPin,
StickyNote,
} from "lucide-react";
import { cn } from "../../lib/utils";
import { whatsappUrl } from "../../lib/crm-constants";
import { abbreviatePaise } from "../../lib/currency-utils";
import type { Lead } from "../../lib/api/pro/crm";
// ─── Helpers ─────────────────────────────────────────────────────────────────
const PROJECT_TYPE_LABELS: Record<string, string> = {
modular_kitchen: "Kitchen",
full_interior: "Full Interior",
wardrobe: "Wardrobe",
tv_unit: "TV Unit",
pooja_unit: "Pooja Unit",
kitchen_renovation: "Kitchen Reno",
other: "Other",
};
function getContactRecencyColor(lastContactedAt: string | null): string {
if (!lastContactedAt) return "bg-foreground-subtle"; // gray — never contacted
const hours =
(Date.now() - new Date(lastContactedAt).getTime()) / (1000 * 60 * 60);
if (hours < 48) return "bg-success"; // green
if (hours < 168) return "bg-warning"; // yellow (7 days)
return "bg-error"; // red
}
function getContactRecencyLabel(lastContactedAt: string | null): string {
if (!lastContactedAt) return "Never contacted";
const hours =
(Date.now() - new Date(lastContactedAt).getTime()) / (1000 * 60 * 60);
if (hours < 1) return "Contacted just now";
if (hours < 24) return `Contacted ${Math.floor(hours)}h ago`;
const days = Math.floor(hours / 24);
if (days === 1) return "Contacted yesterday";
return `Contacted ${days}d ago`;
}
function formatNextReminder(dueAt: string): string {
const diff = new Date(dueAt).getTime() - Date.now();
const absDiff = Math.abs(diff);
const hours = Math.floor(absDiff / (1000 * 60 * 60));
const days = Math.floor(hours / 24);
if (diff < 0) {
if (hours < 1) return "overdue";
if (hours < 24) return `${hours}h overdue`;
return `${days}d overdue`;
}
if (hours < 1) return "< 1h";
if (hours < 24) return `in ${hours}h`;
if (days === 1) return "tomorrow";
return `in ${days}d`;
}
// ─── Component ───────────────────────────────────────────────────────────────
type LeadCardProps = {
lead: Lead;
sourceName?: string;
documentCount?: number;
reminderCount?: number;
nextReminderDueAt?: string | null;
onDragStart?: (e: React.DragEvent, leadId: number) => void;
onQuickNote?: (leadId: number) => void;
onQuickReminder?: (leadId: number) => void;
};
export function LeadCard({
lead,
sourceName,
documentCount = 0,
reminderCount = 0,
nextReminderDueAt,
onDragStart,
onQuickNote,
onQuickReminder,
}: LeadCardProps) {
const recencyColor = getContactRecencyColor(lead.lastContactedAt);
const recencyLabel = getContactRecencyLabel(lead.lastContactedAt);
const projectLabel = lead.projectType
? PROJECT_TYPE_LABELS[lead.projectType] || lead.projectType
: null;
const displayValue =
lead.quoteValuePaise ?? lead.orderValuePaise ?? null;
return (
<Link
to="/crm/leads/$leadId"
params={{ leadId: String(lead.id) }}
draggable={!!onDragStart}
onDragStart={onDragStart ? (e) => onDragStart(e, lead.id) : undefined}
className={cn(
"block rounded-lg border border-border-default bg-background-elevated p-3",
"shadow-sm hover:shadow-card-hover transition-shadow",
onDragStart ? "cursor-grab active:cursor-grabbing" : "cursor-pointer",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500",
)}
>
{/* Row 1: Recency dot + Name */}
<div className="flex items-center gap-2">
<span
className={cn("h-2 w-2 rounded-full flex-shrink-0", recencyColor)}
title={recencyLabel}
/>
<span className="text-sm font-medium text-foreground-default truncate">
{lead.customerName}
</span>
</div>
{/* Row 2: Phone + WhatsApp */}
<div className="mt-1.5 flex items-center gap-2 text-xs text-foreground-muted">
<Phone className="h-3 w-3 flex-shrink-0" />
<span className="truncate">{lead.phone}</span>
<button
type="button"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
window.open(
whatsappUrl(lead.phone),
"_blank",
"noopener",
);
}}
className="ml-auto flex-shrink-0 text-success hover:text-success/80 transition-colors"
title="Open WhatsApp"
>
<MessageCircle className="h-3.5 w-3.5" />
</button>
</div>
{/* Row 3: Source + Project type + Location */}
<div className="mt-2 flex flex-wrap items-center gap-1.5">
{sourceName && (
<span className="inline-flex items-center rounded-full bg-primary-100 px-2 py-0.5 text-[10px] font-medium text-primary-700">
{sourceName}
</span>
)}
{projectLabel && (
<span className="inline-flex items-center rounded-full bg-background-muted px-2 py-0.5 text-[10px] font-medium text-foreground-muted">
{projectLabel}
</span>
)}
{lead.location && (
<span className="inline-flex items-center gap-0.5 text-[10px] text-foreground-subtle">
<MapPin className="h-2.5 w-2.5" />
{lead.location}
</span>
)}
</div>
{/* Row 4: Value + indicators */}
{(displayValue || documentCount > 0 || reminderCount > 0) && (
<div className="mt-2 flex items-center justify-between text-xs">
{displayValue ? (
<span className="font-semibold text-foreground-default">
₹{abbreviatePaise(displayValue)}
</span>
) : (
<span />
)}
<div className="flex items-center gap-2 text-foreground-subtle">
{documentCount > 0 && (
<span className="flex items-center gap-0.5" title={`${documentCount} documents`}>
<FileText className="h-3 w-3" />
{documentCount}
</span>
)}
{reminderCount > 0 && (
<span
className="flex items-center gap-0.5 text-warning"
title={nextReminderDueAt ? `Next: ${formatNextReminder(nextReminderDueAt)}` : `${reminderCount} reminders`}
>
<Bell className="h-3 w-3" />
{nextReminderDueAt ? formatNextReminder(nextReminderDueAt) : reminderCount}
</span>
)}
</div>
</div>
)}
{/* Row 5: Quick actions */}
{(onQuickNote || onQuickReminder) && (
<div className="mt-2 pt-2 border-t border-border-default flex items-center gap-1">
{onQuickNote && (
<button
type="button"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onQuickNote(lead.id);
}}
className="p-1 rounded text-foreground-subtle hover:text-primary-600 hover:bg-primary-50 transition-colors"
title="Add note"
>
<StickyNote className="h-3.5 w-3.5" />
</button>
)}
{onQuickReminder && (
<button
type="button"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onQuickReminder(lead.id);
}}
className="p-1 rounded text-foreground-subtle hover:text-warning hover:bg-warning/10 transition-colors"
title="Set reminder"
>
<Bell className="h-3.5 w-3.5" />
</button>
)}
</div>
)}
</Link>
);
}
|