BRIDGE_Modul-S_prod / src /pages /Analytics.tsx
sitcod3's picture
build: add Docker support and deployment pipeline
9e7f815
Raw History Blame Contribute Delete
12 kB
import { useQuery } from "@tanstack/react-query";
import { apiClient } from "../lib/apiClient";
import {
BarChart2,
TrendingUp,
Download,
Calendar,
Mail,
Inbox,
Flame,
ShieldCheck,
Percent,
ArrowUpRight
} from "lucide-react";
import {
ResponsiveContainer,
LineChart,
Line,
BarChart,
Bar,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
Legend
} from "recharts";
import { useState } from "react";
import StatCard from "../components/StatCard";
import CsvExportButton from "../components/CsvExportButton";
const timelineData = [
{ date: "Oct 1", sent: 820, opens: 530, replies: 48, bounces: 4 },
{ date: "Oct 5", sent: 1140, opens: 760, replies: 72, bounces: 8 },
{ date: "Oct 10", sent: 1650, opens: 1120, replies: 98, bounces: 11 },
{ date: "Oct 15", sent: 2100, opens: 1450, replies: 134, bounces: 15 },
{ date: "Oct 20", sent: 2800, opens: 1980, replies: 182, bounces: 21 },
{ date: "Oct 25", sent: 3400, opens: 2450, replies: 226, bounces: 28 },
{ date: "Oct 30", sent: 4120, opens: 2980, replies: 280, bounces: 34 },
];
const campaignComparisonData = [
{ name: "SaaS Enterprise VPs", sent: 4200, opens: 2600, replies: 240 },
{ name: "Series A Tech Founders", sent: 3100, opens: 2100, replies: 195 },
{ name: "Agency Owners Q4", sent: 2400, opens: 1400, replies: 120 },
{ name: "E-commerce Directors", sent: 1800, opens: 980, replies: 84 },
{ name: "RevOps Decision Makers", sent: 1200, opens: 720, replies: 65 },
];
export default function Analytics() {
const [dateRange, setDateRange] = useState("30d");
const { data: analytics } = useQuery({
queryKey: ["analytics-campaigns"],
queryFn: async () => {
const res = await apiClient.get("/analytics/campaigns");
return res.data;
},
});
const { data: emailAccounts = [] } = useQuery({
queryKey: ["email-accounts"],
queryFn: async () => {
const res = await apiClient.get("/email-accounts");
return res.data;
},
});
return (
<div className="p-4 md:p-6 max-w-7xl mx-auto space-y-10 animate-fadeIn">
{/* Header */}
<div className="flex flex-col md:flex-row md:items-center justify-between gap-6">
<div className="space-y-2">
<div className="flex items-center gap-2 text-[10px] font-bold uppercase tracking-widest text-zinc-500 font-mono">
<span>Intelligence</span>
<span className="text-zinc-700">/</span>
<span className="text-zinc-400">Global Performance Radar</span>
</div>
<h1 className="text-3xl font-bold tracking-tight text-white font-sans flex items-center gap-3">
<BarChart2 className="w-8 h-8 text-emerald-400" />
Outbound Analytics
</h1>
<p className="text-zinc-400 text-sm max-w-xl leading-relaxed">
Global deliverability performance, engagement conversion funnels, and multi-mailbox health telemetry.
</p>
</div>
<div className="flex items-center gap-3">
<select
value={dateRange}
onChange={(e) => setDateRange(e.target.value)}
className="bg-zinc-900 border border-white/10 rounded-xl py-2.5 px-4 text-[10px] font-bold uppercase tracking-widest text-zinc-400 focus:outline-none focus:border-emerald-500 transition-colors"
>
<option value="7d">Last 7 Days</option>
<option value="14d">Last 14 Days</option>
<option value="30d">Last 30 Days</option>
<option value="90d">Last 90 Days</option>
</select>
<CsvExportButton data={timelineData} filename="smartlead-analytics-export.csv" />
</div>
</div>
{/* KPI Conversion Cards */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
<StatCard
title="Open Velocity"
value="64.8%"
subtitle="4,890 unique opens"
icon={Mail}
iconColor="emerald"
change={{ value: "+3.4%", isPositive: true, period: "vs benchmark" }}
/>
<StatCard
title="Digital CTR"
value="18.2%"
subtitle="1,120 link clicks"
icon={ArrowUpRight}
iconColor="emerald"
change={{ value: "+1.1%", isPositive: true, period: "last 30 days" }}
/>
<StatCard
title="Intent Signal"
value="6.2%"
subtitle="378 prospect responses"
icon={Inbox}
iconColor="emerald"
change={{ value: "+0.8%", isPositive: true, period: "positive intent" }}
/>
<StatCard
title="Health Score"
value="0.7%"
subtitle="Deliverability safe"
icon={ShieldCheck}
iconColor="emerald"
change={{ value: "-0.2%", isPositive: true, period: "health optimal" }}
/>
</div>
{/* Timeline Chart */}
<div className="bg-zinc-900/30 border border-white/5 backdrop-blur-md rounded-2xl p-8 shadow-2xl">
<div className="flex items-center justify-between mb-8">
<div>
<div className="text-[10px] font-bold uppercase tracking-widest text-zinc-500 font-mono mb-1">Telemetry Trajectory</div>
<h3 className="text-xl font-bold text-white">Cumulative Volume & Responses</h3>
</div>
</div>
<div className="h-[360px] w-full">
<ResponsiveContainer width="100%" height="100%">
<LineChart data={timelineData} margin={{ top: 5, right: 20, bottom: 5, left: 0 }}>
<CartesianGrid strokeDasharray="3 3" stroke="rgba(255,255,255,0.03)" vertical={false} />
<XAxis dataKey="date" stroke="#475569" fontSize={10} tickLine={false} axisLine={false} className="font-mono font-bold uppercase tracking-tighter" />
<YAxis stroke="#475569" fontSize={10} tickLine={false} axisLine={false} tickFormatter={(val) => new Intl.NumberFormat('en-US').format(val)} className="font-mono" />
<Tooltip
contentStyle={{
backgroundColor: "#0c0d10",
borderColor: "rgba(255,255,255,0.08)",
borderRadius: "16px",
fontSize: "11px",
boxShadow: "0 20px 40px rgba(0,0,0,0.8)"
}}
/>
<Legend wrapperStyle={{ fontSize: "10px", paddingTop: "20px", textTransform: 'uppercase', fontWeight: 'bold', letterSpacing: '0.1em' }} />
<Line type="monotone" dataKey="sent" name="Sent" stroke="#38bdf8" strokeWidth={3} dot={false} activeDot={{ r: 5, fill: '#38bdf8' }} animationDuration={2000} />
<Line type="monotone" dataKey="opens" name="Opened" stroke="#00e5bc" strokeWidth={3} dot={false} activeDot={{ r: 5, fill: '#00e5bc' }} animationDuration={2000} />
<Line type="monotone" dataKey="replies" name="Replied" stroke="#10b981" strokeWidth={3} dot={false} activeDot={{ r: 5, fill: '#10b981' }} animationDuration={2000} />
</LineChart>
</ResponsiveContainer>
</div>
</div>
{/* Comparison Grid */}
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8">
{/* Top Campaigns Comparison */}
<div className="bg-zinc-900/30 border border-white/5 backdrop-blur-md rounded-2xl p-8 shadow-2xl">
<div className="text-[10px] font-bold uppercase tracking-widest text-zinc-500 font-mono mb-1">Cluster Comparison</div>
<h3 className="text-xl font-bold text-white mb-8">Top Cluster Performance</h3>
<div className="h-[300px] w-full">
<ResponsiveContainer width="100%" height="100%">
<BarChart data={campaignComparisonData} layout="vertical" margin={{ top: 5, right: 30, bottom: 5, left: 40 }}>
<defs>
<linearGradient id="mintGradient" x1="0" y1="0" x2="1" y2="0">
<stop offset="0%" stopColor="#00e5bc" stopOpacity={0.6}/>
<stop offset="100%" stopColor="#00e5bc" stopOpacity={1}/>
</linearGradient>
<linearGradient id="emeraldGradient" x1="0" y1="0" x2="1" y2="0">
<stop offset="0%" stopColor="#10b981" stopOpacity={0.6}/>
<stop offset="100%" stopColor="#10b981" stopOpacity={1}/>
</linearGradient>
</defs>
<CartesianGrid strokeDasharray="3 3" stroke="rgba(255,255,255,0.03)" horizontal={false} />
<XAxis type="number" stroke="#475569" fontSize={10} tickLine={false} axisLine={false} className="font-mono" />
<YAxis dataKey="name" type="category" stroke="#94a3b8" fontSize={10} tickLine={false} axisLine={false} width={120} />
<Tooltip
contentStyle={{
backgroundColor: "#0c0d10",
borderColor: "rgba(255,255,255,0.08)",
borderRadius: "12px",
fontSize: "11px",
}}
/>
<Bar dataKey="opens" name="Opened" fill="url(#mintGradient)" radius={[0, 4, 4, 0]} barSize={12} animationDuration={1500} />
<Bar dataKey="replies" name="Replied" fill="url(#emeraldGradient)" radius={[0, 4, 4, 0]} barSize={12} animationDuration={1500} />
</BarChart>
</ResponsiveContainer>
</div>
</div>
{/* Mailbox Deliverability Health Matrix */}
<div className="bg-zinc-900/30 border border-white/5 backdrop-blur-md rounded-2xl p-8 shadow-2xl flex flex-col justify-between">
<div>
<div className="text-[10px] font-bold uppercase tracking-widest text-zinc-500 font-mono mb-1">Infrastructure Health</div>
<h3 className="text-xl font-bold text-white mb-8">Mailbox Deliverability Matrix</h3>
<div className="space-y-4">
{emailAccounts.map((acc: any) => (
<div
key={acc.id}
className="flex items-center justify-between p-4 bg-black/40 border border-white/5 rounded-xl group hover:bg-white/[0.02] transition-all"
>
<div className="flex items-center gap-4">
<div className="p-2.5 rounded-lg bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 group-hover:shadow-[0_0_15px_rgba(16,185,129,0.15)] transition-all">
<Mail className="w-4 h-4" />
</div>
<div>
<span className="text-[11px] font-bold text-zinc-200">{acc.from_email}</span>
<div className="text-[9px] text-zinc-600 mt-1 uppercase tracking-widest font-mono">
SPF: <span className="text-emerald-500/60">PASS</span> • DKIM: <span className="text-emerald-500/60">PASS</span> • DMARC: <span className="text-emerald-500/60">PASS</span>
</div>
</div>
</div>
<div className="flex items-center gap-4 font-mono">
<div className="text-right">
<div className="text-sm font-black text-emerald-400 drop-shadow-[0_0_12px_rgba(0,229,188,0.3)]">99.4%</div>
<div className="text-[8px] font-bold uppercase tracking-widest text-zinc-500">OPTIMAL</div>
</div>
</div>
</div>
))}
</div>
</div>
<div className="mt-8 pt-6 border-t border-white/5 flex items-center justify-between">
<span className="text-[10px] font-bold uppercase tracking-widest text-zinc-500 font-mono">Global Operational Reputation: <span className="text-emerald-400">98.4 / 100</span></span>
<span className="text-emerald-400 text-[10px] font-bold uppercase tracking-widest flex items-center gap-2"><ShieldCheck className="w-4 h-4" /> Nodes Secure</span>
</div>
</div>
</div>
</div>
);
}