Spaces:
Running
Running
axeronis commited on
Commit ·
93d3f09
1
Parent(s): cd862bf
feat: add delete modal with AI cache clear option
Browse files- backend/app/api/leads.py +17 -1
- frontend/app/chats/page.tsx +8 -3
- frontend/components/LeadsList.tsx +203 -134
- frontend/lib/api.ts +4 -2
backend/app/api/leads.py
CHANGED
|
@@ -572,12 +572,14 @@ async def update_lead_stage(
|
|
| 572 |
@router.delete("/{lead_id}")
|
| 573 |
async def delete_lead(
|
| 574 |
lead_id: UUID,
|
|
|
|
| 575 |
current_user: User = Depends(get_current_user),
|
| 576 |
session = Depends(get_session)
|
| 577 |
):
|
| 578 |
"""
|
| 579 |
Delete a lead and all associated data (conversations, messages).
|
| 580 |
Tenant-isolated - users can only delete their own leads.
|
|
|
|
| 581 |
"""
|
| 582 |
# Use authenticated user's tenant_id (prevents tenant isolation breach)
|
| 583 |
tenant_id = current_user.tenant_id
|
|
@@ -615,9 +617,23 @@ async def delete_lead(
|
|
| 615 |
await session.delete(lead)
|
| 616 |
await session.commit()
|
| 617 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
return {
|
| 619 |
"ok": True,
|
| 620 |
"message": f"Lead '{lead_name}' and all associated data deleted successfully",
|
| 621 |
-
"lead_id": str(lead_id)
|
|
|
|
| 622 |
}
|
| 623 |
|
|
|
|
|
|
| 572 |
@router.delete("/{lead_id}")
|
| 573 |
async def delete_lead(
|
| 574 |
lead_id: UUID,
|
| 575 |
+
clear_cache: bool = Query(False, description="Clear AI memory cache for tenant"),
|
| 576 |
current_user: User = Depends(get_current_user),
|
| 577 |
session = Depends(get_session)
|
| 578 |
):
|
| 579 |
"""
|
| 580 |
Delete a lead and all associated data (conversations, messages).
|
| 581 |
Tenant-isolated - users can only delete their own leads.
|
| 582 |
+
Optional: clear_cache=true to invalidate AI memory cache.
|
| 583 |
"""
|
| 584 |
# Use authenticated user's tenant_id (prevents tenant isolation breach)
|
| 585 |
tenant_id = current_user.tenant_id
|
|
|
|
| 617 |
await session.delete(lead)
|
| 618 |
await session.commit()
|
| 619 |
|
| 620 |
+
# Optionally clear AI cache
|
| 621 |
+
cache_cleared = False
|
| 622 |
+
if clear_cache:
|
| 623 |
+
try:
|
| 624 |
+
from app.services.ai_memory_manager import get_memory_manager
|
| 625 |
+
tenant = await session.get(Tenant, tenant_id)
|
| 626 |
+
if tenant and tenant.ai_cache_key:
|
| 627 |
+
await get_memory_manager().invalidate_memory(session, tenant)
|
| 628 |
+
cache_cleared = True
|
| 629 |
+
except Exception as e:
|
| 630 |
+
print(f"⚠️ Failed to clear AI cache: {e}")
|
| 631 |
+
|
| 632 |
return {
|
| 633 |
"ok": True,
|
| 634 |
"message": f"Lead '{lead_name}' and all associated data deleted successfully",
|
| 635 |
+
"lead_id": str(lead_id),
|
| 636 |
+
"cache_cleared": cache_cleared
|
| 637 |
}
|
| 638 |
|
| 639 |
+
|
frontend/app/chats/page.tsx
CHANGED
|
@@ -99,10 +99,15 @@ function ChatsContent() {
|
|
| 99 |
}
|
| 100 |
|
| 101 |
// Delete Lead Handler
|
| 102 |
-
const handleDeleteLead = async (leadId: string) => {
|
| 103 |
try {
|
| 104 |
-
await leadsApi.deleteLead(leadId)
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
// Clear selection if deleted lead was selected
|
| 108 |
if (selectedLead?.id === leadId) {
|
|
|
|
| 99 |
}
|
| 100 |
|
| 101 |
// Delete Lead Handler
|
| 102 |
+
const handleDeleteLead = async (leadId: string, clearCache: boolean) => {
|
| 103 |
try {
|
| 104 |
+
const result = await leadsApi.deleteLead(leadId, clearCache)
|
| 105 |
+
|
| 106 |
+
if (result.cache_cleared) {
|
| 107 |
+
toast.success('Удалено', 'Чат удален и кэш AI очищен')
|
| 108 |
+
} else {
|
| 109 |
+
toast.success('Удалено', 'Чат успешно удален')
|
| 110 |
+
}
|
| 111 |
|
| 112 |
// Clear selection if deleted lead was selected
|
| 113 |
if (selectedLead?.id === leadId) {
|
frontend/components/LeadsList.tsx
CHANGED
|
@@ -1,15 +1,16 @@
|
|
| 1 |
'use client'
|
| 2 |
|
|
|
|
| 3 |
import { Lead } from '@/lib/api'
|
| 4 |
import { cn } from '@/lib/utils'
|
| 5 |
-
import { Search, Flame, Inbox, CheckCircle2, MessageCircle, Mail, Linkedin, Trash2 } from 'lucide-react'
|
| 6 |
|
| 7 |
interface LeadsListProps {
|
| 8 |
leads: Lead[] | undefined
|
| 9 |
isLoading: boolean
|
| 10 |
selectedLeadId: string | undefined
|
| 11 |
onSelectLead: (lead: Lead) => void
|
| 12 |
-
onDeleteLead?: (leadId: string) => void
|
| 13 |
searchQuery: string
|
| 14 |
setSearchQuery: (query: string) => void
|
| 15 |
activeTab: 'all' | 'hot' | 'unread' | 'whatsapp' | 'email' | 'linkedin'
|
|
@@ -28,6 +29,18 @@ export function LeadsList({
|
|
| 28 |
setActiveTab
|
| 29 |
}: LeadsListProps) {
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
// Filter Logic
|
| 32 |
const filteredLeads = leads?.filter(lead => {
|
| 33 |
const matchesSearch = (lead.name || '').toLowerCase().includes(searchQuery.toLowerCase())
|
|
@@ -60,152 +73,208 @@ export function LeadsList({
|
|
| 60 |
}
|
| 61 |
|
| 62 |
return (
|
| 63 |
-
<
|
| 64 |
-
{/*
|
| 65 |
-
|
| 66 |
-
<div className="flex items-center justify-
|
| 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 |
-
activeTab === 'hot' ? "bg-red-500/10 text-red-400" : "text-slate-500 hover:text-slate-300"
|
| 104 |
-
)}
|
| 105 |
-
>
|
| 106 |
-
<Flame className="w-3 h-3" />
|
| 107 |
-
Важные
|
| 108 |
-
</button>
|
| 109 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
|
|
|
| 113 |
</div>
|
| 114 |
-
</div>
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
| 127 |
</div>
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
const isSelected = selectedLeadId === lead.id
|
| 135 |
-
|
| 136 |
-
return (
|
| 137 |
-
<div
|
| 138 |
-
key={lead.id}
|
| 139 |
-
onClick={() => onSelectLead(lead)}
|
| 140 |
-
className={cn(
|
| 141 |
-
"p-3 rounded-xl cursor-pointer transition-all duration-200 group relative border",
|
| 142 |
-
isSelected
|
| 143 |
-
? "bg-[#1A1B26] border-white/5 shadow-lg"
|
| 144 |
-
: "bg-transparent border-transparent hover:bg-white/5"
|
| 145 |
-
)}
|
| 146 |
-
>
|
| 147 |
-
<div className="flex gap-3">
|
| 148 |
-
{/* Avatar */}
|
| 149 |
-
<div className="relative">
|
| 150 |
-
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center text-white font-bold text-sm shadow-inner">
|
| 151 |
-
{lead.name?.charAt(0) || '?'}
|
| 152 |
-
</div>
|
| 153 |
-
{/* Online/Status Indicator */}
|
| 154 |
-
<div className={cn(
|
| 155 |
-
"absolute bottom-0 right-0 w-3 h-3 rounded-full border-2 border-[#0D0E18]",
|
| 156 |
-
lead.heat_level === 'HOT' ? "bg-red-500" : "bg-green-500"
|
| 157 |
-
)} />
|
| 158 |
-
</div>
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
}
|
| 177 |
-
}}
|
| 178 |
-
className="p-1 opacity-0 group-hover:opacity-100 hover:bg-red-500/20 rounded-md transition-all"
|
| 179 |
-
title="Удалить чат"
|
| 180 |
-
>
|
| 181 |
-
<Trash2 className="w-3.5 h-3.5 text-red-400 hover:text-red-300" />
|
| 182 |
-
</button>
|
| 183 |
-
)}
|
| 184 |
-
<span className="text-[10px] text-slate-500 font-medium whitespace-nowrap">
|
| 185 |
-
{new Date(lead.last_message_at).toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' })}
|
| 186 |
-
</span>
|
| 187 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
</div>
|
| 189 |
|
| 190 |
-
<
|
| 191 |
-
"
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
</div>
|
| 197 |
</div>
|
| 198 |
-
|
| 199 |
-
)
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
</div>
|
| 208 |
-
</
|
| 209 |
)
|
| 210 |
}
|
| 211 |
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
+
import { useState } from 'react'
|
| 4 |
import { Lead } from '@/lib/api'
|
| 5 |
import { cn } from '@/lib/utils'
|
| 6 |
+
import { Search, Flame, Inbox, CheckCircle2, MessageCircle, Mail, Linkedin, Trash2, X, Brain } from 'lucide-react'
|
| 7 |
|
| 8 |
interface LeadsListProps {
|
| 9 |
leads: Lead[] | undefined
|
| 10 |
isLoading: boolean
|
| 11 |
selectedLeadId: string | undefined
|
| 12 |
onSelectLead: (lead: Lead) => void
|
| 13 |
+
onDeleteLead?: (leadId: string, clearCache: boolean) => void
|
| 14 |
searchQuery: string
|
| 15 |
setSearchQuery: (query: string) => void
|
| 16 |
activeTab: 'all' | 'hot' | 'unread' | 'whatsapp' | 'email' | 'linkedin'
|
|
|
|
| 29 |
setActiveTab
|
| 30 |
}: LeadsListProps) {
|
| 31 |
|
| 32 |
+
// Delete Modal State
|
| 33 |
+
const [deleteModal, setDeleteModal] = useState<{ leadId: string; leadName: string } | null>(null)
|
| 34 |
+
const [clearCacheOnDelete, setClearCacheOnDelete] = useState(false)
|
| 35 |
+
|
| 36 |
+
const handleConfirmDelete = () => {
|
| 37 |
+
if (deleteModal && onDeleteLead) {
|
| 38 |
+
onDeleteLead(deleteModal.leadId, clearCacheOnDelete)
|
| 39 |
+
setDeleteModal(null)
|
| 40 |
+
setClearCacheOnDelete(false)
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
// Filter Logic
|
| 45 |
const filteredLeads = leads?.filter(lead => {
|
| 46 |
const matchesSearch = (lead.name || '').toLowerCase().includes(searchQuery.toLowerCase())
|
|
|
|
| 73 |
}
|
| 74 |
|
| 75 |
return (
|
| 76 |
+
<>
|
| 77 |
+
{/* Delete Confirmation Modal */}
|
| 78 |
+
{deleteModal && (
|
| 79 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm">
|
| 80 |
+
<div className="bg-[#1A1B26] rounded-2xl border border-white/10 p-6 max-w-md w-full shadow-2xl">
|
| 81 |
+
<div className="flex items-center justify-between mb-4">
|
| 82 |
+
<h3 className="text-lg font-bold text-white">Удалить чат</h3>
|
| 83 |
+
<button
|
| 84 |
+
onClick={() => { setDeleteModal(null); setClearCacheOnDelete(false) }}
|
| 85 |
+
className="p-1 hover:bg-white/10 rounded-lg text-slate-400 hover:text-white"
|
| 86 |
+
>
|
| 87 |
+
<X className="w-5 h-5" />
|
| 88 |
+
</button>
|
| 89 |
+
</div>
|
| 90 |
|
| 91 |
+
<p className="text-slate-400 text-sm mb-4">
|
| 92 |
+
Удалить чат с <span className="font-semibold text-white">"{deleteModal.leadName}"</span>?
|
| 93 |
+
Все сообщения будут удалены безвозвратно.
|
| 94 |
+
</p>
|
| 95 |
+
|
| 96 |
+
{/* Cache Clear Option */}
|
| 97 |
+
<label className="flex items-start gap-3 p-3 bg-surface-elevated rounded-xl border border-white/5 cursor-pointer hover:border-indigo-500/30 transition-colors mb-4">
|
| 98 |
+
<input
|
| 99 |
+
type="checkbox"
|
| 100 |
+
checked={clearCacheOnDelete}
|
| 101 |
+
onChange={(e) => setClearCacheOnDelete(e.target.checked)}
|
| 102 |
+
className="w-4 h-4 mt-0.5 rounded border-white/20 bg-surface text-indigo-500 focus:ring-indigo-500/20"
|
| 103 |
+
/>
|
| 104 |
+
<div>
|
| 105 |
+
<div className="flex items-center gap-2 text-sm font-medium text-white">
|
| 106 |
+
<Brain className="w-4 h-4 text-indigo-400" />
|
| 107 |
+
Очистить кэш AI
|
| 108 |
+
</div>
|
| 109 |
+
<p className="text-xs text-slate-500 mt-1">
|
| 110 |
+
Сбросит память AI ассистента. Рекомендуется если клиент давал неверную информацию.
|
| 111 |
+
</p>
|
| 112 |
+
</div>
|
| 113 |
+
</label>
|
| 114 |
|
| 115 |
+
<div className="flex gap-3">
|
| 116 |
+
<button
|
| 117 |
+
onClick={() => { setDeleteModal(null); setClearCacheOnDelete(false) }}
|
| 118 |
+
className="flex-1 px-4 py-2.5 text-sm font-medium text-slate-400 hover:text-white transition-colors"
|
| 119 |
+
>
|
| 120 |
+
Отмена
|
| 121 |
+
</button>
|
| 122 |
+
<button
|
| 123 |
+
onClick={handleConfirmDelete}
|
| 124 |
+
className="flex-1 px-4 py-2.5 text-sm font-bold bg-red-500/20 text-red-400 rounded-xl hover:bg-red-500/30 transition-colors"
|
| 125 |
+
>
|
| 126 |
+
Удалить
|
| 127 |
+
</button>
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
</div>
|
| 131 |
+
)}
|
| 132 |
+
|
| 133 |
+
<div className="flex flex-col h-full bg-[#0D0E18] border-r border-white/10">
|
| 134 |
+
{/* Header & Search */}
|
| 135 |
+
<div className="p-4 border-b border-white/10 space-y-3 flex-shrink-0 bg-surface-elevated">
|
| 136 |
+
<div className="flex items-center justify-between">
|
| 137 |
+
<h2 className="text-xl font-bold text-white tracking-tight">Чаты</h2>
|
| 138 |
+
<button className="p-2 hover:bg-white/5 rounded-lg text-slate-400 hover:text-white transition-colors">
|
| 139 |
+
<Inbox className="w-5 h-5" />
|
| 140 |
+
</button>
|
| 141 |
+
</div>
|
| 142 |
+
|
| 143 |
+
{/* Start Active Chats Section (Visual Helper) */}
|
| 144 |
+
{/* In reference, there is a "Чаты" list directly. We keep search for usability though reference hides it or it's collapsed. */}
|
| 145 |
+
{/* We'll keep search but style it minimally */}
|
| 146 |
+
|
| 147 |
+
<div className="relative group">
|
| 148 |
+
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-500 group-focus-within:text-indigo-400 transition-colors" />
|
| 149 |
+
<input
|
| 150 |
+
type="text"
|
| 151 |
+
placeholder="Поиск..."
|
| 152 |
+
value={searchQuery}
|
| 153 |
+
onChange={(e) => setSearchQuery(e.target.value)}
|
| 154 |
+
className="w-full pl-9 pr-4 py-2 bg-[#0D0E18] border border-white/5 rounded-xl text-sm text-white focus:outline-none focus:border-indigo-500/50 transition-all placeholder:text-slate-600"
|
| 155 |
+
/>
|
| 156 |
+
</div>
|
| 157 |
+
|
| 158 |
+
{/* Tabs - Simplified to match clean look */}
|
| 159 |
+
<div className="flex gap-1 overflow-x-auto scrollbar-hide py-1">
|
| 160 |
+
<button
|
| 161 |
+
onClick={() => setActiveTab('all')}
|
| 162 |
+
className={cn(
|
| 163 |
+
"px-3 py-1 text-xs font-semibold rounded-full transition-all whitespace-nowrap",
|
| 164 |
+
activeTab === 'all' ? "bg-white/10 text-white" : "text-slate-500 hover:text-slate-300"
|
| 165 |
+
)}
|
| 166 |
+
>
|
| 167 |
+
Все
|
| 168 |
+
</button>
|
| 169 |
+
<button
|
| 170 |
+
onClick={() => setActiveTab('hot')}
|
| 171 |
+
className={cn(
|
| 172 |
+
"px-3 py-1 text-xs font-semibold rounded-full transition-all whitespace-nowrap flex items-center gap-1",
|
| 173 |
+
activeTab === 'hot' ? "bg-red-500/10 text-red-400" : "text-slate-500 hover:text-slate-300"
|
| 174 |
+
)}
|
| 175 |
+
>
|
| 176 |
+
<Flame className="w-3 h-3" />
|
| 177 |
+
Важные
|
| 178 |
+
</button>
|
| 179 |
+
</div>
|
| 180 |
|
| 181 |
+
<div className="text-[10px] font-bold text-slate-500 uppercase tracking-wider px-1">
|
| 182 |
+
Активные чаты
|
| 183 |
+
</div>
|
| 184 |
</div>
|
|
|
|
| 185 |
|
| 186 |
+
{/* List Content */}
|
| 187 |
+
<div className="flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-white/10 p-2 space-y-1">
|
| 188 |
+
{isLoading ? (
|
| 189 |
+
// Skeleton Loading
|
| 190 |
+
<div className="space-y-2 p-2">
|
| 191 |
+
{[1, 2, 3, 4, 5].map((i) => (
|
| 192 |
+
<div key={i} className="p-3 flex gap-3 animate-pulse bg-white/5 rounded-xl">
|
| 193 |
+
<div className="w-10 h-10 rounded-full bg-white/10 flex-shrink-0" />
|
| 194 |
+
<div className="flex-1 space-y-2">
|
| 195 |
+
<div className="h-4 bg-white/10 rounded w-24"></div>
|
| 196 |
+
<div className="h-3 bg-white/10 rounded w-full"></div>
|
| 197 |
+
</div>
|
| 198 |
</div>
|
| 199 |
+
))}
|
| 200 |
+
</div>
|
| 201 |
+
) : filteredLeads.length > 0 ? (
|
| 202 |
+
<>
|
| 203 |
+
{filteredLeads.map((lead) => {
|
| 204 |
+
const isSelected = selectedLeadId === lead.id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
+
return (
|
| 207 |
+
<div
|
| 208 |
+
key={lead.id}
|
| 209 |
+
onClick={() => onSelectLead(lead)}
|
| 210 |
+
className={cn(
|
| 211 |
+
"p-3 rounded-xl cursor-pointer transition-all duration-200 group relative border",
|
| 212 |
+
isSelected
|
| 213 |
+
? "bg-[#1A1B26] border-white/5 shadow-lg"
|
| 214 |
+
: "bg-transparent border-transparent hover:bg-white/5"
|
| 215 |
+
)}
|
| 216 |
+
>
|
| 217 |
+
<div className="flex gap-3">
|
| 218 |
+
{/* Avatar */}
|
| 219 |
+
<div className="relative">
|
| 220 |
+
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center text-white font-bold text-sm shadow-inner">
|
| 221 |
+
{lead.name?.charAt(0) || '?'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
</div>
|
| 223 |
+
{/* Online/Status Indicator */}
|
| 224 |
+
<div className={cn(
|
| 225 |
+
"absolute bottom-0 right-0 w-3 h-3 rounded-full border-2 border-[#0D0E18]",
|
| 226 |
+
lead.heat_level === 'HOT' ? "bg-red-500" : "bg-green-500"
|
| 227 |
+
)} />
|
| 228 |
</div>
|
| 229 |
|
| 230 |
+
<div className="flex-1 min-w-0">
|
| 231 |
+
<div className="flex justify-between items-baseline mb-0.5">
|
| 232 |
+
<h3 className={cn(
|
| 233 |
+
"font-semibold text-sm truncate pr-2",
|
| 234 |
+
isSelected ? "text-white" : "text-slate-300 group-hover:text-white"
|
| 235 |
+
)}>
|
| 236 |
+
{lead.name || 'Без имени'}
|
| 237 |
+
</h3>
|
| 238 |
+
<div className="flex items-center gap-1">
|
| 239 |
+
{/* Delete Button - shows on hover */}
|
| 240 |
+
{onDeleteLead && (
|
| 241 |
+
<button
|
| 242 |
+
onClick={(e) => {
|
| 243 |
+
e.stopPropagation()
|
| 244 |
+
setDeleteModal({ leadId: lead.id, leadName: lead.name || 'Без имени' })
|
| 245 |
+
}}
|
| 246 |
+
className="p-1 opacity-0 group-hover:opacity-100 hover:bg-red-500/20 rounded-md transition-all"
|
| 247 |
+
title="Удалить чат"
|
| 248 |
+
>
|
| 249 |
+
<Trash2 className="w-3.5 h-3.5 text-red-400 hover:text-red-300" />
|
| 250 |
+
</button>
|
| 251 |
+
)}
|
| 252 |
+
<span className="text-[10px] text-slate-500 font-medium whitespace-nowrap">
|
| 253 |
+
{new Date(lead.last_message_at).toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' })}
|
| 254 |
+
</span>
|
| 255 |
+
</div>
|
| 256 |
+
</div>
|
| 257 |
+
|
| 258 |
+
<p className={cn(
|
| 259 |
+
"text-xs truncate transition-colors",
|
| 260 |
+
isSelected ? "text-slate-400" : "text-slate-500 group-hover:text-slate-400"
|
| 261 |
+
)}>
|
| 262 |
+
Последнее сообщение...
|
| 263 |
+
</p>
|
| 264 |
+
</div>
|
| 265 |
</div>
|
| 266 |
</div>
|
| 267 |
+
)
|
| 268 |
+
})}
|
| 269 |
+
</>
|
| 270 |
+
) : (
|
| 271 |
+
<div className="text-center py-10 text-slate-500 text-sm">
|
| 272 |
+
Нет диалогов
|
| 273 |
+
</div>
|
| 274 |
+
)}
|
| 275 |
+
</div>
|
| 276 |
</div>
|
| 277 |
+
</>
|
| 278 |
)
|
| 279 |
}
|
| 280 |
|
frontend/lib/api.ts
CHANGED
|
@@ -126,8 +126,10 @@ export const leadsApi = {
|
|
| 126 |
return response.data
|
| 127 |
},
|
| 128 |
|
| 129 |
-
deleteLead: async (leadId: string) => {
|
| 130 |
-
const response = await api.delete(`/api/v1/leads/${leadId}`
|
|
|
|
|
|
|
| 131 |
return response.data
|
| 132 |
}
|
| 133 |
}
|
|
|
|
| 126 |
return response.data
|
| 127 |
},
|
| 128 |
|
| 129 |
+
deleteLead: async (leadId: string, clearCache: boolean = false) => {
|
| 130 |
+
const response = await api.delete(`/api/v1/leads/${leadId}`, {
|
| 131 |
+
params: { clear_cache: clearCache }
|
| 132 |
+
})
|
| 133 |
return response.data
|
| 134 |
}
|
| 135 |
}
|