Spaces:
Running

axeronis commited on
Commit
6850fae
·
1 Parent(s): dc38b4e

feat(dashboard): Overhaul Dashboard with localized real data, new charts (Channels, Funnel, Objections), and visual refinements

Browse files
backend/app/api/analytics.py CHANGED
@@ -59,12 +59,19 @@ class LeadValueOverTime(BaseModel):
59
  count: int
60
 
61
 
 
 
 
 
 
 
62
  class DashboardResponse(BaseModel):
63
  metrics: DashboardMetrics
64
  funnel: List[FunnelStage]
65
  disc_distribution: List[DISCData]
66
  top_objections: List[ObjectionData]
67
  lead_value_over_time: List[LeadValueOverTime]
 
68
 
69
 
70
  # ============================================================================
@@ -147,6 +154,14 @@ async def get_dashboard_analytics(
147
  count=val.count
148
  )
149
  for val in dashboard_data.lead_value_over_time
 
 
 
 
 
 
 
 
150
  ]
151
  )
152
 
 
59
  count: int
60
 
61
 
62
+ class ChannelStats(BaseModel):
63
+ channel: str
64
+ count: int
65
+ percentage: float
66
+
67
+
68
  class DashboardResponse(BaseModel):
69
  metrics: DashboardMetrics
70
  funnel: List[FunnelStage]
71
  disc_distribution: List[DISCData]
72
  top_objections: List[ObjectionData]
73
  lead_value_over_time: List[LeadValueOverTime]
74
+ channel_stats: List[ChannelStats]
75
 
76
 
77
  # ============================================================================
 
154
  count=val.count
155
  )
156
  for val in dashboard_data.lead_value_over_time
157
+ ],
158
+ channel_stats=[
159
+ ChannelStats(
160
+ channel=ch.channel,
161
+ count=ch.count,
162
+ percentage=ch.percentage
163
+ )
164
+ for ch in dashboard_data.channel_stats
165
  ]
166
  )
167
 
backend/app/services/analytics_service.py CHANGED
@@ -92,6 +92,14 @@ class LeadValueOverTimeData:
92
  self.count = count
93
 
94
 
 
 
 
 
 
 
 
 
95
  class DashboardData:
96
  """Полные данные дашборда."""
97
  def __init__(
@@ -101,12 +109,23 @@ class DashboardData:
101
  disc_distribution: List[DISCDistributionData],
102
  top_objections: List[ObjectionData],
103
  lead_value_over_time: List[LeadValueOverTimeData]
 
 
 
 
 
 
 
 
 
 
104
  ):
105
  self.metrics = metrics
106
  self.funnel = funnel
107
  self.disc_distribution = disc_distribution
108
  self.top_objections = top_objections
109
  self.lead_value_over_time = lead_value_over_time
 
110
 
111
 
112
  # ============================================================================
@@ -202,12 +221,16 @@ class AnalyticsService:
202
  hot_leads=metrics.hot_leads
203
  )
204
 
 
 
 
205
  return DashboardData(
206
  metrics=metrics,
207
  funnel=funnel,
208
  disc_distribution=disc_distribution,
209
  top_objections=top_objections,
210
- lead_value_over_time=lead_value_over_time
 
211
  )
212
 
213
  # ========================================================================
@@ -557,6 +580,37 @@ class AnalyticsService:
557
  )
558
 
559
  return lead_value_over_time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
560
 
561
 
562
  # ============================================================================
 
92
  self.count = count
93
 
94
 
95
+ class ChannelStatsData:
96
+ """Статистика лидов по каналам."""
97
+ def __init__(self, channel: str, count: int, percentage: float):
98
+ self.channel = channel
99
+ self.count = count
100
+ self.percentage = percentage
101
+
102
+
103
  class DashboardData:
104
  """Полные данные дашборда."""
105
  def __init__(
 
109
  disc_distribution: List[DISCDistributionData],
110
  top_objections: List[ObjectionData],
111
  lead_value_over_time: List[LeadValueOverTimeData]
112
+ class DashboardData:
113
+ """Полные данные дашборда."""
114
+ def __init__(
115
+ self,
116
+ metrics: DashboardMetrics,
117
+ funnel: List[FunnelStageData],
118
+ disc_distribution: List[DISCDistributionData],
119
+ top_objections: List[ObjectionData],
120
+ lead_value_over_time: List[LeadValueOverTimeData],
121
+ channel_stats: List[ChannelStatsData] # NEW
122
  ):
123
  self.metrics = metrics
124
  self.funnel = funnel
125
  self.disc_distribution = disc_distribution
126
  self.top_objections = top_objections
127
  self.lead_value_over_time = lead_value_over_time
128
+ self.channel_stats = channel_stats
129
 
130
 
131
  # ============================================================================
 
221
  hot_leads=metrics.hot_leads
222
  )
223
 
224
+ # 12. Рассчитать статистику по каналам
225
+ channel_stats = self._calculate_channel_stats(leads)
226
+
227
  return DashboardData(
228
  metrics=metrics,
229
  funnel=funnel,
230
  disc_distribution=disc_distribution,
231
  top_objections=top_objections,
232
+ lead_value_over_time=lead_value_over_time,
233
+ channel_stats=channel_stats
234
  )
235
 
236
  # ========================================================================
 
580
  )
581
 
582
  return lead_value_over_time
583
+
584
+ def _calculate_channel_stats(self, leads: List[Lead]) -> List[ChannelStatsData]:
585
+ """Рассчитать распределение лидов по каналам (source)."""
586
+ total_leads = len(leads)
587
+ channel_counts = {}
588
+
589
+ for lead in leads:
590
+ source = lead.source if lead.source else "manual"
591
+ channel_counts[source] = channel_counts.get(source, 0) + 1
592
+
593
+ # Нормализация имен каналов для display
594
+ normalized_counts = {}
595
+ for source, count in channel_counts.items():
596
+ display_name = source.capitalize().replace('_', ' ')
597
+ if "whatsapp" in source.lower():
598
+ display_name = "WhatsApp"
599
+ elif "telegram" in source.lower():
600
+ display_name = "Telegram"
601
+ elif "instagram" in source.lower():
602
+ display_name = "Instagram"
603
+
604
+ normalized_counts[display_name] = normalized_counts.get(display_name, 0) + count
605
+
606
+ return [
607
+ ChannelStatsData(
608
+ channel=channel,
609
+ count=count,
610
+ percentage=(count / total_leads * 100) if total_leads > 0 else 0.0
611
+ )
612
+ for channel, count in normalized_counts.items()
613
+ ]
614
 
615
 
616
  # ============================================================================
frontend/app/dashboard/page.tsx CHANGED
@@ -55,38 +55,22 @@ interface LeadValueOverTime {
55
  count: number
56
  }
57
 
 
 
 
 
 
 
58
  interface DashboardData {
59
  metrics: DashboardMetrics
60
  funnel: FunnelStage[]
61
  disc_distribution: DISCData[]
62
  top_objections: ObjectionData[]
63
  lead_value_over_time: LeadValueOverTime[]
 
64
  }
65
 
66
- // DISC Colors (Neon / High Contrast)
67
- const DISC_COLORS = {
68
- 'Dominant': '#ef4444', // Red-500 Neon
69
- 'Influential': '#f59e0b', // Amber-500 Neon
70
- 'Steady': '#10b981', // Emerald-500 Neon
71
- 'Conscientious': '#3b82f6', // Blue-500 Neon
72
- 'Unknown': '#475569' // Slate-600
73
- }
74
-
75
- const PSYCHOTYPE_RUSSIAN: Record<string, string> = {
76
- 'Dominant': 'Доминант',
77
- 'Influential': 'Влияющий',
78
- 'Steady': 'Стабильный',
79
- 'Conscientious': 'Аналитик',
80
- 'Unknown': 'Неизвестно'
81
- }
82
-
83
- const STAGE_RUSSIAN: Record<string, string> = {
84
- 'New': 'Новый',
85
- 'Contacted': 'Контакт',
86
- 'Qualified': 'Квалиф.',
87
- 'Negotiation': 'Переговоры',
88
- 'Closed': 'Сделка'
89
- }
90
 
91
  export default function DashboardPage() {
92
  const { user, isLoading: authLoading } = useAuth()
@@ -116,7 +100,6 @@ export default function DashboardPage() {
116
  setError(null)
117
  const token = localStorage.getItem('auth_token')
118
 
119
- // Calculate dates
120
  let dateFrom = ''
121
  const today = new Date().toISOString().split('T')[0]
122
 
@@ -127,7 +110,6 @@ export default function DashboardPage() {
127
  dateFrom = date.toISOString().split('T')[0]
128
  }
129
 
130
- // Build Query
131
  const params = new URLSearchParams()
132
  if (dateFrom) params.append('date_from', dateFrom)
133
  params.append('date_to', today)
@@ -155,65 +137,20 @@ export default function DashboardPage() {
155
 
156
  useEffect(() => {
157
  if (authLoading) return
158
-
159
  if (!user) {
160
  setError('Нет авторизации')
161
  setLoading(false)
162
  return
163
  }
164
-
165
  fetchAnalytics()
166
  }, [user, authLoading, dateRange])
167
 
168
- // Custom Tooltip Component (Dark Mode)
169
- const CustomTooltip = ({ active, payload, label }: any) => {
170
- if (active && payload && payload.length) {
171
- return (
172
- <div className="bg-[#0f1117] p-3 rounded-lg border border-slate-700 shadow-2xl z-50">
173
- <p className="text-xs font-mono text-slate-400 mb-2">{label}</p>
174
- {payload.map((entry: any, index: number) => (
175
- <div key={index} className="flex items-center gap-2 text-xs font-mono">
176
- <div
177
- className="w-1.5 h-1.5 rounded-full"
178
- style={{ backgroundColor: entry.color }}
179
- />
180
- <span className="text-slate-300">{entry.name}:</span>
181
- <span className="font-bold text-white">
182
- {typeof entry.value === 'number'
183
- ? entry.name.includes('Value') || entry.name.includes('Пайплайн')
184
- ? `$${entry.value.toLocaleString()}`
185
- : entry.value
186
- : entry.value}
187
- </span>
188
- </div>
189
- ))}
190
- </div>
191
- )
192
- }
193
- return null
194
- }
195
-
196
- // Percent Change Component (Neon Style)
197
- const PercentChange = ({ value }: { value: number }) => {
198
- if (value === 0) return <span className="text-slate-500 text-[10px] font-mono">0%</span>
199
- const isPositive = value > 0
200
- return (
201
- <span className={cn(
202
- "flex items-center gap-1 text-[10px] font-bold px-1.5 py-0.5 rounded border font-mono",
203
- isPositive ? "text-emerald-400 border-emerald-500/30 bg-emerald-500/10" : "text-rose-400 border-rose-500/30 bg-rose-500/10"
204
- )}>
205
- {isPositive ? <ArrowUp className="w-3 h-3" /> : <ArrowDown className="w-3 h-3" />}
206
- {Math.abs(value)}%
207
- </span>
208
- )
209
- }
210
-
211
  if (authLoading || (loading && !data)) {
212
  return (
213
  <div className="flex items-center justify-center min-h-screen bg-[#030014]">
214
  <div className="flex flex-col items-center gap-4">
215
  <div className="w-8 h-8 rounded-full border-2 border-indigo-500 border-t-transparent animate-spin"></div>
216
- <p className="text-indigo-400 font-mono text-xs animate-pulse">ЗАГРУЗКА ПАНЕЛИ...</p>
217
  </div>
218
  </div>
219
  )
@@ -248,11 +185,9 @@ export default function DashboardPage() {
248
  <div className="flex flex-col md:flex-row md:items-center justify-between gap-4 border-b border-white/5 pb-6">
249
  <div>
250
  <h1 className="text-2xl font-black text-white tracking-wider flex items-center gap-3">
251
- ПАНЕЛЬ УПРАВЛЕНИЯ <span className="px-2 py-0.5 rounded bg-indigo-500/20 text-indigo-400 text-[10px] font-mono border border-indigo-500/30">LIVE</span>
252
  </h1>
253
- <div className="flex items-center gap-2 mt-1">
254
- <p className="text-slate-500 text-xs font-mono">Метрики и статус ИИ</p>
255
- </div>
256
  </div>
257
  <div className="flex items-center gap-3">
258
  {/* Date Filter Dropdown */}
@@ -306,14 +241,14 @@ export default function DashboardPage() {
306
  <button
307
  onClick={fetchAnalytics}
308
  className="p-2 bg-[#0f1117] border border-white/10 rounded-lg hover:border-indigo-500/50 text-slate-400 transition-colors hover:rotate-180 duration-500"
309
- title="Sync Data"
310
  >
311
  <RefreshCw className="w-4 h-4" />
312
  </button>
313
  </div>
314
  </div>
315
 
316
- {/* Key Metrics Grid - Reference Design */}
317
  <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
318
  {/* Total Leads */}
319
  <div className="group relative bg-[#12131F] rounded-2xl border border-white/10 p-6 transition-all hover:border-indigo-500/30 hover:shadow-[0_0_30px_-5px_rgba(99,102,241,0.15)]">
@@ -322,77 +257,165 @@ export default function DashboardPage() {
322
  <div className="h-12 w-12 rounded-xl bg-purple-500/10 border border-purple-500/20 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300">
323
  <Users className="w-6 h-6 text-purple-400" />
324
  </div>
325
- <p className="text-xs font-bold text-slate-500 uppercase tracking-wider mb-1">TOTAL LEADS</p>
326
  <p className="text-3xl font-bold text-white tracking-tight">{data.metrics.total_leads}</p>
327
  </div>
328
  </div>
329
 
330
- {/* Pipeline Value */}
331
  <div className="group relative bg-[#12131F] rounded-2xl border border-white/10 p-6 transition-all hover:border-indigo-500/30 hover:shadow-[0_0_30px_-5px_rgba(99,102,241,0.15)]">
332
  <div className="absolute inset-0 bg-gradient-to-br from-indigo-500/0 via-purple-500/0 to-pink-500/0 group-hover:from-indigo-500/5 group-hover:via-purple-500/5 group-hover:to-pink-500/5 rounded-2xl transition-all duration-500" />
333
  <div className="relative">
334
  <div className="h-12 w-12 rounded-xl bg-indigo-500/10 border border-indigo-500/20 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300">
335
- <TrendingUp className="w-6 h-6 text-indigo-400" />
336
  </div>
337
- <p className="text-xs font-bold text-slate-500 uppercase tracking-wider mb-1">PIPELINE VALUE</p>
338
- <p className="text-3xl font-bold text-white tracking-tight">${data.metrics.pipeline_value.toLocaleString()}</p>
339
  </div>
340
  </div>
341
 
342
- {/* Conversion Rate */}
343
  <div className="group relative bg-[#12131F] rounded-2xl border border-white/10 p-6 transition-all hover:border-indigo-500/30 hover:shadow-[0_0_30px_-5px_rgba(99,102,241,0.15)]">
344
  <div className="absolute inset-0 bg-gradient-to-br from-indigo-500/0 via-purple-500/0 to-pink-500/0 group-hover:from-indigo-500/5 group-hover:via-purple-500/5 group-hover:to-pink-500/5 rounded-2xl transition-all duration-500" />
345
  <div className="relative">
346
  <div className="h-12 w-12 rounded-xl bg-pink-500/10 border border-pink-500/20 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300">
347
- <Activity className="w-6 h-6 text-pink-400" />
348
  </div>
349
- <p className="text-xs font-bold text-slate-500 uppercase tracking-wider mb-1">CONVERSION RATE</p>
350
  <p className="text-3xl font-bold text-white tracking-tight">{data.metrics.conversion_rate}%</p>
351
  </div>
352
  </div>
353
 
354
- {/* Active Users */}
355
  <div className="group relative bg-[#12131F] rounded-2xl border border-white/10 p-6 transition-all hover:border-indigo-500/30 hover:shadow-[0_0_30px_-5px_rgba(99,102,241,0.15)]">
356
  <div className="absolute inset-0 bg-gradient-to-br from-indigo-500/0 via-purple-500/0 to-pink-500/0 group-hover:from-indigo-500/5 group-hover:via-purple-500/5 group-hover:to-pink-500/5 rounded-2xl transition-all duration-500" />
357
  <div className="relative">
358
- <div className="flex justify-between items-start mb-4">
359
- <div className="h-12 w-12 rounded-xl bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center group-hover:scale-110 transition-transform duration-300">
360
- <Users className="w-6 h-6 text-emerald-400" />
361
- </div>
362
- <div className="px-2 py-1 rounded-full bg-emerald-500/10 border border-emerald-500/20 flex items-center gap-1.5">
363
- <div className="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse" />
364
- <span className="text-[10px] font-bold text-emerald-400">ОНЛАЙН</span>
365
- </div>
366
  </div>
367
- <p className="text-xs font-bold text-slate-500 uppercase tracking-wider mb-1">ACTIVE USERS</p>
368
- <p className="text-3xl font-bold text-white tracking-tight">{data.metrics.active_leads_24h}</p>
369
  </div>
370
  </div>
371
  </div>
372
 
373
 
374
- {/* Charts Section - Reference Design */}
375
  <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
376
 
377
- {/* Pipeline Dynamics Chart */}
378
- <div className="lg:col-span-2 bg-[#12131F] rounded-2xl border border-white/10 p-6 relative overflow-hidden group">
379
- {/* Subtle aurora background */}
380
- <div className="absolute top-0 right-0 w-64 h-64 bg-purple-500/5 blur-3xl rounded-full" />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
 
382
- <div className="flex items-center justify-between mb-8 relative z-10">
383
- <h3 className="text-sm font-bold text-slate-400 uppercase tracking-wider">PIPELINE DYNAMICS</h3>
384
- <div className="flex bg-white/5 rounded-lg p-0.5 border border-white/5">
385
- <button className="px-3 py-1 text-xs font-medium text-white bg-white/10 rounded-md shadow-sm">Money</button>
386
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  </div>
 
388
 
 
 
 
389
  <div className="h-[300px] w-full relative z-10">
390
  <ResponsiveContainer width="100%" height="100%">
391
  <AreaChart data={data.lead_value_over_time}>
392
  <defs>
393
  <linearGradient id="colorValue" x1="0" y1="0" x2="0" y2="1">
394
- <stop offset="5%" stopColor="#8b5cf6" stopOpacity={0.3} />
395
- <stop offset="95%" stopColor="#8b5cf6" stopOpacity={0} />
396
  </linearGradient>
397
  </defs>
398
  <CartesianGrid strokeDasharray="3 3" stroke="rgba(255,255,255,0.05)" vertical={false} />
@@ -400,7 +423,7 @@ export default function DashboardPage() {
400
  dataKey="date"
401
  stroke="#475569"
402
  tick={{ fill: '#475569', fontSize: 10 }}
403
- tickFormatter={(value) => new Date(value).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}
404
  axisLine={false}
405
  tickLine={false}
406
  />
@@ -411,14 +434,13 @@ export default function DashboardPage() {
411
  tickLine={false}
412
  />
413
  <Tooltip
414
- contentStyle={{ backgroundColor: '#0F111A', border: '1px solid rgba(255,255,255,0.1)', borderRadius: '12px', boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1)' }}
415
- itemStyle={{ color: '#fff', fontSize: '12px' }}
416
- labelStyle={{ color: '#94a3b8', fontSize: '10px', marginBottom: '4px' }}
417
  />
418
  <Area
419
  type="monotone"
420
  dataKey="value"
421
- stroke="#8b5cf6"
422
  strokeWidth={3}
423
  fillOpacity={1}
424
  fill="url(#colorValue)"
@@ -427,41 +449,8 @@ export default function DashboardPage() {
427
  </ResponsiveContainer>
428
  </div>
429
  </div>
430
-
431
- {/* High Intent Leads Widget */}
432
- <div className="bg-[#12131F] rounded-2xl border border-white/10 p-6 relative overflow-hidden flex flex-col">
433
- <div className="flex items-center justify-between mb-6">
434
- <h3 className="text-sm font-bold text-slate-400 uppercase tracking-wider">HIGH INTENT LEADS</h3>
435
- <button className="text-slate-500 hover:text-white transition-colors">
436
- <div className="flex gap-0.5">
437
- <div className="w-1 h-1 rounded-full bg-slate-500" />
438
- <div className="w-1 h-1 rounded-full bg-slate-500" />
439
- <div className="w-1 h-1 rounded-full bg-slate-500" />
440
- </div>
441
- </button>
442
- </div>
443
-
444
- <div className="flex-1 overflow-y-auto space-y-3 pr-2 scrollbar-thin scrollbar-thumb-white/10">
445
- {[1, 2, 3, 4].map((i) => (
446
- <div key={i} className="group p-3 rounded-xl bg-white/5 border border-white/5 hover:bg-white/10 transition-all flex items-center gap-3">
447
- <div className="w-10 h-10 rounded-full bg-slate-800 flex items-center justify-center text-slate-400 font-bold text-xs border border-white/10">
448
- {['LN', 'VA', 'NM', 'EM'][i - 1]}
449
- </div>
450
- <div className="flex-1 min-w-0">
451
- <h4 className="text-sm font-bold text-white truncate">{['Lead Name', 'Veronika A.', 'Nimax Corp', 'Emiax Ltd'][i - 1]}</h4>
452
- <p className="text-[10px] text-slate-500 truncate">Contact info unavailable</p>
453
- </div>
454
- <div className="flex flex-col items-end gap-1">
455
- <span className="text-[10px] text-slate-500">Last activity</span>
456
- <div className="px-2 py-0.5 rounded-full bg-purple-500/10 border border-purple-500/20 text-[10px] font-bold text-purple-400 shadow-[0_0_10px_-3px_rgba(168,85,247,0.3)]">
457
- 95%
458
- </div>
459
- </div>
460
- </div>
461
- ))}
462
- </div>
463
- </div>
464
  </div>
 
465
  </div>
466
  </div>
467
  )
 
55
  count: number
56
  }
57
 
58
+ interface ChannelStats {
59
+ channel: string
60
+ count: number
61
+ percentage: number
62
+ }
63
+
64
  interface DashboardData {
65
  metrics: DashboardMetrics
66
  funnel: FunnelStage[]
67
  disc_distribution: DISCData[]
68
  top_objections: ObjectionData[]
69
  lead_value_over_time: LeadValueOverTime[]
70
+ channel_stats: ChannelStats[]
71
  }
72
 
73
+ const COLORS = ['#6366f1', '#8b5cf6', '#ec4899', '#f43f5e', '#10b981', '#06b6d4', '#3b82f6', '#818cf8'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  export default function DashboardPage() {
76
  const { user, isLoading: authLoading } = useAuth()
 
100
  setError(null)
101
  const token = localStorage.getItem('auth_token')
102
 
 
103
  let dateFrom = ''
104
  const today = new Date().toISOString().split('T')[0]
105
 
 
110
  dateFrom = date.toISOString().split('T')[0]
111
  }
112
 
 
113
  const params = new URLSearchParams()
114
  if (dateFrom) params.append('date_from', dateFrom)
115
  params.append('date_to', today)
 
137
 
138
  useEffect(() => {
139
  if (authLoading) return
 
140
  if (!user) {
141
  setError('Нет авторизации')
142
  setLoading(false)
143
  return
144
  }
 
145
  fetchAnalytics()
146
  }, [user, authLoading, dateRange])
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  if (authLoading || (loading && !data)) {
149
  return (
150
  <div className="flex items-center justify-center min-h-screen bg-[#030014]">
151
  <div className="flex flex-col items-center gap-4">
152
  <div className="w-8 h-8 rounded-full border-2 border-indigo-500 border-t-transparent animate-spin"></div>
153
+ <p className="text-indigo-400 font-mono text-xs animate-pulse">ЗАГРУЗКА АНАЛИТИКИ...</p>
154
  </div>
155
  </div>
156
  )
 
185
  <div className="flex flex-col md:flex-row md:items-center justify-between gap-4 border-b border-white/5 pb-6">
186
  <div>
187
  <h1 className="text-2xl font-black text-white tracking-wider flex items-center gap-3">
188
+ АНАЛИТИКА
189
  </h1>
190
+ {/* Subtitle removed as requested */}
 
 
191
  </div>
192
  <div className="flex items-center gap-3">
193
  {/* Date Filter Dropdown */}
 
241
  <button
242
  onClick={fetchAnalytics}
243
  className="p-2 bg-[#0f1117] border border-white/10 rounded-lg hover:border-indigo-500/50 text-slate-400 transition-colors hover:rotate-180 duration-500"
244
+ title="Обновить"
245
  >
246
  <RefreshCw className="w-4 h-4" />
247
  </button>
248
  </div>
249
  </div>
250
 
251
+ {/* Key Metrics Grid */}
252
  <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
253
  {/* Total Leads */}
254
  <div className="group relative bg-[#12131F] rounded-2xl border border-white/10 p-6 transition-all hover:border-indigo-500/30 hover:shadow-[0_0_30px_-5px_rgba(99,102,241,0.15)]">
 
257
  <div className="h-12 w-12 rounded-xl bg-purple-500/10 border border-purple-500/20 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300">
258
  <Users className="w-6 h-6 text-purple-400" />
259
  </div>
260
+ <p className="text-xs font-bold text-slate-500 uppercase tracking-wider mb-1">ВСЕГО ЛИДОВ</p>
261
  <p className="text-3xl font-bold text-white tracking-tight">{data.metrics.total_leads}</p>
262
  </div>
263
  </div>
264
 
265
+ {/* Average Response Time */}
266
  <div className="group relative bg-[#12131F] rounded-2xl border border-white/10 p-6 transition-all hover:border-indigo-500/30 hover:shadow-[0_0_30px_-5px_rgba(99,102,241,0.15)]">
267
  <div className="absolute inset-0 bg-gradient-to-br from-indigo-500/0 via-purple-500/0 to-pink-500/0 group-hover:from-indigo-500/5 group-hover:via-purple-500/5 group-hover:to-pink-500/5 rounded-2xl transition-all duration-500" />
268
  <div className="relative">
269
  <div className="h-12 w-12 rounded-xl bg-indigo-500/10 border border-indigo-500/20 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300">
270
+ <Clock className="w-6 h-6 text-indigo-400" />
271
  </div>
272
+ <p className="text-xs font-bold text-slate-500 uppercase tracking-wider mb-1">СРЕДНЕЕ ВРЕМЯ ОТВЕТА</p>
273
+ <p className="text-3xl font-bold text-white tracking-tight">{data.metrics.avg_response_time_seconds.toFixed(0)} <span className="text-sm font-medium text-slate-500">сек</span></p>
274
  </div>
275
  </div>
276
 
277
+ {/* Conversion */}
278
  <div className="group relative bg-[#12131F] rounded-2xl border border-white/10 p-6 transition-all hover:border-indigo-500/30 hover:shadow-[0_0_30px_-5px_rgba(99,102,241,0.15)]">
279
  <div className="absolute inset-0 bg-gradient-to-br from-indigo-500/0 via-purple-500/0 to-pink-500/0 group-hover:from-indigo-500/5 group-hover:via-purple-500/5 group-hover:to-pink-500/5 rounded-2xl transition-all duration-500" />
280
  <div className="relative">
281
  <div className="h-12 w-12 rounded-xl bg-pink-500/10 border border-pink-500/20 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300">
282
+ <Target className="w-6 h-6 text-pink-400" />
283
  </div>
284
+ <p className="text-xs font-bold text-slate-500 uppercase tracking-wider mb-1">КОНВЕРСИЯ</p>
285
  <p className="text-3xl font-bold text-white tracking-tight">{data.metrics.conversion_rate}%</p>
286
  </div>
287
  </div>
288
 
289
+ {/* Pipeline Value */}
290
  <div className="group relative bg-[#12131F] rounded-2xl border border-white/10 p-6 transition-all hover:border-indigo-500/30 hover:shadow-[0_0_30px_-5px_rgba(99,102,241,0.15)]">
291
  <div className="absolute inset-0 bg-gradient-to-br from-indigo-500/0 via-purple-500/0 to-pink-500/0 group-hover:from-indigo-500/5 group-hover:via-purple-500/5 group-hover:to-pink-500/5 rounded-2xl transition-all duration-500" />
292
  <div className="relative">
293
+ <div className="h-12 w-12 rounded-xl bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300">
294
+ <DollarSign className="w-6 h-6 text-emerald-400" />
 
 
 
 
 
 
295
  </div>
296
+ <p className="text-xs font-bold text-slate-500 uppercase tracking-wider mb-1">ОБЪЁМ ПАЙПЛАЙНА</p>
297
+ <p className="text-3xl font-bold text-white tracking-tight">${data.metrics.pipeline_value.toLocaleString()}</p>
298
  </div>
299
  </div>
300
  </div>
301
 
302
 
303
+ {/* Row 2: Charts Area */}
304
  <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
305
 
306
+ {/* Leads by Channel (Donut Chart) */}
307
+ <div className="bg-[#12131F] rounded-2xl border border-white/10 p-6 relative overflow-hidden flex flex-col">
308
+ <h3 className="text-sm font-bold text-slate-400 uppercase tracking-wider mb-6">ИСТОЧНИКИ ЛИДОВ</h3>
309
+ <div className="h-[250px] w-full relative z-10 flex items-center justify-center">
310
+ {data.channel_stats && data.channel_stats.length > 0 ? (
311
+ <ResponsiveContainer width="100%" height="100%">
312
+ <PieChart>
313
+ <Pie
314
+ data={data.channel_stats}
315
+ cx="50%"
316
+ cy="50%"
317
+ innerRadius={60}
318
+ outerRadius={80}
319
+ paddingAngle={5}
320
+ dataKey="count"
321
+ >
322
+ {data.channel_stats.map((entry, index) => (
323
+ <Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} stroke="rgba(0,0,0,0.2)" />
324
+ ))}
325
+ </Pie>
326
+ <Tooltip
327
+ contentStyle={{ backgroundColor: '#0F111A', border: '1px solid rgba(255,255,255,0.1)', borderRadius: '12px' }}
328
+ itemStyle={{ color: '#fff' }}
329
+ />
330
+ <Legend
331
+ layout="vertical"
332
+ verticalAlign="middle"
333
+ align="right"
334
+ wrapperStyle={{ fontSize: '10px', color: '#94a3b8' }}
335
+ />
336
+ </PieChart>
337
+ </ResponsiveContainer>
338
+ ) : (
339
+ <div className="text-slate-500 text-sm">Нет данных по каналам</div>
340
+ )}
341
+ </div>
342
+ </div>
343
+
344
+ {/* Funnel Drop-off (Bar Chart) */}
345
+ <div className="lg:col-span-2 bg-[#12131F] rounded-2xl border border-white/10 p-6 relative overflow-hidden">
346
+ <h3 className="text-sm font-bold text-slate-400 uppercase tracking-wider mb-6">ВОРОНКА ПРОДАЖ (ОТТОК КЛИЕНТОВ)</h3>
347
+ <div className="h-[250px] w-full relative z-10">
348
+ <ResponsiveContainer width="100%" height="100%">
349
+ <BarChart
350
+ data={data.funnel}
351
+ layout="vertical"
352
+ margin={{ top: 5, right: 30, left: 40, bottom: 5 }}
353
+ >
354
+ <CartesianGrid strokeDasharray="3 3" stroke="rgba(255,255,255,0.05)" horizontal={false} />
355
+ <XAxis type="number" stroke="#475569" tick={{ fill: '#475569', fontSize: 10 }} />
356
+ <YAxis type="category" dataKey="stage" stroke="#94a3b8" tick={{ fill: '#94a3b8', fontSize: 11 }} width={100} />
357
+ <Tooltip
358
+ cursor={{ fill: 'rgba(255,255,255,0.05)' }}
359
+ contentStyle={{ backgroundColor: '#0F111A', border: '1px solid rgba(255,255,255,0.1)', borderRadius: '12px' }}
360
+ itemStyle={{ color: '#fff' }}
361
+ />
362
+ <Bar dataKey="count" name="Кол-во" fill="#8b5cf6" radius={[0, 4, 4, 0]}>
363
+ {data.funnel.map((entry, index) => (
364
+ <Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
365
+ ))}
366
+ </Bar>
367
+ </BarChart>
368
+ </ResponsiveContainer>
369
+ </div>
370
+ </div>
371
+ </div>
372
 
373
+ {/* Row 3: Objections & Leads Value */}
374
+ <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
375
+
376
+ {/* Frequent Objections (List) */}
377
+ <div className="bg-[#12131F] rounded-2xl border border-white/10 p-6 relative overflow-hidden">
378
+ <h3 className="text-sm font-bold text-slate-400 uppercase tracking-wider mb-6 flex items-center gap-2">
379
+ <AlertCircle className="w-4 h-4 text-red-400" />
380
+ ЧАСТЫЕ ВОЗРАЖЕНИЯ
381
+ </h3>
382
+ <div className="space-y-4">
383
+ {data.top_objections && data.top_objections.length > 0 ? (
384
+ data.top_objections.map((obj, i) => (
385
+ <div key={i} className="flex items-center justify-between group">
386
+ <div className="flex-1 min-w-0 mr-4">
387
+ <p className="text-sm text-slate-300 font-medium truncate group-hover:text-white transition-colors">
388
+ {obj.objection}
389
+ </p>
390
+ <div className="w-full bg-white/5 rounded-full h-1.5 mt-2">
391
+ <div
392
+ className="bg-red-500 h-1.5 rounded-full"
393
+ style={{ width: `${obj.percentage}%` }}
394
+ />
395
+ </div>
396
+ </div>
397
+ <div className="text-right">
398
+ <span className="text-xs font-bold text-white">{obj.count}</span>
399
+ <p className="text-[10px] text-slate-500">{obj.percentage.toFixed(0)}%</p>
400
+ </div>
401
+ </div>
402
+ ))
403
+ ) : (
404
+ <div className="text-center text-slate-500 text-sm py-4">Нет данных о возражениях</div>
405
+ )}
406
  </div>
407
+ </div>
408
 
409
+ {/* Pipeline Dynamics (Area Chart) reused */}
410
+ <div className="lg:col-span-2 bg-[#12131F] rounded-2xl border border-white/10 p-6 relative overflow-hidden">
411
+ <h3 className="text-sm font-bold text-slate-400 uppercase tracking-wider mb-6">ДИНАМИКА ЦЕННОСТИ ЛИДОВ (30 ДНЕЙ)</h3>
412
  <div className="h-[300px] w-full relative z-10">
413
  <ResponsiveContainer width="100%" height="100%">
414
  <AreaChart data={data.lead_value_over_time}>
415
  <defs>
416
  <linearGradient id="colorValue" x1="0" y1="0" x2="0" y2="1">
417
+ <stop offset="5%" stopColor="#ec4899" stopOpacity={0.3} />
418
+ <stop offset="95%" stopColor="#ec4899" stopOpacity={0} />
419
  </linearGradient>
420
  </defs>
421
  <CartesianGrid strokeDasharray="3 3" stroke="rgba(255,255,255,0.05)" vertical={false} />
 
423
  dataKey="date"
424
  stroke="#475569"
425
  tick={{ fill: '#475569', fontSize: 10 }}
426
+ tickFormatter={(value) => new Date(value).toLocaleDateString('ru-RU', { month: 'short', day: 'numeric' })}
427
  axisLine={false}
428
  tickLine={false}
429
  />
 
434
  tickLine={false}
435
  />
436
  <Tooltip
437
+ contentStyle={{ backgroundColor: '#0F111A', border: '1px solid rgba(255,255,255,0.1)', borderRadius: '12px' }}
438
+ itemStyle={{ color: '#fff' }}
 
439
  />
440
  <Area
441
  type="monotone"
442
  dataKey="value"
443
+ stroke="#ec4899"
444
  strokeWidth={3}
445
  fillOpacity={1}
446
  fill="url(#colorValue)"
 
449
  </ResponsiveContainer>
450
  </div>
451
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452
  </div>
453
+
454
  </div>
455
  </div>
456
  )
frontend/components/Header.tsx CHANGED
@@ -44,18 +44,18 @@ export function Header() {
44
  </button> */}
45
 
46
  {/* User Profile */}
47
- <div className="flex items-center gap-3 pl-4 border-l border-white/10">
48
  <div className="flex flex-col items-end mr-2 hidden md:flex">
49
  <span className="text-sm font-bold text-white leading-none">
50
  {user?.full_name || 'User'}
51
  </span>
52
- <span className="text-[10px] text-slate-500 font-mono mt-1">
53
  {user?.role === 'admin' ? 'ADMINISTRATOR' : user?.email}
54
  </span>
55
  </div>
56
 
57
  <div className={cn(
58
- "w-9 h-9 rounded-lg flex items-center justify-center text-white font-bold text-xs shadow-lg border border-white/10 ring-2 ring-white/5",
59
  getAvatarColor(user?.email)
60
  )}>
61
  {getInitials(user?.full_name, user?.email)}
@@ -63,10 +63,10 @@ export function Header() {
63
 
64
  <button
65
  onClick={() => logout()}
66
- className="p-2 text-slate-500 hover:text-red-400 hover:bg-red-500/10 rounded-lg transition-colors ml-1"
67
  title="Выйти"
68
  >
69
- <LogOut className="w-4 h-4" />
70
  </button>
71
  </div>
72
  </div>
 
44
  </button> */}
45
 
46
  {/* User Profile */}
47
+ <div className="flex items-center gap-4 pl-6 border-l border-white/10 h-10">
48
  <div className="flex flex-col items-end mr-2 hidden md:flex">
49
  <span className="text-sm font-bold text-white leading-none">
50
  {user?.full_name || 'User'}
51
  </span>
52
+ <span className="text-[11px] text-slate-500 font-mono mt-1.5">
53
  {user?.role === 'admin' ? 'ADMINISTRATOR' : user?.email}
54
  </span>
55
  </div>
56
 
57
  <div className={cn(
58
+ "w-10 h-10 rounded-xl flex items-center justify-center text-white font-bold text-sm shadow-lg border border-white/10 ring-2 ring-white/5",
59
  getAvatarColor(user?.email)
60
  )}>
61
  {getInitials(user?.full_name, user?.email)}
 
63
 
64
  <button
65
  onClick={() => logout()}
66
+ className="p-2.5 text-slate-500 hover:text-red-400 hover:bg-red-500/10 rounded-xl transition-colors ml-2"
67
  title="Выйти"
68
  >
69
+ <LogOut className="w-5 h-5" />
70
  </button>
71
  </div>
72
  </div>
frontend/components/Sidebar.tsx CHANGED
@@ -82,10 +82,10 @@ export function Sidebar() {
82
  {/* Logo Section */}
83
  <div className="p-6 border-b border-white/10 relative z-50">
84
  <Link href="/dashboard" className="flex items-center gap-3 group">
85
- <div className="w-8 h-8 flex items-center justify-center">
86
  <img src="/logo-v2.png" alt="MicroFunnel Logo" className="w-full h-full object-contain" />
87
  </div>
88
- <h1 className="text-lg font-black text-white tracking-widest group-hover:text-indigo-400 transition-colors uppercase">
89
  MicroFunnel
90
  </h1>
91
  </Link>
 
82
  {/* Logo Section */}
83
  <div className="p-6 border-b border-white/10 relative z-50">
84
  <Link href="/dashboard" className="flex items-center gap-3 group">
85
+ <div className="w-12 h-12 flex items-center justify-center">
86
  <img src="/logo-v2.png" alt="MicroFunnel Logo" className="w-full h-full object-contain" />
87
  </div>
88
+ <h1 className="text-xl font-black text-white tracking-widest group-hover:text-indigo-400 transition-colors uppercase">
89
  MicroFunnel
90
  </h1>
91
  </Link>