Spaces:
Paused
Paused
CBV01 commited on
Commit ·
d05eb3b
1
Parent(s): 2ad179a
Updated dashboard engagement chart to match 'Trends' design from image
Browse files- frontend/src/app/page.tsx +112 -60
frontend/src/app/page.tsx
CHANGED
|
@@ -1,14 +1,50 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import React, { useState, useEffect } from 'react';
|
| 4 |
-
import Link from 'next/link';
|
| 5 |
-
import { apiFetch } from '@/lib/auth';
|
| 6 |
-
import { Megaphone, Shield } from 'lucide-react';
|
| 7 |
|
| 8 |
export default function Dashboard() {
|
| 9 |
const [stats, setStats] = useState<any>(null);
|
| 10 |
const [loading, setLoading] = useState(true);
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
useEffect(() => {
|
| 13 |
const fetchStats = async () => {
|
| 14 |
try {
|
|
@@ -59,102 +95,118 @@ export default function Dashboard() {
|
|
| 59 |
<div className="grid grid-cols-1 md:grid-cols-4 gap-5 mb-8">
|
| 60 |
<div className="bg-card border border-border p-5 rounded-[20px] relative overflow-hidden group hover:border-indigo-500/30 transition-all shadow-xl">
|
| 61 |
<div className="flex justify-between items-start mb-2">
|
| 62 |
-
<div className="text-foreground/40 text-[11px] font-bold tracking-wider uppercase">
|
| 63 |
-
<div className="p-1.5 bg-blue-500/10 rounded-lg text-blue-400"><
|
| 64 |
</div>
|
| 65 |
<div className="text-2xl font-bold text-foreground mb-2">{stats?.counts?.messages ?? '...'}</div>
|
| 66 |
-
<div className="flex items-center gap-1.5 text-[10px] text-foreground/30 font-medium">
|
| 67 |
</div>
|
| 68 |
|
| 69 |
<div className="bg-card border border-border p-5 rounded-[20px] relative overflow-hidden group hover:border-indigo-500/30 transition-all shadow-xl">
|
| 70 |
<div className="flex justify-between items-start mb-2">
|
| 71 |
-
<div className="text-foreground/40 text-[11px] font-bold tracking-wider uppercase">
|
| 72 |
-
<div className="p-1.5 bg-indigo-500/10 rounded-lg text-indigo-500"><
|
| 73 |
</div>
|
| 74 |
<div className="text-2xl font-bold text-foreground mb-2">{stats?.counts?.accounts ?? '...'}</div>
|
| 75 |
<div className="flex items-center gap-1.5 text-[10px] text-emerald-400/60 font-medium">
|
| 76 |
-
<span className="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"></span> {Number(stats?.counts?.accounts) > 0 ? '
|
| 77 |
</div>
|
| 78 |
</div>
|
| 79 |
|
| 80 |
<div className="bg-card border border-border p-5 rounded-[20px] relative overflow-hidden group hover:border-indigo-500/30 transition-all shadow-xl">
|
| 81 |
<div className="flex justify-between items-start mb-2">
|
| 82 |
-
<div className="text-foreground/40 text-[11px] font-bold tracking-wider uppercase">
|
| 83 |
-
<div className="p-1.5 bg-purple-500/10 rounded-lg text-purple-400"><
|
| 84 |
</div>
|
| 85 |
<div className="text-2xl font-bold text-foreground mb-2">{stats?.counts?.leads ?? '...'}</div>
|
| 86 |
-
<div className="flex items-center gap-1.5 text-[10px] text-foreground/30 font-medium">
|
| 87 |
</div>
|
| 88 |
|
| 89 |
<div className="bg-card border border-border p-5 rounded-[20px] relative overflow-hidden group hover:border-indigo-500/30 transition-all shadow-xl">
|
| 90 |
<div className="flex justify-between items-start mb-2">
|
| 91 |
-
<div className="text-foreground/40 text-[11px] font-bold tracking-wider uppercase">
|
| 92 |
-
<div className="p-1.5 bg-amber-500/10 rounded-lg text-amber-500"><
|
| 93 |
</div>
|
| 94 |
<div className="text-2xl font-bold text-foreground mb-2">{stats?.counts?.pending ?? '...'}</div>
|
| 95 |
-
<div className="flex items-center gap-1.5 text-[10px] text-amber-400/60 font-medium">
|
| 96 |
</div>
|
| 97 |
</div>
|
| 98 |
|
| 99 |
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8 mb-8">
|
| 100 |
-
<div className="lg:col-span-2 bg-card border border-border rounded-[32px] p-8 shadow-2xl relative overflow-hidden group">
|
| 101 |
-
<div className="
|
| 102 |
-
<
|
|
|
|
|
|
|
|
|
|
| 103 |
</div>
|
| 104 |
-
<
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
</div>
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
</div>
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
<svg className="w-full h-full pb-4 pr-4" viewBox="0 0 1000 100" preserveAspectRatio="none">
|
| 116 |
<defs>
|
| 117 |
-
<linearGradient id="
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
<stop offset="0%" stopColor="#4f46e5" />
|
| 119 |
-
<stop offset="50%" stopColor="#6366f1" />
|
| 120 |
<stop offset="100%" stopColor="#818cf8" />
|
| 121 |
</linearGradient>
|
| 122 |
-
<filter id="glow" x="-20%" y="-20%" width="140%" height="140%">
|
| 123 |
-
<feGaussianBlur stdDeviation="3" result="blur" />
|
| 124 |
-
<feComposite in="SourceGraphic" in2="blur" operator="over" />
|
| 125 |
-
</filter>
|
| 126 |
</defs>
|
|
|
|
|
|
|
| 127 |
<path
|
| 128 |
-
d={
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
| 133 |
fill="none"
|
| 134 |
-
stroke="url(#
|
| 135 |
strokeWidth="4"
|
| 136 |
strokeLinecap="round"
|
| 137 |
strokeLinejoin="round"
|
| 138 |
-
|
| 139 |
-
className="drop-shadow-[0_0_15px_rgba(99,102,241,0.3)] transition-all duration-1000"
|
| 140 |
/>
|
| 141 |
-
|
| 142 |
-
{
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
</svg>
|
| 153 |
</div>
|
| 154 |
-
<div className="flex justify-between text-foreground/20 text-[9px] font-bold uppercase tracking-[0.3em] mt-6 border-t border-border/50 pt-4">
|
| 155 |
-
<span>Historical Cycle Start</span>
|
| 156 |
-
<span>Current Transmission Window</span>
|
| 157 |
-
</div>
|
| 158 |
</div>
|
| 159 |
|
| 160 |
<div className="bg-card border border-border rounded-[32px] p-8 shadow-2xl flex flex-col relative overflow-hidden group">
|
|
|
|
| 1 |
+
import { Megaphone, Shield, TrendingUp, Activity, Zap } from 'lucide-react';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
export default function Dashboard() {
|
| 4 |
const [stats, setStats] = useState<any>(null);
|
| 5 |
const [loading, setLoading] = useState(true);
|
| 6 |
|
| 7 |
+
// Generate date labels for the last 7 days
|
| 8 |
+
const getDateLabels = () => {
|
| 9 |
+
const labels = [];
|
| 10 |
+
for (let i = 6; i >= 0; i--) {
|
| 11 |
+
const d = new Date();
|
| 12 |
+
d.setDate(d.getDate() - i);
|
| 13 |
+
labels.push(`${(d.getMonth() + 1).toString().padStart(2, '0')}/${d.getDate().toString().padStart(2, '0')}`);
|
| 14 |
+
}
|
| 15 |
+
return labels;
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
const dateLabels = getDateLabels();
|
| 19 |
+
const chartData = stats?.engagement_flow || [85, 45, 60, 30, 70, 55, 40]; // Use 7 points for weekly
|
| 20 |
+
|
| 21 |
+
// Smooth curve calculation (simple interpolation)
|
| 22 |
+
const generateSmoothPath = (data: number[]) => {
|
| 23 |
+
if (!data.length) return "";
|
| 24 |
+
const width = 1000;
|
| 25 |
+
const height = 200;
|
| 26 |
+
const padding = 40;
|
| 27 |
+
const chartHeight = height - padding * 2;
|
| 28 |
+
const chartWidth = width - padding * 2;
|
| 29 |
+
const step = chartWidth / (data.length - 1);
|
| 30 |
+
|
| 31 |
+
let path = `M ${padding} ${height - padding - (data[0] / 100) * chartHeight}`;
|
| 32 |
+
|
| 33 |
+
for (let i = 0; i < data.length - 1; i++) {
|
| 34 |
+
const x1 = padding + i * step;
|
| 35 |
+
const y1 = height - padding - (data[i] / 100) * chartHeight;
|
| 36 |
+
const x2 = padding + (i + 1) * step;
|
| 37 |
+
const y2 = height - padding - (data[i + 1] / 100) * chartHeight;
|
| 38 |
+
|
| 39 |
+
const cx = (x1 + x2) / 2;
|
| 40 |
+
path += ` C ${cx} ${y1}, ${cx} ${y2}, ${x2} ${y2}`;
|
| 41 |
+
}
|
| 42 |
+
return path;
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
const smoothPath = generateSmoothPath(chartData);
|
| 46 |
+
const areaPath = smoothPath + ` L ${960} 160 L 40 160 Z`;
|
| 47 |
+
|
| 48 |
useEffect(() => {
|
| 49 |
const fetchStats = async () => {
|
| 50 |
try {
|
|
|
|
| 95 |
<div className="grid grid-cols-1 md:grid-cols-4 gap-5 mb-8">
|
| 96 |
<div className="bg-card border border-border p-5 rounded-[20px] relative overflow-hidden group hover:border-indigo-500/30 transition-all shadow-xl">
|
| 97 |
<div className="flex justify-between items-start mb-2">
|
| 98 |
+
<div className="text-foreground/40 text-[11px] font-bold tracking-wider uppercase font-mono">Transmission Count</div>
|
| 99 |
+
<div className="p-1.5 bg-blue-500/10 rounded-lg text-blue-400"><Activity size={16} /></div>
|
| 100 |
</div>
|
| 101 |
<div className="text-2xl font-bold text-foreground mb-2">{stats?.counts?.messages ?? '...'}</div>
|
| 102 |
+
<div className="flex items-center gap-1.5 text-[10px] text-foreground/30 font-medium italic">Verified broadcast throughput</div>
|
| 103 |
</div>
|
| 104 |
|
| 105 |
<div className="bg-card border border-border p-5 rounded-[20px] relative overflow-hidden group hover:border-indigo-500/30 transition-all shadow-xl">
|
| 106 |
<div className="flex justify-between items-start mb-2">
|
| 107 |
+
<div className="text-foreground/40 text-[11px] font-bold tracking-wider uppercase font-mono">Active Nodes</div>
|
| 108 |
+
<div className="p-1.5 bg-indigo-500/10 rounded-lg text-indigo-500"><Zap size={16} /></div>
|
| 109 |
</div>
|
| 110 |
<div className="text-2xl font-bold text-foreground mb-2">{stats?.counts?.accounts ?? '...'}</div>
|
| 111 |
<div className="flex items-center gap-1.5 text-[10px] text-emerald-400/60 font-medium">
|
| 112 |
+
<span className="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse shadow-[0_0_8px_rgba(16,185,129,0.5)]"></span> {Number(stats?.counts?.accounts) > 0 ? 'Cluster Online' : 'Status: Isolated'}
|
| 113 |
</div>
|
| 114 |
</div>
|
| 115 |
|
| 116 |
<div className="bg-card border border-border p-5 rounded-[20px] relative overflow-hidden group hover:border-indigo-500/30 transition-all shadow-xl">
|
| 117 |
<div className="flex justify-between items-start mb-2">
|
| 118 |
+
<div className="text-foreground/40 text-[11px] font-bold tracking-wider uppercase font-mono">Entity Leads</div>
|
| 119 |
+
<div className="p-1.5 bg-purple-500/10 rounded-lg text-purple-400"><Shield size={16} /></div>
|
| 120 |
</div>
|
| 121 |
<div className="text-2xl font-bold text-foreground mb-2">{stats?.counts?.leads ?? '...'}</div>
|
| 122 |
+
<div className="flex items-center gap-1.5 text-[10px] text-foreground/30 font-medium italic">Targeted leads analyzed</div>
|
| 123 |
</div>
|
| 124 |
|
| 125 |
<div className="bg-card border border-border p-5 rounded-[20px] relative overflow-hidden group hover:border-indigo-500/30 transition-all shadow-xl">
|
| 126 |
<div className="flex justify-between items-start mb-2">
|
| 127 |
+
<div className="text-foreground/40 text-[11px] font-bold tracking-wider uppercase font-mono">Queue Depth</div>
|
| 128 |
+
<div className="p-1.5 bg-amber-500/10 rounded-lg text-amber-500"><Activity size={16} /></div>
|
| 129 |
</div>
|
| 130 |
<div className="text-2xl font-bold text-foreground mb-2">{stats?.counts?.pending ?? '...'}</div>
|
| 131 |
+
<div className="flex items-center gap-1.5 text-[10px] text-amber-400/60 font-medium font-mono">Cycle Overhead Status</div>
|
| 132 |
</div>
|
| 133 |
</div>
|
| 134 |
|
| 135 |
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8 mb-8">
|
| 136 |
+
<div className="lg:col-span-2 bg-card border border-border rounded-[32px] p-8 shadow-2xl relative overflow-hidden group flex flex-col min-h-[420px]">
|
| 137 |
+
<div className="flex items-center gap-3 mb-2">
|
| 138 |
+
<div className="p-2 bg-emerald-500/10 rounded-xl text-emerald-500">
|
| 139 |
+
<TrendingUp size={24} />
|
| 140 |
+
</div>
|
| 141 |
+
<h3 className="text-2xl font-bold text-foreground tracking-tight">Trends</h3>
|
| 142 |
</div>
|
| 143 |
+
<p className="text-sm text-foreground/40 mb-10 font-medium">Message outreach over the last 7 days</p>
|
| 144 |
+
|
| 145 |
+
<div className="flex-1 relative mt-4">
|
| 146 |
+
{/* Grid Lines */}
|
| 147 |
+
<div className="absolute inset-x-0 inset-y-0 flex flex-col justify-between pointer-events-none opacity-20 px-10 pt-10 pb-10">
|
| 148 |
+
{[1400, 1050, 700, 350, 0].map(val => (
|
| 149 |
+
<div key={val} className="flex items-center gap-4 w-full">
|
| 150 |
+
<span className="text-[10px] font-mono text-foreground/50 w-8">{val}</span>
|
| 151 |
+
<div className="flex-1 border-t border-dashed border-foreground/30" />
|
| 152 |
+
</div>
|
| 153 |
+
))}
|
| 154 |
</div>
|
| 155 |
+
|
| 156 |
+
<div className="absolute inset-x-0 bottom-0 flex justify-between px-10 pointer-events-none">
|
| 157 |
+
{dateLabels.map(label => (
|
| 158 |
+
<span key={label} className="text-[10px] font-mono text-foreground/30 font-bold">{label}</span>
|
| 159 |
+
))}
|
| 160 |
</div>
|
| 161 |
+
|
| 162 |
+
<svg className="w-full h-full pb-10 px-10" viewBox="0 0 1000 200" preserveAspectRatio="none">
|
|
|
|
| 163 |
<defs>
|
| 164 |
+
<linearGradient id="areaGradient" x1="0%" y1="0%" x2="0%" y2="100%">
|
| 165 |
+
<stop offset="0%" stopColor="#6366f1" stopOpacity="0.3" />
|
| 166 |
+
<stop offset="100%" stopColor="#6366f1" stopOpacity="0" />
|
| 167 |
+
</linearGradient>
|
| 168 |
+
<linearGradient id="lineGradient" x1="0%" y1="0%" x2="100%" y2="0%">
|
| 169 |
<stop offset="0%" stopColor="#4f46e5" />
|
|
|
|
| 170 |
<stop offset="100%" stopColor="#818cf8" />
|
| 171 |
</linearGradient>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
</defs>
|
| 173 |
+
|
| 174 |
+
{/* Fill Area */}
|
| 175 |
<path
|
| 176 |
+
d={areaPath}
|
| 177 |
+
fill="url(#areaGradient)"
|
| 178 |
+
className="transition-all duration-1000"
|
| 179 |
+
/>
|
| 180 |
+
|
| 181 |
+
{/* Main Line */}
|
| 182 |
+
<path
|
| 183 |
+
d={smoothPath}
|
| 184 |
fill="none"
|
| 185 |
+
stroke="url(#lineGradient)"
|
| 186 |
strokeWidth="4"
|
| 187 |
strokeLinecap="round"
|
| 188 |
strokeLinejoin="round"
|
| 189 |
+
className="drop-shadow-[0_0_15px_rgba(99,102,241,0.5)] transition-all duration-1000"
|
|
|
|
| 190 |
/>
|
| 191 |
+
|
| 192 |
+
{/* Data Points / Interaction Nodes */}
|
| 193 |
+
{chartData.map((val: number, i: number) => {
|
| 194 |
+
const step = 920 / (chartData.length - 1);
|
| 195 |
+
const x = 40 + i * step;
|
| 196 |
+
const y = 160 - (val / 100) * 120;
|
| 197 |
+
return (
|
| 198 |
+
<circle
|
| 199 |
+
key={i}
|
| 200 |
+
cx={x}
|
| 201 |
+
cy={y}
|
| 202 |
+
r="4"
|
| 203 |
+
fill="#ffffff"
|
| 204 |
+
className="stroke-[3] stroke-indigo-600 hover:r-6 transition-all cursor-pointer"
|
| 205 |
+
/>
|
| 206 |
+
);
|
| 207 |
+
})}
|
| 208 |
</svg>
|
| 209 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
</div>
|
| 211 |
|
| 212 |
<div className="bg-card border border-border rounded-[32px] p-8 shadow-2xl flex flex-col relative overflow-hidden group">
|