All checks were successful
CI / test-go-consent (push) Successful in 42s
CI / test-python-voice (push) Successful in 30s
CI / test-bqas (push) Successful in 30s
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / Deploy (push) Successful in 2s
Adds /pitch-admin dashboard with real bcrypt admin accounts and full audit attribution for every state-changing action. - pitch_admins + pitch_admin_sessions tables (migration 002) - pitch_audit_logs.admin_id + target_investor_id columns - lib/admin-auth.ts: bcryptjs, single-session, jose JWT with audience claim - middleware.ts: two-cookie gating with bearer-secret CLI fallback - 14 new API routes (admin-auth, dashboard, investor detail/edit/resend, admins CRUD, fm scenarios + assumptions PATCH) - 9 admin pages: login, dashboard, investors list/new/[id], audit, financial-model list/[id], admins - Bootstrap CLI: npm run admin:create - 36 vitest tests covering auth, admin-auth, rate-limit primitives Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
143 lines
5.0 KiB
TypeScript
143 lines
5.0 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
import Link from 'next/link'
|
|
import { Users, UserCheck, Mail, Eye, ArrowRight } from 'lucide-react'
|
|
import StatCard from '@/components/pitch-admin/StatCard'
|
|
import AuditLogTable from '@/components/pitch-admin/AuditLogTable'
|
|
|
|
interface DashboardData {
|
|
totals: {
|
|
total_investors: number
|
|
pending_invites: number
|
|
active_7d: number
|
|
slides_viewed_total: number
|
|
active_sessions: number
|
|
active_admins: number
|
|
}
|
|
recent_logins: Array<{
|
|
investor_id: string
|
|
email: string
|
|
name: string | null
|
|
company: string | null
|
|
created_at: string
|
|
ip_address: string | null
|
|
}>
|
|
recent_activity: Array<{
|
|
id: number
|
|
action: string
|
|
created_at: string
|
|
details: Record<string, unknown> | null
|
|
investor_email: string | null
|
|
investor_name: string | null
|
|
target_investor_email: string | null
|
|
admin_email: string | null
|
|
admin_name: string | null
|
|
}>
|
|
}
|
|
|
|
export default function DashboardPage() {
|
|
const [data, setData] = useState<DashboardData | null>(null)
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
fetch('/api/admin/dashboard')
|
|
.then((r) => r.json())
|
|
.then(setData)
|
|
.finally(() => setLoading(false))
|
|
}, [])
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="flex items-center justify-center h-64">
|
|
<div className="w-8 h-8 border-2 border-indigo-500 border-t-transparent rounded-full animate-spin" />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (!data) return <div className="text-rose-400">Failed to load dashboard</div>
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<h1 className="text-2xl font-semibold text-white">Dashboard</h1>
|
|
<p className="text-sm text-white/50 mt-1">Investor activity overview</p>
|
|
</div>
|
|
<Link
|
|
href="/pitch-admin/investors/new"
|
|
className="bg-gradient-to-r from-indigo-500 to-purple-600 hover:from-indigo-600 hover:to-purple-700 text-white text-sm font-medium px-4 py-2 rounded-lg shadow-lg shadow-indigo-500/20 transition-all"
|
|
>
|
|
+ Invite Investor
|
|
</Link>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
|
<StatCard label="Total Investors" value={data.totals.total_investors} icon={Users} accent="indigo" />
|
|
<StatCard
|
|
label="Active (7d)"
|
|
value={data.totals.active_7d}
|
|
icon={UserCheck}
|
|
accent="green"
|
|
hint={`${data.totals.active_sessions} live sessions`}
|
|
/>
|
|
<StatCard
|
|
label="Pending Invites"
|
|
value={data.totals.pending_invites}
|
|
icon={Mail}
|
|
accent="amber"
|
|
/>
|
|
<StatCard
|
|
label="Slides Viewed"
|
|
value={data.totals.slides_viewed_total}
|
|
icon={Eye}
|
|
accent="indigo"
|
|
hint="all-time"
|
|
/>
|
|
</div>
|
|
|
|
<div className="grid lg:grid-cols-2 gap-6">
|
|
<section className="bg-white/[0.04] border border-white/[0.06] rounded-2xl p-5">
|
|
<div className="flex items-center justify-between mb-4">
|
|
<h2 className="text-sm font-semibold text-white">Recent Logins</h2>
|
|
<Link href="/pitch-admin/investors" className="text-xs text-indigo-400 hover:text-indigo-300 flex items-center gap-1">
|
|
All investors <ArrowRight className="w-3 h-3" />
|
|
</Link>
|
|
</div>
|
|
{data.recent_logins.length === 0 ? (
|
|
<div className="text-white/40 text-sm py-8 text-center">No logins yet</div>
|
|
) : (
|
|
<ul className="space-y-2">
|
|
{data.recent_logins.map((row, i) => (
|
|
<li key={i} className="flex items-center justify-between text-sm py-2 border-b border-white/[0.04] last:border-0">
|
|
<div className="min-w-0">
|
|
<Link href={`/pitch-admin/investors/${row.investor_id}`} className="text-white/90 hover:text-indigo-300 truncate block">
|
|
{row.name || row.email}
|
|
</Link>
|
|
<div className="text-xs text-white/40 truncate">{row.company || row.email}</div>
|
|
</div>
|
|
<div className="text-xs text-white/40 whitespace-nowrap ml-3">
|
|
{new Date(row.created_at).toLocaleString()}
|
|
</div>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</section>
|
|
|
|
<section className="bg-white/[0.04] border border-white/[0.06] rounded-2xl p-5">
|
|
<div className="flex items-center justify-between mb-4">
|
|
<h2 className="text-sm font-semibold text-white">Recent Activity</h2>
|
|
<Link href="/pitch-admin/audit" className="text-xs text-indigo-400 hover:text-indigo-300 flex items-center gap-1">
|
|
Full log <ArrowRight className="w-3 h-3" />
|
|
</Link>
|
|
</div>
|
|
<div className="-mx-5">
|
|
<AuditLogTable rows={data.recent_activity.slice(0, 8)} />
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|