Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
78f40f7
1
Parent(s): 2e478cd
Redesign Analytics page with dark mode and glassmorphism
Browse files- frontend/app/dashboard/page.tsx +348 -386
frontend/app/dashboard/page.tsx
CHANGED
|
@@ -2,14 +2,15 @@
|
|
| 2 |
|
| 3 |
import { useEffect, useState } from 'react'
|
| 4 |
import { useAuth } from '@/contexts/AuthContext'
|
| 5 |
-
import {
|
| 6 |
AreaChart, Area, BarChart, Bar, PieChart, Pie, Cell,
|
| 7 |
-
XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer
|
| 8 |
} from 'recharts'
|
| 9 |
-
import {
|
| 10 |
TrendingUp, Users, Clock, DollarSign, Target, Zap,
|
| 11 |
-
AlertCircle, Loader2, ArrowUp, MessageSquare
|
| 12 |
} from 'lucide-react'
|
|
|
|
| 13 |
|
| 14 |
interface DashboardMetrics {
|
| 15 |
total_leads: number
|
|
@@ -19,7 +20,7 @@ interface DashboardMetrics {
|
|
| 19 |
conversion_rate: number
|
| 20 |
pipeline_value: number
|
| 21 |
hours_saved: number
|
| 22 |
-
money_saved: number
|
| 23 |
}
|
| 24 |
|
| 25 |
interface FunnelStage {
|
|
@@ -54,16 +55,15 @@ interface DashboardData {
|
|
| 54 |
lead_value_over_time: LeadValueOverTime[]
|
| 55 |
}
|
| 56 |
|
| 57 |
-
// DISC Colors (
|
| 58 |
const DISC_COLORS = {
|
| 59 |
-
'Dominant': '#
|
| 60 |
-
'Influential': '#
|
| 61 |
-
'Steady': '#
|
| 62 |
-
'Conscientious': '#
|
| 63 |
-
'Unknown': '#9CA3AF' // Gray
|
| 64 |
}
|
| 65 |
|
| 66 |
-
// Russian psychotype mapping
|
| 67 |
const PSYCHOTYPE_RUSSIAN: Record<string, string> = {
|
| 68 |
'Dominant': 'Доминантный',
|
| 69 |
'Influential': 'Влияющий',
|
|
@@ -72,7 +72,6 @@ const PSYCHOTYPE_RUSSIAN: Record<string, string> = {
|
|
| 72 |
'Unknown': 'Неизвестно'
|
| 73 |
}
|
| 74 |
|
| 75 |
-
// Russian stage mapping
|
| 76 |
const STAGE_RUSSIAN: Record<string, string> = {
|
| 77 |
'New': 'Знакомство',
|
| 78 |
'Contacted': 'Контакт',
|
|
@@ -88,109 +87,75 @@ export default function DashboardPage() {
|
|
| 88 |
const [error, setError] = useState<string | null>(null)
|
| 89 |
|
| 90 |
useEffect(() => {
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
if (authLoading) {
|
| 94 |
-
console.log('⏳ [Dashboard] Waiting for auth...')
|
| 95 |
-
return
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
if (!user) {
|
| 99 |
-
console.error('❌ [Dashboard] No user found after auth loaded')
|
| 100 |
setError('Пользователь не авторизован')
|
| 101 |
setLoading(false)
|
| 102 |
return
|
| 103 |
}
|
| 104 |
-
|
| 105 |
-
console.log('✅ [Dashboard] User authenticated, fetching analytics...')
|
| 106 |
fetchAnalytics()
|
| 107 |
}, [user, authLoading])
|
| 108 |
|
| 109 |
const fetchAnalytics = async () => {
|
| 110 |
const token = localStorage.getItem('auth_token')
|
| 111 |
if (!token) {
|
| 112 |
-
console.error('❌ [Dashboard] No access token found')
|
| 113 |
setError('Токен авторизации не найден')
|
| 114 |
setLoading(false)
|
| 115 |
return
|
| 116 |
}
|
| 117 |
|
| 118 |
-
console.log('📡 [Dashboard] Fetching analytics with token:', token.substring(0, 20) + '...')
|
| 119 |
setError(null)
|
| 120 |
|
| 121 |
try {
|
| 122 |
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'
|
| 123 |
const fullUrl = `${apiUrl}/api/v1/analytics/dashboard`
|
| 124 |
-
|
| 125 |
-
|
| 126 |
const response = await fetch(fullUrl, {
|
| 127 |
headers: {
|
| 128 |
'Authorization': `Bearer ${token}`
|
| 129 |
}
|
| 130 |
})
|
| 131 |
|
| 132 |
-
console.log('📊 [Dashboard] Response status:', response.status)
|
| 133 |
-
|
| 134 |
if (response.ok) {
|
| 135 |
const analyticsData = await response.json()
|
| 136 |
-
console.log('✅ [Dashboard] Analytics data loaded successfully:', analyticsData)
|
| 137 |
setData(analyticsData)
|
| 138 |
} else {
|
| 139 |
-
const errorText = await response.text()
|
| 140 |
-
console.error('❌ [Dashboard] Failed to fetch analytics:', response.status, errorText)
|
| 141 |
-
|
| 142 |
-
setError(`Ошибка загрузки: ${response.status}`)
|
| 143 |
-
|
| 144 |
-
// If token expired or invalid, redirect to login
|
| 145 |
if (response.status === 401 || response.status === 403) {
|
| 146 |
-
console.error('🚪 [Dashboard] Authentication failed - redirecting to login')
|
| 147 |
localStorage.removeItem('auth_token')
|
| 148 |
-
document.cookie = 'auth_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT'
|
| 149 |
window.location.href = '/login'
|
| 150 |
}
|
|
|
|
| 151 |
}
|
| 152 |
} catch (error) {
|
| 153 |
-
console.error('💥 [Dashboard] Exception:', error)
|
| 154 |
setError(error instanceof Error ? error.message : 'Неизвестная ошибка')
|
| 155 |
} finally {
|
| 156 |
setLoading(false)
|
| 157 |
}
|
| 158 |
}
|
| 159 |
|
| 160 |
-
// Show loading while checking auth OR fetching data
|
| 161 |
if (authLoading || loading) {
|
| 162 |
return (
|
| 163 |
-
<div className="flex items-center justify-center
|
| 164 |
<div className="text-center">
|
| 165 |
-
<Loader2 className="w-12 h-12 animate-spin text-indigo-
|
| 166 |
-
<p className="text-slate-
|
| 167 |
-
{authLoading ? 'Проверка авторизации...' : 'Загрузка аналитики...'}
|
| 168 |
-
</p>
|
| 169 |
</div>
|
| 170 |
</div>
|
| 171 |
)
|
| 172 |
}
|
| 173 |
|
| 174 |
-
// Show error if auth failed or no user
|
| 175 |
if (!user || error) {
|
| 176 |
return (
|
| 177 |
-
<div className="flex items-center justify-center
|
| 178 |
-
<div className="text-center max-w-md">
|
| 179 |
<AlertCircle className="w-16 h-16 text-red-500 mx-auto mb-4" />
|
| 180 |
-
<h2 className="text-xl font-bold text-
|
| 181 |
-
<p className="text-slate-
|
| 182 |
-
{error || 'Пользователь не авторизован'}
|
| 183 |
-
</p>
|
| 184 |
-
<div className="bg-slate-100 rounded-lg p-4 text-left text-sm">
|
| 185 |
-
<p className="font-mono text-xs text-slate-700">
|
| 186 |
-
User: {user ? `${user.email} (${user.role})` : 'null'}<br />
|
| 187 |
-
Auth Loading: {authLoading ? 'true' : 'false'}<br />
|
| 188 |
-
Error: {error || 'none'}
|
| 189 |
-
</p>
|
| 190 |
-
</div>
|
| 191 |
<button
|
| 192 |
onClick={() => window.location.reload()}
|
| 193 |
-
className="
|
| 194 |
>
|
| 195 |
Обновить страницу
|
| 196 |
</button>
|
|
@@ -199,24 +164,8 @@ export default function DashboardPage() {
|
|
| 199 |
)
|
| 200 |
}
|
| 201 |
|
| 202 |
-
if (!data)
|
| 203 |
-
return (
|
| 204 |
-
<div className="flex items-center justify-center h-full bg-slate-50">
|
| 205 |
-
<div className="text-center">
|
| 206 |
-
<AlertCircle className="w-12 h-12 text-gray-400 mx-auto mb-4" />
|
| 207 |
-
<p className="text-gray-600">Нет данных для отображения</p>
|
| 208 |
-
<button
|
| 209 |
-
onClick={fetchAnalytics}
|
| 210 |
-
className="mt-4 px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700"
|
| 211 |
-
>
|
| 212 |
-
Повторить запрос
|
| 213 |
-
</button>
|
| 214 |
-
</div>
|
| 215 |
-
</div>
|
| 216 |
-
)
|
| 217 |
-
}
|
| 218 |
|
| 219 |
-
// Format currency in USD
|
| 220 |
const formatCurrency = (value: number) => {
|
| 221 |
return new Intl.NumberFormat('en-US', {
|
| 222 |
style: 'currency',
|
|
@@ -226,7 +175,6 @@ export default function DashboardPage() {
|
|
| 226 |
}).format(value)
|
| 227 |
}
|
| 228 |
|
| 229 |
-
// Format hours saved
|
| 230 |
const formatHoursSaved = (hours: number) => {
|
| 231 |
const h = Math.floor(hours)
|
| 232 |
const m = Math.round((hours - h) * 60)
|
|
@@ -234,335 +182,349 @@ export default function DashboardPage() {
|
|
| 234 |
}
|
| 235 |
|
| 236 |
return (
|
| 237 |
-
<div className="
|
| 238 |
-
{/*
|
| 239 |
-
<div className="
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
<
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
<
|
| 250 |
-
<div>
|
| 251 |
-
<p className="text-indigo-200 text-sm font-medium mb-1">Объем Пайплайна</p>
|
| 252 |
-
<h2 className="text-4xl font-bold">{formatCurrency(data.metrics.pipeline_value)}</h2>
|
| 253 |
-
<p className="text-indigo-200 text-xs mt-1">Потенциальная выручка</p>
|
| 254 |
-
</div>
|
| 255 |
-
<div className="w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center">
|
| 256 |
-
<DollarSign className="w-6 h-6" />
|
| 257 |
-
</div>
|
| 258 |
-
</div>
|
| 259 |
-
|
| 260 |
-
{/* Area Chart */}
|
| 261 |
-
<div className="h-48 -mx-2">
|
| 262 |
-
<ResponsiveContainer width="100%" height="100%">
|
| 263 |
-
<AreaChart data={data.lead_value_over_time}>
|
| 264 |
-
<defs>
|
| 265 |
-
<linearGradient id="colorValue" x1="0" y1="0" x2="0" y2="1">
|
| 266 |
-
<stop offset="5%" stopColor="#ffffff" stopOpacity={0.3}/>
|
| 267 |
-
<stop offset="95%" stopColor="#ffffff" stopOpacity={0}/>
|
| 268 |
-
</linearGradient>
|
| 269 |
-
</defs>
|
| 270 |
-
<XAxis
|
| 271 |
-
dataKey="date"
|
| 272 |
-
stroke="#ffffff"
|
| 273 |
-
opacity={0.5}
|
| 274 |
-
tick={{ fontSize: 12 }}
|
| 275 |
-
tickFormatter={(value) => {
|
| 276 |
-
const date = new Date(value)
|
| 277 |
-
return `${date.getDate()}/${date.getMonth() + 1}`
|
| 278 |
-
}}
|
| 279 |
-
/>
|
| 280 |
-
<YAxis stroke="#ffffff" opacity={0.5} tick={{ fontSize: 12 }} />
|
| 281 |
-
<Tooltip
|
| 282 |
-
contentStyle={{
|
| 283 |
-
backgroundColor: 'rgba(255, 255, 255, 0.95)',
|
| 284 |
-
border: 'none',
|
| 285 |
-
borderRadius: '8px',
|
| 286 |
-
color: '#1e293b'
|
| 287 |
-
}}
|
| 288 |
-
formatter={(value: any) => [formatCurrency(value), 'Ценность']}
|
| 289 |
-
labelFormatter={(value) => {
|
| 290 |
-
const date = new Date(value)
|
| 291 |
-
return date.toLocaleDateString('ru-RU', { day: 'numeric', month: 'short' })
|
| 292 |
-
}}
|
| 293 |
-
/>
|
| 294 |
-
<Area
|
| 295 |
-
type="monotone"
|
| 296 |
-
dataKey="value"
|
| 297 |
-
stroke="#ffffff"
|
| 298 |
-
strokeWidth={2}
|
| 299 |
-
fill="url(#colorValue)"
|
| 300 |
-
/>
|
| 301 |
-
</AreaChart>
|
| 302 |
-
</ResponsiveContainer>
|
| 303 |
-
</div>
|
| 304 |
</div>
|
| 305 |
|
| 306 |
-
{/*
|
| 307 |
-
<div className="
|
| 308 |
-
<div className="flex items-center justify-between mb-4">
|
| 309 |
-
<div className="w-10 h-10 bg-emerald-100 rounded-xl flex items-center justify-center">
|
| 310 |
-
<TrendingUp className="w-5 h-5 text-emerald-600" />
|
| 311 |
-
</div>
|
| 312 |
-
<div className="flex items-center gap-1 text-emerald-600 text-sm font-semibold">
|
| 313 |
-
<ArrowUp className="w-4 h-4" />
|
| 314 |
-
{data.metrics.conversion_rate > 15 ? '+12%' : '+5%'}
|
| 315 |
-
</div>
|
| 316 |
-
</div>
|
| 317 |
-
<p className="text-slate-600 text-sm font-medium mb-1">Конверсия</p>
|
| 318 |
-
<h3 className="text-3xl font-bold text-slate-900">{data.metrics.conversion_rate}%</h3>
|
| 319 |
-
<p className="text-xs text-slate-500 mt-2">
|
| 320 |
-
{data.metrics.total_leads} всего лидов
|
| 321 |
-
</p>
|
| 322 |
-
</div>
|
| 323 |
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
</span>
|
| 334 |
</div>
|
| 335 |
-
</div>
|
| 336 |
-
<p className="text-slate-600 text-sm font-medium mb-1">Активные Диалоги</p>
|
| 337 |
-
<h3 className="text-3xl font-bold text-slate-900">{data.metrics.total_leads}</h3>
|
| 338 |
-
<p className="text-xs text-slate-500 mt-2">
|
| 339 |
-
{data.metrics.hot_leads} горячих лидов
|
| 340 |
-
</p>
|
| 341 |
-
</div>
|
| 342 |
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
</div>
|
| 353 |
-
</div>
|
| 354 |
-
<p className="text-slate-600 text-sm font-medium mb-1">Сэкономлено Времени</p>
|
| 355 |
-
<h3 className="text-3xl font-bold text-slate-900">{formatHoursSaved(data.metrics.hours_saved)}</h3>
|
| 356 |
-
<p className="text-xs text-slate-500 mt-2">
|
| 357 |
-
Эквивалент работы менеджера
|
| 358 |
-
</p>
|
| 359 |
-
</div>
|
| 360 |
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
</div>
|
| 371 |
-
</div>
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
}}
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
radius={[8, 8, 0, 0]}
|
| 426 |
-
maxBarSize={60}
|
| 427 |
-
/>
|
| 428 |
-
</BarChart>
|
| 429 |
-
</ResponsiveContainer>
|
| 430 |
-
</div>
|
| 431 |
-
</div>
|
| 432 |
-
|
| 433 |
-
{/* DISC Personality Distribution */}
|
| 434 |
-
<div className="lg:col-span-2 bg-white rounded-2xl shadow-sm p-6 border border-gray-100">
|
| 435 |
-
<div className="flex items-center gap-2 mb-6">
|
| 436 |
-
<Users className="w-5 h-5 text-indigo-600" />
|
| 437 |
-
<h3 className="text-lg font-bold text-slate-900">Психотипы Клиентов (DISC)</h3>
|
| 438 |
-
</div>
|
| 439 |
-
<div className="h-64">
|
| 440 |
-
<ResponsiveContainer width="100%" height="100%">
|
| 441 |
-
<PieChart>
|
| 442 |
-
<Pie
|
| 443 |
-
data={data.disc_distribution.map(disc => ({
|
| 444 |
-
...disc,
|
| 445 |
-
psychotype: PSYCHOTYPE_RUSSIAN[disc.psychotype] || disc.psychotype
|
| 446 |
-
})) as any}
|
| 447 |
-
cx="50%"
|
| 448 |
-
cy="45%"
|
| 449 |
-
innerRadius={60}
|
| 450 |
-
outerRadius={90}
|
| 451 |
-
paddingAngle={2}
|
| 452 |
-
dataKey="count"
|
| 453 |
-
>
|
| 454 |
-
{data.disc_distribution.map((entry, index) => (
|
| 455 |
-
<Cell
|
| 456 |
-
key={`cell-${index}`}
|
| 457 |
-
fill={DISC_COLORS[entry.psychotype as keyof typeof DISC_COLORS] || DISC_COLORS['Unknown']}
|
| 458 |
-
/>
|
| 459 |
-
))}
|
| 460 |
-
</Pie>
|
| 461 |
-
<Tooltip
|
| 462 |
-
contentStyle={{
|
| 463 |
-
backgroundColor: 'white',
|
| 464 |
-
border: '1px solid #e2e8f0',
|
| 465 |
-
borderRadius: '8px'
|
| 466 |
-
}}
|
| 467 |
-
formatter={(value: any, name: string, props: any) => [
|
| 468 |
-
`${value} лидов (${props.payload.percentage.toFixed(1)}%)`,
|
| 469 |
-
PSYCHOTYPE_RUSSIAN[props.payload.psychotype] || props.payload.psychotype
|
| 470 |
-
]}
|
| 471 |
-
/>
|
| 472 |
-
<Legend
|
| 473 |
-
verticalAlign="bottom"
|
| 474 |
-
height={36}
|
| 475 |
-
formatter={(value, entry: any) => {
|
| 476 |
-
const item = entry.payload
|
| 477 |
-
const russianName = PSYCHOTYPE_RUSSIAN[item.psychotype] || item.psychotype
|
| 478 |
-
return `${russianName}: ${item.count}`
|
| 479 |
-
}}
|
| 480 |
-
/>
|
| 481 |
-
</PieChart>
|
| 482 |
-
</ResponsiveContainer>
|
| 483 |
-
</div>
|
| 484 |
-
</div>
|
| 485 |
-
|
| 486 |
-
{/* Lead Temperature Stats */}
|
| 487 |
-
<div className="bg-white rounded-2xl shadow-sm p-6 border border-gray-100">
|
| 488 |
-
<h3 className="text-sm font-medium text-slate-500 uppercase mb-4">Температура Лидов</h3>
|
| 489 |
-
<div className="space-y-4">
|
| 490 |
-
<div>
|
| 491 |
-
<div className="flex items-center justify-between mb-2">
|
| 492 |
-
<p className="text-slate-700 text-sm font-medium">🔥 Горячие</p>
|
| 493 |
-
<span className="text-2xl font-bold text-red-600">{data.metrics.hot_leads}</span>
|
| 494 |
</div>
|
| 495 |
-
<
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
</div>
|
|
|
|
| 501 |
</div>
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
</div>
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
|
|
|
| 526 |
</div>
|
|
|
|
| 527 |
</div>
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
</div>
|
| 550 |
-
<div className="w-full bg-
|
| 551 |
-
<div
|
| 552 |
-
|
| 553 |
-
|
|
|
|
|
|
|
| 554 |
/>
|
| 555 |
</div>
|
| 556 |
</div>
|
| 557 |
))}
|
| 558 |
</div>
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 566 |
</div>
|
| 567 |
</div>
|
| 568 |
)
|
|
|
|
| 2 |
|
| 3 |
import { useEffect, useState } from 'react'
|
| 4 |
import { useAuth } from '@/contexts/AuthContext'
|
| 5 |
+
import {
|
| 6 |
AreaChart, Area, BarChart, Bar, PieChart, Pie, Cell,
|
| 7 |
+
XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer
|
| 8 |
} from 'recharts'
|
| 9 |
+
import {
|
| 10 |
TrendingUp, Users, Clock, DollarSign, Target, Zap,
|
| 11 |
+
AlertCircle, Loader2, ArrowUp, MessageSquare, Activity
|
| 12 |
} from 'lucide-react'
|
| 13 |
+
import { motion } from 'framer-motion'
|
| 14 |
|
| 15 |
interface DashboardMetrics {
|
| 16 |
total_leads: number
|
|
|
|
| 20 |
conversion_rate: number
|
| 21 |
pipeline_value: number
|
| 22 |
hours_saved: number
|
| 23 |
+
money_saved: number
|
| 24 |
}
|
| 25 |
|
| 26 |
interface FunnelStage {
|
|
|
|
| 55 |
lead_value_over_time: LeadValueOverTime[]
|
| 56 |
}
|
| 57 |
|
| 58 |
+
// DISC Colors (Neon/Dark mode friendly)
|
| 59 |
const DISC_COLORS = {
|
| 60 |
+
'Dominant': '#F87171', // Red-400
|
| 61 |
+
'Influential': '#FBBF24', // Amber-400
|
| 62 |
+
'Steady': '#34D399', // Emerald-400
|
| 63 |
+
'Conscientious': '#60A5FA', // Blue-400
|
| 64 |
+
'Unknown': '#9CA3AF' // Gray-400
|
| 65 |
}
|
| 66 |
|
|
|
|
| 67 |
const PSYCHOTYPE_RUSSIAN: Record<string, string> = {
|
| 68 |
'Dominant': 'Доминантный',
|
| 69 |
'Influential': 'Влияющий',
|
|
|
|
| 72 |
'Unknown': 'Неизвестно'
|
| 73 |
}
|
| 74 |
|
|
|
|
| 75 |
const STAGE_RUSSIAN: Record<string, string> = {
|
| 76 |
'New': 'Знакомство',
|
| 77 |
'Contacted': 'Контакт',
|
|
|
|
| 87 |
const [error, setError] = useState<string | null>(null)
|
| 88 |
|
| 89 |
useEffect(() => {
|
| 90 |
+
if (authLoading) return
|
| 91 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
if (!user) {
|
|
|
|
| 93 |
setError('Пользователь не авторизован')
|
| 94 |
setLoading(false)
|
| 95 |
return
|
| 96 |
}
|
| 97 |
+
|
|
|
|
| 98 |
fetchAnalytics()
|
| 99 |
}, [user, authLoading])
|
| 100 |
|
| 101 |
const fetchAnalytics = async () => {
|
| 102 |
const token = localStorage.getItem('auth_token')
|
| 103 |
if (!token) {
|
|
|
|
| 104 |
setError('Токен авторизации не найден')
|
| 105 |
setLoading(false)
|
| 106 |
return
|
| 107 |
}
|
| 108 |
|
|
|
|
| 109 |
setError(null)
|
| 110 |
|
| 111 |
try {
|
| 112 |
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'
|
| 113 |
const fullUrl = `${apiUrl}/api/v1/analytics/dashboard`
|
| 114 |
+
|
|
|
|
| 115 |
const response = await fetch(fullUrl, {
|
| 116 |
headers: {
|
| 117 |
'Authorization': `Bearer ${token}`
|
| 118 |
}
|
| 119 |
})
|
| 120 |
|
|
|
|
|
|
|
| 121 |
if (response.ok) {
|
| 122 |
const analyticsData = await response.json()
|
|
|
|
| 123 |
setData(analyticsData)
|
| 124 |
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
if (response.status === 401 || response.status === 403) {
|
|
|
|
| 126 |
localStorage.removeItem('auth_token')
|
|
|
|
| 127 |
window.location.href = '/login'
|
| 128 |
}
|
| 129 |
+
setError(`Ошибка загрузки: ${response.status}`)
|
| 130 |
}
|
| 131 |
} catch (error) {
|
|
|
|
| 132 |
setError(error instanceof Error ? error.message : 'Неизвестная ошибка')
|
| 133 |
} finally {
|
| 134 |
setLoading(false)
|
| 135 |
}
|
| 136 |
}
|
| 137 |
|
|
|
|
| 138 |
if (authLoading || loading) {
|
| 139 |
return (
|
| 140 |
+
<div className="min-h-screen flex items-center justify-center bg-[#020005]">
|
| 141 |
<div className="text-center">
|
| 142 |
+
<Loader2 className="w-12 h-12 animate-spin text-indigo-500 mx-auto mb-4" />
|
| 143 |
+
<p className="text-slate-400 font-medium">Загрузка аналитики...</p>
|
|
|
|
|
|
|
| 144 |
</div>
|
| 145 |
</div>
|
| 146 |
)
|
| 147 |
}
|
| 148 |
|
|
|
|
| 149 |
if (!user || error) {
|
| 150 |
return (
|
| 151 |
+
<div className="min-h-screen flex items-center justify-center bg-[#020005]">
|
| 152 |
+
<div className="text-center max-w-md p-8 glass-card rounded-2xl border border-white/10">
|
| 153 |
<AlertCircle className="w-16 h-16 text-red-500 mx-auto mb-4" />
|
| 154 |
+
<h2 className="text-xl font-bold text-white mb-2">Ошибка загрузки</h2>
|
| 155 |
+
<p className="text-slate-400 mb-6">{error || 'Пользователь не авторизован'}</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
<button
|
| 157 |
onClick={() => window.location.reload()}
|
| 158 |
+
className="px-6 py-2 bg-indigo-600 text-white rounded-xl hover:bg-indigo-500 transition-colors"
|
| 159 |
>
|
| 160 |
Обновить страницу
|
| 161 |
</button>
|
|
|
|
| 164 |
)
|
| 165 |
}
|
| 166 |
|
| 167 |
+
if (!data) return null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
|
|
|
| 169 |
const formatCurrency = (value: number) => {
|
| 170 |
return new Intl.NumberFormat('en-US', {
|
| 171 |
style: 'currency',
|
|
|
|
| 175 |
}).format(value)
|
| 176 |
}
|
| 177 |
|
|
|
|
| 178 |
const formatHoursSaved = (hours: number) => {
|
| 179 |
const h = Math.floor(hours)
|
| 180 |
const m = Math.round((hours - h) * 60)
|
|
|
|
| 182 |
}
|
| 183 |
|
| 184 |
return (
|
| 185 |
+
<div className="min-h-screen bg-[#020005] font-['Inter'] relative overflow-hidden p-4 md:p-8">
|
| 186 |
+
{/* Background Effects */}
|
| 187 |
+
<div className="absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-indigo-900/10 via-[#020005] to-[#020005] pointer-events-none" />
|
| 188 |
+
<div className="absolute top-0 left-1/4 w-96 h-96 bg-indigo-500/5 rounded-full blur-[100px] animate-pulse pointer-events-none" />
|
| 189 |
+
|
| 190 |
+
<div className="max-w-7xl mx-auto relative z-10">
|
| 191 |
+
{/* Header */}
|
| 192 |
+
<div className="mb-10">
|
| 193 |
+
<h1 className="text-3xl font-bold text-white mb-2 flex items-center gap-3">
|
| 194 |
+
<Activity className="w-8 h-8 text-indigo-500" />
|
| 195 |
+
Аналитика Продаж
|
| 196 |
+
</h1>
|
| 197 |
+
<p className="text-slate-400">Обзор эффективности вашего AI-отдела продаж</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
</div>
|
| 199 |
|
| 200 |
+
{/* Bento Grid */}
|
| 201 |
+
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
+
{/* Revenue Card */}
|
| 204 |
+
<motion.div
|
| 205 |
+
initial={{ opacity: 0, y: 20 }}
|
| 206 |
+
animate={{ opacity: 1, y: 0 }}
|
| 207 |
+
transition={{ duration: 0.5 }}
|
| 208 |
+
className="lg:col-span-2 relative overflow-hidden rounded-3xl border border-indigo-500/30 bg-gradient-to-br from-[#1e1b4b] to-[#0f172a] p-6 shadow-2xl shadow-indigo-500/10"
|
| 209 |
+
>
|
| 210 |
+
<div className="absolute top-0 right-0 p-8 opacity-10">
|
| 211 |
+
<DollarSign className="w-32 h-32 text-indigo-500 -rotate-12" />
|
|
|
|
| 212 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
+
<div className="relative z-10 flex items-center justify-between mb-6">
|
| 215 |
+
<div>
|
| 216 |
+
<p className="text-indigo-300 text-sm font-medium mb-1">Объем Пайплайна</p>
|
| 217 |
+
<h2 className="text-4xl font-bold text-white">{formatCurrency(data.metrics.pipeline_value)}</h2>
|
| 218 |
+
<p className="text-slate-400 text-xs mt-1">Потенциальная выручка</p>
|
| 219 |
+
</div>
|
| 220 |
+
<div className="w-12 h-12 bg-indigo-500/20 rounded-xl flex items-center justify-center border border-indigo-500/30">
|
| 221 |
+
<DollarSign className="w-6 h-6 text-indigo-400" />
|
| 222 |
+
</div>
|
| 223 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
+
<div className="h-48 -mx-2">
|
| 226 |
+
<ResponsiveContainer width="100%" height="100%">
|
| 227 |
+
<AreaChart data={data.lead_value_over_time}>
|
| 228 |
+
<defs>
|
| 229 |
+
<linearGradient id="colorValue" x1="0" y1="0" x2="0" y2="1">
|
| 230 |
+
<stop offset="5%" stopColor="#6366f1" stopOpacity={0.3} />
|
| 231 |
+
<stop offset="95%" stopColor="#6366f1" stopOpacity={0} />
|
| 232 |
+
</linearGradient>
|
| 233 |
+
</defs>
|
| 234 |
+
<XAxis
|
| 235 |
+
dataKey="date"
|
| 236 |
+
stroke="#475569"
|
| 237 |
+
tick={{ fontSize: 12, fill: '#94a3b8' }}
|
| 238 |
+
tickFormatter={(value) => {
|
| 239 |
+
const date = new Date(value)
|
| 240 |
+
return `${date.getDate()}/${date.getMonth() + 1}`
|
| 241 |
+
}}
|
| 242 |
+
/>
|
| 243 |
+
<YAxis stroke="#475569" tick={{ fontSize: 12, fill: '#94a3b8' }} />
|
| 244 |
+
<Tooltip
|
| 245 |
+
contentStyle={{
|
| 246 |
+
backgroundColor: '#0f172a',
|
| 247 |
+
border: '1px solid rgba(255,255,255,0.1)',
|
| 248 |
+
borderRadius: '12px',
|
| 249 |
+
color: '#fff'
|
| 250 |
+
}}
|
| 251 |
+
formatter={(value: any) => [formatCurrency(value), 'Ценность']}
|
| 252 |
+
labelFormatter={(value) => {
|
| 253 |
+
const date = new Date(value)
|
| 254 |
+
return date.toLocaleDateString('ru-RU', { day: 'numeric', month: 'short' })
|
| 255 |
+
}}
|
| 256 |
+
/>
|
| 257 |
+
<Area
|
| 258 |
+
type="monotone"
|
| 259 |
+
dataKey="value"
|
| 260 |
+
stroke="#6366f1"
|
| 261 |
+
strokeWidth={3}
|
| 262 |
+
fill="url(#colorValue)"
|
| 263 |
+
/>
|
| 264 |
+
</AreaChart>
|
| 265 |
+
</ResponsiveContainer>
|
| 266 |
</div>
|
| 267 |
+
</motion.div>
|
| 268 |
+
|
| 269 |
+
{/* KPI Cards */}
|
| 270 |
+
{[
|
| 271 |
+
{
|
| 272 |
+
title: "Конверсия",
|
| 273 |
+
value: `${data.metrics.conversion_rate}%`,
|
| 274 |
+
sub: `${data.metrics.total_leads} всего лидов`,
|
| 275 |
+
icon: TrendingUp,
|
| 276 |
+
color: "emerald",
|
| 277 |
+
trend: data.metrics.conversion_rate > 15 ? '+12%' : '+5%'
|
| 278 |
+
},
|
| 279 |
+
{
|
| 280 |
+
title: "Активные Диалоги",
|
| 281 |
+
value: data.metrics.total_leads,
|
| 282 |
+
sub: `${data.metrics.hot_leads} горячих лидов`,
|
| 283 |
+
icon: MessageSquare,
|
| 284 |
+
color: "blue",
|
| 285 |
+
trend: `+${data.metrics.hot_leads} сегодня`
|
| 286 |
+
},
|
| 287 |
+
{
|
| 288 |
+
title: "Сэкономлено Времени",
|
| 289 |
+
value: formatHoursSaved(data.metrics.hours_saved),
|
| 290 |
+
sub: "Эквивалент работы менеджера",
|
| 291 |
+
icon: Clock,
|
| 292 |
+
color: "purple",
|
| 293 |
+
trend: "AI"
|
| 294 |
+
},
|
| 295 |
+
{
|
| 296 |
+
title: "Сэкономлено Денег",
|
| 297 |
+
value: formatCurrency(data.metrics.money_saved),
|
| 298 |
+
sub: "На основе почасовой ставки",
|
| 299 |
+
icon: Zap,
|
| 300 |
+
color: "amber",
|
| 301 |
+
trend: "ROI"
|
| 302 |
+
}
|
| 303 |
+
].map((kpi, i) => (
|
| 304 |
+
<motion.div
|
| 305 |
+
key={i}
|
| 306 |
+
initial={{ opacity: 0, y: 20 }}
|
| 307 |
+
animate={{ opacity: 1, y: 0 }}
|
| 308 |
+
transition={{ duration: 0.5, delay: i * 0.1 }}
|
| 309 |
+
className="bg-white/5 border border-white/10 rounded-3xl p-6 backdrop-blur-md hover:bg-white/10 transition-colors"
|
| 310 |
+
>
|
| 311 |
+
<div className="flex items-center justify-between mb-4">
|
| 312 |
+
<div className={`w-10 h-10 rounded-xl flex items-center justify-center bg-${kpi.color}-500/20 border border-${kpi.color}-500/30`}>
|
| 313 |
+
<kpi.icon className={`w-5 h-5 text-${kpi.color}-400`} />
|
| 314 |
+
</div>
|
| 315 |
+
<div className={`px-2 py-1 rounded-full bg-${kpi.color}-500/10 border border-${kpi.color}-500/20`}>
|
| 316 |
+
<span className={`text-${kpi.color}-400 text-xs font-semibold flex items-center gap-1`}>
|
| 317 |
+
{kpi.title === "Конверсия" && <ArrowUp className="w-3 h-3" />}
|
| 318 |
+
{kpi.trend}
|
| 319 |
+
</span>
|
| 320 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
</div>
|
| 322 |
+
<p className="text-slate-400 text-sm font-medium mb-1">{kpi.title}</p>
|
| 323 |
+
<h3 className="text-3xl font-bold text-white">{kpi.value}</h3>
|
| 324 |
+
<p className="text-xs text-slate-500 mt-2">{kpi.sub}</p>
|
| 325 |
+
</motion.div>
|
| 326 |
+
))}
|
| 327 |
+
|
| 328 |
+
{/* Sales Funnel */}
|
| 329 |
+
<motion.div
|
| 330 |
+
initial={{ opacity: 0, y: 20 }}
|
| 331 |
+
animate={{ opacity: 1, y: 0 }}
|
| 332 |
+
transition={{ duration: 0.5, delay: 0.2 }}
|
| 333 |
+
className="lg:col-span-2 bg-white/5 border border-white/10 rounded-3xl p-6 backdrop-blur-md"
|
| 334 |
+
>
|
| 335 |
+
<div className="flex items-center gap-3 mb-6">
|
| 336 |
+
<div className="w-8 h-8 rounded-lg bg-orange-500/20 flex items-center justify-center border border-orange-500/30">
|
| 337 |
+
<Target className="w-4 h-4 text-orange-400" />
|
| 338 |
</div>
|
| 339 |
+
<h3 className="text-lg font-bold text-white">Воронка Продаж</h3>
|
| 340 |
</div>
|
| 341 |
+
<div className="h-64">
|
| 342 |
+
<ResponsiveContainer width="100%" height="100%">
|
| 343 |
+
<BarChart data={data.funnel.map(stage => ({
|
| 344 |
+
...stage,
|
| 345 |
+
stage: STAGE_RUSSIAN[stage.stage] || stage.stage
|
| 346 |
+
}))} layout="horizontal">
|
| 347 |
+
<defs>
|
| 348 |
+
<linearGradient id="colorBar" x1="0" y1="0" x2="0" y2="1">
|
| 349 |
+
<stop offset="0%" stopColor="#818cf8" />
|
| 350 |
+
<stop offset="100%" stopColor="#4f46e5" />
|
| 351 |
+
</linearGradient>
|
| 352 |
+
</defs>
|
| 353 |
+
<CartesianGrid strokeDasharray="3 3" stroke="#334155" vertical={false} />
|
| 354 |
+
<XAxis
|
| 355 |
+
dataKey="stage"
|
| 356 |
+
tick={{ fontSize: 12, fill: '#94a3b8' }}
|
| 357 |
+
stroke="#475569"
|
| 358 |
+
axisLine={false}
|
| 359 |
+
tickLine={false}
|
| 360 |
+
/>
|
| 361 |
+
<YAxis
|
| 362 |
+
tick={{ fontSize: 12, fill: '#94a3b8' }}
|
| 363 |
+
stroke="#475569"
|
| 364 |
+
axisLine={false}
|
| 365 |
+
tickLine={false}
|
| 366 |
+
/>
|
| 367 |
+
<Tooltip
|
| 368 |
+
cursor={{ fill: 'rgba(255,255,255,0.05)' }}
|
| 369 |
+
contentStyle={{
|
| 370 |
+
backgroundColor: '#0f172a',
|
| 371 |
+
border: '1px solid rgba(255,255,255,0.1)',
|
| 372 |
+
borderRadius: '12px',
|
| 373 |
+
color: '#fff'
|
| 374 |
+
}}
|
| 375 |
+
formatter={(value: any) => [value, 'Лиды']}
|
| 376 |
+
/>
|
| 377 |
+
<Bar
|
| 378 |
+
dataKey="count"
|
| 379 |
+
fill="url(#colorBar)"
|
| 380 |
+
radius={[6, 6, 0, 0]}
|
| 381 |
+
maxBarSize={50}
|
| 382 |
+
/>
|
| 383 |
+
</BarChart>
|
| 384 |
+
</ResponsiveContainer>
|
| 385 |
</div>
|
| 386 |
+
</motion.div>
|
| 387 |
+
|
| 388 |
+
{/* DISC Distribution */}
|
| 389 |
+
<motion.div
|
| 390 |
+
initial={{ opacity: 0, y: 20 }}
|
| 391 |
+
animate={{ opacity: 1, y: 0 }}
|
| 392 |
+
transition={{ duration: 0.5, delay: 0.3 }}
|
| 393 |
+
className="lg:col-span-2 bg-white/5 border border-white/10 rounded-3xl p-6 backdrop-blur-md"
|
| 394 |
+
>
|
| 395 |
+
<div className="flex items-center gap-3 mb-6">
|
| 396 |
+
<div className="w-8 h-8 rounded-lg bg-indigo-500/20 flex items-center justify-center border border-indigo-500/30">
|
| 397 |
+
<Users className="w-4 h-4 text-indigo-400" />
|
| 398 |
</div>
|
| 399 |
+
<h3 className="text-lg font-bold text-white">Психотипы (DISC)</h3>
|
| 400 |
</div>
|
| 401 |
+
<div className="h-64">
|
| 402 |
+
<ResponsiveContainer width="100%" height="100%">
|
| 403 |
+
<PieChart>
|
| 404 |
+
<Pie
|
| 405 |
+
data={data.disc_distribution.map(disc => ({
|
| 406 |
+
...disc,
|
| 407 |
+
psychotype: PSYCHOTYPE_RUSSIAN[disc.psychotype] || disc.psychotype
|
| 408 |
+
})) as any}
|
| 409 |
+
cx="50%"
|
| 410 |
+
cy="50%"
|
| 411 |
+
innerRadius={60}
|
| 412 |
+
outerRadius={80}
|
| 413 |
+
paddingAngle={5}
|
| 414 |
+
dataKey="count"
|
| 415 |
+
stroke="none"
|
| 416 |
+
>
|
| 417 |
+
{data.disc_distribution.map((entry, index) => (
|
| 418 |
+
<Cell
|
| 419 |
+
key={`cell-${index}`}
|
| 420 |
+
fill={DISC_COLORS[entry.psychotype as keyof typeof DISC_COLORS] || DISC_COLORS['Unknown']}
|
| 421 |
+
/>
|
| 422 |
+
))}
|
| 423 |
+
</Pie>
|
| 424 |
+
<Tooltip
|
| 425 |
+
contentStyle={{
|
| 426 |
+
backgroundColor: '#0f172a',
|
| 427 |
+
border: '1px solid rgba(255,255,255,0.1)',
|
| 428 |
+
borderRadius: '12px',
|
| 429 |
+
color: '#fff'
|
| 430 |
+
}}
|
| 431 |
+
/>
|
| 432 |
+
<Legend
|
| 433 |
+
verticalAlign="middle"
|
| 434 |
+
align="right"
|
| 435 |
+
layout="vertical"
|
| 436 |
+
iconType="circle"
|
| 437 |
+
formatter={(value, entry: any) => {
|
| 438 |
+
const item = entry.payload
|
| 439 |
+
const russianName = PSYCHOTYPE_RUSSIAN[item.psychotype] || item.psychotype
|
| 440 |
+
return <span className="text-slate-300 ml-2">{russianName}</span>
|
| 441 |
+
}}
|
| 442 |
+
/>
|
| 443 |
+
</PieChart>
|
| 444 |
+
</ResponsiveContainer>
|
| 445 |
+
</div>
|
| 446 |
+
</motion.div>
|
| 447 |
+
|
| 448 |
+
{/* Lead Temperature */}
|
| 449 |
+
<motion.div
|
| 450 |
+
initial={{ opacity: 0, y: 20 }}
|
| 451 |
+
animate={{ opacity: 1, y: 0 }}
|
| 452 |
+
transition={{ duration: 0.5, delay: 0.4 }}
|
| 453 |
+
className="bg-white/5 border border-white/10 rounded-3xl p-6 backdrop-blur-md"
|
| 454 |
+
>
|
| 455 |
+
<h3 className="text-sm font-medium text-slate-500 uppercase tracking-wider mb-6">Температура Лидов</h3>
|
| 456 |
+
<div className="space-y-6">
|
| 457 |
+
{[
|
| 458 |
+
{ label: "Горячие", count: data.metrics.hot_leads, color: "red", icon: "🔥" },
|
| 459 |
+
{ label: "Тёплые", count: data.metrics.warm_leads, color: "orange", icon: "⚡" },
|
| 460 |
+
{ label: "Холодные", count: data.metrics.cold_leads, color: "blue", icon: "❄️" }
|
| 461 |
+
].map((item, i) => (
|
| 462 |
+
<div key={i}>
|
| 463 |
+
<div className="flex items-center justify-between mb-2">
|
| 464 |
+
<div className="flex items-center gap-2">
|
| 465 |
+
<span className="text-lg">{item.icon}</span>
|
| 466 |
+
<span className="text-slate-300 text-sm font-medium">{item.label}</span>
|
| 467 |
+
</div>
|
| 468 |
+
<span className={`text-xl font-bold text-${item.color}-400`}>{item.count}</span>
|
| 469 |
</div>
|
| 470 |
+
<div className="w-full bg-white/5 rounded-full h-1.5 overflow-hidden">
|
| 471 |
+
<motion.div
|
| 472 |
+
initial={{ width: 0 }}
|
| 473 |
+
animate={{ width: `${(item.count / data.metrics.total_leads * 100) || 0}%` }}
|
| 474 |
+
transition={{ duration: 1, delay: 0.5 + i * 0.1 }}
|
| 475 |
+
className={`bg-${item.color}-500 h-full rounded-full shadow-[0_0_10px_rgba(var(--${item.color}-500),0.5)]`}
|
| 476 |
/>
|
| 477 |
</div>
|
| 478 |
</div>
|
| 479 |
))}
|
| 480 |
</div>
|
| 481 |
+
</motion.div>
|
| 482 |
+
|
| 483 |
+
{/* Top Objections */}
|
| 484 |
+
<motion.div
|
| 485 |
+
initial={{ opacity: 0, y: 20 }}
|
| 486 |
+
animate={{ opacity: 1, y: 0 }}
|
| 487 |
+
transition={{ duration: 0.5, delay: 0.5 }}
|
| 488 |
+
className="bg-white/5 border border-white/10 rounded-3xl p-6 backdrop-blur-md"
|
| 489 |
+
>
|
| 490 |
+
<div className="flex items-center gap-3 mb-6">
|
| 491 |
+
<div className="w-8 h-8 rounded-lg bg-rose-500/20 flex items-center justify-center border border-rose-500/30">
|
| 492 |
+
<AlertCircle className="w-4 h-4 text-rose-400" />
|
| 493 |
+
</div>
|
| 494 |
+
<h3 className="text-lg font-bold text-white">Топ Возражений</h3>
|
| 495 |
+
</div>
|
| 496 |
|
| 497 |
+
{data.top_objections.length > 0 ? (
|
| 498 |
+
<div className="space-y-5">
|
| 499 |
+
{data.top_objections.slice(0, 5).map((objection, index) => (
|
| 500 |
+
<div key={index}>
|
| 501 |
+
<div className="flex items-center justify-between mb-2">
|
| 502 |
+
<p className="text-xs text-slate-300 font-medium truncate flex-1 pr-4">
|
| 503 |
+
{objection.objection}
|
| 504 |
+
</p>
|
| 505 |
+
<span className="text-xs font-bold text-white bg-white/10 px-2 py-0.5 rounded-full">
|
| 506 |
+
{objection.percentage.toFixed(0)}%
|
| 507 |
+
</span>
|
| 508 |
+
</div>
|
| 509 |
+
<div className="w-full bg-white/5 rounded-full h-1.5 overflow-hidden">
|
| 510 |
+
<motion.div
|
| 511 |
+
initial={{ width: 0 }}
|
| 512 |
+
animate={{ width: `${objection.percentage}%` }}
|
| 513 |
+
transition={{ duration: 1, delay: 0.6 + index * 0.1 }}
|
| 514 |
+
className="bg-gradient-to-r from-rose-500 to-pink-500 h-full rounded-full"
|
| 515 |
+
/>
|
| 516 |
+
</div>
|
| 517 |
+
</div>
|
| 518 |
+
))}
|
| 519 |
+
</div>
|
| 520 |
+
) : (
|
| 521 |
+
<div className="h-full flex flex-col items-center justify-center text-slate-500">
|
| 522 |
+
<p>Нет данных</p>
|
| 523 |
+
</div>
|
| 524 |
+
)}
|
| 525 |
+
</motion.div>
|
| 526 |
+
|
| 527 |
+
</div>
|
| 528 |
</div>
|
| 529 |
</div>
|
| 530 |
)
|