Spaces:
Running
Running
Download frontend/components/admin/AnalyticsTab.tsx from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 8.05 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/frontend/components/admin/AnalyticsTab.tsx
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/frontend/components/admin/AnalyticsTab.tsx
-
curl -L -o AnalyticsTab.tsx https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/frontend/components/admin/AnalyticsTab.tsx
8.05 kB
| import { useState, useEffect } from 'react' | |
| import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, LineChart, Line, CartesianGrid, AreaChart, Area } from 'recharts' | |
| import { Activity, DollarSign, Users, TrendingUp } from 'lucide-react' | |
| export default function AnalyticsTab() { | |
| const [revenueData, setRevenueData] = useState<any>(null) | |
| const [growthData, setGrowthData] = useState<any[]>([]) | |
| const [aiPulse, setAiPulse] = useState<any>(null) | |
| const [loading, setLoading] = useState(true) | |
| useEffect(() => { | |
| loadData() | |
| }, []) | |
| const loadData = async () => { | |
| try { | |
| const token = localStorage.getItem('auth_token') | |
| const headers = { 'Authorization': 'Bearer ' + token } | |
| const [revRes, growthRes, pulseRes] = await Promise.all([ | |
| fetch('/api/v1/admin/analytics/revenue', { headers }), | |
| fetch('/api/v1/admin/analytics/growth', { headers }), | |
| fetch('/api/v1/analytics/admin/ai-pulse', { headers }) | |
| ]) | |
| if (revRes.ok) setRevenueData(await revRes.json()) | |
| if (growthRes.ok) setGrowthData(await growthRes.json()) | |
| if (pulseRes.ok) setAiPulse(await pulseRes.json()) | |
| } catch (error) { | |
| console.error('Analytics load error', error) | |
| } finally { | |
| setLoading(false) | |
| } | |
| } | |
| if (loading) return ( | |
| <div className="p-8 text-center text-slate-400"> | |
| <div className="animate-pulse">Загрузка аналитики...</div> | |
| </div> | |
| ) | |
| return ( | |
| <div className="space-y-6"> | |
| {/* Info Card - Aurora Style */} | |
| <div className="bg-gradient-to-r from-indigo-500/10 to-purple-500/10 border border-indigo-500/20 p-4 rounded-xl flex items-start gap-3"> | |
| <div className="p-2 bg-indigo-500/20 rounded-lg text-indigo-400"> | |
| <TrendingUp className="w-5 h-5" /> | |
| </div> | |
| <div> | |
| <h3 className="font-bold text-white text-sm">Аналитика и Доходы</h3> | |
| <p className="text-xs text-slate-400 mt-1 leading-relaxed"> | |
| Обзор ключевых метрик платформы: рост пользователей и финансовые показатели (MRR). | |
| Данные обновляются в реальном времени на основе активных подписок. | |
| </p> | |
| </div> | |
| </div> | |
| {/* AI Pulse Row (NEW) */} | |
| <div className="grid grid-cols-1 md:grid-cols-4 gap-4"> | |
| <div className="bg-slate-900/50 backdrop-blur-sm p-4 rounded-xl border border-indigo-500/20"> | |
| <p className="text-[10px] text-slate-500 font-bold uppercase mb-1">Global Tokens (24h)</p> | |
| <p className="text-xl font-mono font-bold text-white">{(aiPulse?.total_tokens_24h || 0).toLocaleString()}</p> | |
| </div> | |
| <div className="bg-slate-900/50 backdrop-blur-sm p-4 rounded-xl border border-emerald-500/20"> | |
| <p className="text-[10px] text-slate-500 font-bold uppercase mb-1">Global AI Cost</p> | |
| <p className="text-xl font-mono font-bold text-emerald-400">${(aiPulse?.total_cost_usd || 0).toFixed(2)}</p> | |
| </div> | |
| <div className="bg-slate-900/50 backdrop-blur-sm p-4 rounded-xl border border-purple-500/20"> | |
| <p className="text-[10px] text-slate-500 font-bold uppercase mb-1">Active Convs (1h)</p> | |
| <p className="text-xl font-mono font-bold text-purple-400">{aiPulse?.active_conversations_1h || 0}</p> | |
| </div> | |
| <div className="bg-slate-900/50 backdrop-blur-sm p-4 rounded-xl border border-red-500/20"> | |
| <p className="text-[10px] text-slate-500 font-bold uppercase mb-1">Spam Alerts (24h)</p> | |
| <p className="text-xl font-mono font-bold text-red-400">{aiPulse?.spam_alerts_24h || 0}</p> | |
| </div> | |
| </div> | |
| <div className="grid grid-cols-1 md:grid-cols-2 gap-6"> | |
| {/* Growth Chart */} | |
| <div className="bg-slate-900/50 backdrop-blur-sm p-6 rounded-2xl border border-white/10"> | |
| <h3 className="text-lg font-bold text-white mb-4 flex items-center gap-2"> | |
| <Users className="w-5 h-5 text-indigo-400" /> | |
| Рост пользователей | |
| </h3> | |
| <div className="h-64"> | |
| <ResponsiveContainer width="100%" height="100%"> | |
| <AreaChart data={growthData}> | |
| <defs> | |
| <linearGradient id="colorCount" x1="0" y1="0" x2="0" y2="1"> | |
| <stop offset="5%" stopColor="#6366f1" stopOpacity={0.8} /> | |
| <stop offset="95%" stopColor="#6366f1" stopOpacity={0} /> | |
| </linearGradient> | |
| </defs> | |
| <CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#334155" /> | |
| <XAxis dataKey="date" tickFormatter={(str) => str.slice(5)} stroke="#64748b" /> | |
| <YAxis stroke="#64748b" /> | |
| <Tooltip | |
| contentStyle={{ | |
| backgroundColor: '#1e293b', | |
| border: '1px solid #334155', | |
| borderRadius: '8px', | |
| color: '#fff' | |
| }} | |
| /> | |
| <Area type="monotone" dataKey="count" stroke="#6366f1" fillOpacity={1} fill="url(#colorCount)" /> | |
| </AreaChart> | |
| </ResponsiveContainer> | |
| </div> | |
| </div> | |
| {/* Revenue Chart */} | |
| <div className="bg-slate-900/50 backdrop-blur-sm p-6 rounded-2xl border border-white/10"> | |
| <h3 className="text-lg font-bold text-white mb-4 flex items-center gap-2"> | |
| <DollarSign className="w-5 h-5 text-emerald-400" /> | |
| Выручка (MRR) | |
| </h3> | |
| <div className="mb-4"> | |
| <span className="text-3xl font-bold text-white">${revenueData?.current_mrr || 0}</span> | |
| <span className="text-sm text-slate-400 ml-2">текущий MRR</span> | |
| </div> | |
| <div className="h-52"> | |
| <ResponsiveContainer width="100%" height="100%"> | |
| <LineChart data={revenueData?.history || []}> | |
| <CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#334155" /> | |
| <XAxis dataKey="date" tickFormatter={(str) => str.slice(5)} stroke="#64748b" /> | |
| <YAxis stroke="#64748b" /> | |
| <Tooltip | |
| contentStyle={{ | |
| backgroundColor: '#1e293b', | |
| border: '1px solid #334155', | |
| borderRadius: '8px', | |
| color: '#fff' | |
| }} | |
| /> | |
| <Line type="monotone" dataKey="amount" stroke="#10b981" strokeWidth={3} dot={false} /> | |
| </LineChart> | |
| </ResponsiveContainer> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| ) | |
| } | |