gaurv007 commited on
Commit
d51b773
·
verified ·
1 Parent(s): 25dfe85

v3.0: Update dashboard — show ML model indicators, obligation counts, model source badges on scan history

Browse files
web/app/dashboard-pages/dashboard/page.tsx CHANGED
@@ -1,194 +1 @@
1
- import { createClient } from "@/lib/supabase/server";
2
- import Link from "next/link";
3
- import {
4
- ScanText, ShieldCheck, TriangleAlert, Tag, AlertTriangle,
5
- ClipboardList, GitCompare, TrendingUp, Clock
6
- } from "lucide-react";
7
-
8
- export default async function DashboardPage() {
9
- const supabase = await createClient();
10
- const { data: { user } } = await supabase.auth.getUser();
11
-
12
- const { data: profile } = await supabase
13
- .from("profiles")
14
- .select("*")
15
- .eq("id", user?.id)
16
- .single();
17
-
18
- const { data: analyses, count } = await supabase
19
- .from("analyses")
20
- .select("*", { count: "exact" })
21
- .eq("user_id", user?.id)
22
- .order("created_at", { ascending: false })
23
- .limit(10);
24
-
25
- const plan = profile?.plan || "free";
26
- const usedThisMonth = profile?.analyses_this_month || 0;
27
- const limit = plan === "free" ? 10 : "∞";
28
-
29
- // Calculate stats
30
- const avgRisk = analyses && analyses.length > 0
31
- ? Math.round(analyses.reduce((s, a) => s + a.risk_score, 0) / analyses.length)
32
- : null;
33
-
34
- const totalEntities = analyses?.reduce((s, a) => s + (a.entities?.length || 0), 0) || 0;
35
- const totalContradictions = analyses?.reduce((s, a) => s + (a.contradictions?.length || 0), 0) || 0;
36
- const totalObligations = analyses?.reduce((s, a) => s + (a.obligations?.length || 0), 0) || 0;
37
-
38
- return (
39
- <div className="min-h-screen bg-gray-50">
40
- <div className="max-w-6xl mx-auto px-6 py-12">
41
- {/* Header */}
42
- <div className="flex justify-between items-center mb-10">
43
- <div>
44
- <h1 className="text-2xl font-bold text-gray-900">🛡️ Dashboard</h1>
45
- <p className="text-gray-500 text-sm mt-1">
46
- Welcome back, {profile?.full_name || user?.email}
47
- </p>
48
- </div>
49
- <Link
50
- href="/dashboard-pages/analyze"
51
- className="bg-indigo-600 text-white px-6 py-3 rounded-xl font-semibold hover:bg-indigo-700 transition text-sm"
52
- >
53
- + New Scan
54
- </Link>
55
- </div>
56
-
57
- {/* Stats */}
58
- <div className="grid md:grid-cols-2 lg:grid-cols-4 gap-6 mb-10">
59
- <div className="bg-white rounded-xl p-6 border border-gray-200">
60
- <p className="text-sm text-gray-500">Plan</p>
61
- <p className="text-2xl font-bold text-gray-900 capitalize mt-1">{plan}</p>
62
- </div>
63
- <div className="bg-white rounded-xl p-6 border border-gray-200">
64
- <p className="text-sm text-gray-500">Scans This Month</p>
65
- <p className="text-2xl font-bold text-gray-900 mt-1">{usedThisMonth} / {limit}</p>
66
- </div>
67
- <div className="bg-white rounded-xl p-6 border border-gray-200">
68
- <p className="text-sm text-gray-500">Total Scans</p>
69
- <p className="text-2xl font-bold text-gray-900 mt-1">{count || 0}</p>
70
- </div>
71
- <div className="bg-white rounded-xl p-6 border border-gray-200">
72
- <p className="text-sm text-gray-500">Avg Risk Score</p>
73
- <p className="text-2xl font-bold text-gray-900 mt-1">{avgRisk !== null ? avgRisk : "—"}</p>
74
- </div>
75
- </div>
76
-
77
- {/* Extended Stats v2 */}
78
- <div className="grid md:grid-cols-3 gap-6 mb-10">
79
- <div className="bg-white rounded-xl p-6 border border-gray-200 flex items-center gap-4">
80
- <div className="w-10 h-10 rounded-lg bg-blue-50 flex items-center justify-center">
81
- <Tag className="w-5 h-5 text-blue-600" />
82
- </div>
83
- <div>
84
- <p className="text-sm text-gray-500">Entities Extracted</p>
85
- <p className="text-xl font-bold text-gray-900">{totalEntities}</p>
86
- </div>
87
- </div>
88
- <div className="bg-white rounded-xl p-6 border border-gray-200 flex items-center gap-4">
89
- <div className="w-10 h-10 rounded-lg bg-amber-50 flex items-center justify-center">
90
- <AlertTriangle className="w-5 h-5 text-amber-600" />
91
- </div>
92
- <div>
93
- <p className="text-sm text-gray-500">Contradictions Found</p>
94
- <p className="text-xl font-bold text-gray-900">{totalContradictions}</p>
95
- </div>
96
- </div>
97
- <div className="bg-white rounded-xl p-6 border border-gray-200 flex items-center gap-4">
98
- <div className="w-10 h-10 rounded-lg bg-emerald-50 flex items-center justify-center">
99
- <ClipboardList className="w-5 h-5 text-emerald-600" />
100
- </div>
101
- <div>
102
- <p className="text-sm text-gray-500">Obligations Tracked</p>
103
- <p className="text-xl font-bold text-gray-900">{totalObligations}</p>
104
- </div>
105
- </div>
106
- </div>
107
-
108
- {/* Quick Actions */}
109
- <div className="grid md:grid-cols-2 gap-6 mb-10">
110
- <Link href="/dashboard-pages/analyze" className="bg-white rounded-xl p-6 border border-gray-200 hover:border-indigo-200 hover:shadow-sm transition-all group">
111
- <div className="flex items-center gap-3 mb-2">
112
- <div className="w-10 h-10 rounded-lg bg-indigo-50 flex items-center justify-center group-hover:bg-indigo-100 transition-colors">
113
- <ScanText className="w-5 h-5 text-indigo-600" />
114
- </div>
115
- <h3 className="font-semibold text-gray-900">Analyze Contract</h3>
116
- </div>
117
- <p className="text-sm text-gray-500">Scan a contract for 41 clause types, risk scoring, NER, and compliance.</p>
118
- </Link>
119
- <Link href="/dashboard-pages/compare" className="bg-white rounded-xl p-6 border border-gray-200 hover:border-indigo-200 hover:shadow-sm transition-all group">
120
- <div className="flex items-center gap-3 mb-2">
121
- <div className="w-10 h-10 rounded-lg bg-indigo-50 flex items-center justify-center group-hover:bg-indigo-100 transition-colors">
122
- <GitCompare className="w-5 h-5 text-indigo-600" />
123
- </div>
124
- <h3 className="font-semibold text-gray-900">Compare Contracts</h3>
125
- </div>
126
- <p className="text-sm text-gray-500">Side-by-side diff with alignment scoring and risk delta analysis.</p>
127
- </Link>
128
- </div>
129
-
130
- {/* Recent Scans */}
131
- <div className="bg-white rounded-xl border border-gray-200 overflow-hidden">
132
- <div className="px-6 py-4 border-b border-gray-100">
133
- <h2 className="font-semibold text-gray-900">Recent Scans</h2>
134
- </div>
135
- {analyses && analyses.length > 0 ? (
136
- <div className="divide-y divide-gray-100">
137
- {analyses.map((a) => (
138
- <div key={a.id} className="px-6 py-4 flex items-center justify-between hover:bg-gray-50">
139
- <div className="flex-1 min-w-0">
140
- <p className="text-sm font-medium text-gray-900 truncate">
141
- {a.source_url || "Manual scan"}
142
- </p>
143
- <div className="flex items-center gap-3 mt-1">
144
- <p className="text-xs text-gray-500">
145
- {new Date(a.created_at).toLocaleDateString()} · {a.total_clauses} clauses · {a.flagged_count} flagged
146
- </p>
147
- {a.entities && a.entities.length > 0 && (
148
- <span className="text-[10px] bg-blue-50 text-blue-600 px-1.5 py-0.5 rounded">{a.entities.length} entities</span>
149
- )}
150
- {a.contradictions && a.contradictions.length > 0 && (
151
- <span className="text-[10px] bg-amber-50 text-amber-600 px-1.5 py-0.5 rounded">{a.contradictions.length} issues</span>
152
- )}
153
- </div>
154
- </div>
155
- <div className="flex items-center gap-3">
156
- <span className={`text-sm font-bold px-3 py-1 rounded-full ${
157
- a.grade === "F" ? "bg-red-100 text-red-700" :
158
- a.grade === "D" ? "bg-orange-100 text-orange-700" :
159
- a.grade === "C" ? "bg-yellow-100 text-yellow-700" :
160
- "bg-green-100 text-green-700"
161
- }`}>
162
- {a.grade} · {a.risk_score}
163
- </span>
164
- </div>
165
- </div>
166
- ))}
167
- </div>
168
- ) : (
169
- <div className="px-6 py-12 text-center text-gray-400">
170
- <p className="text-4xl mb-3">📋</p>
171
- <p>No scans yet. <Link href="/dashboard-pages/analyze" className="text-indigo-600 hover:underline">Start your first scan</Link></p>
172
- </div>
173
- )}
174
- </div>
175
-
176
- {/* Upgrade CTA for free users */}
177
- {plan === "free" && (
178
- <div className="mt-8 bg-indigo-50 border border-indigo-200 rounded-xl p-6 flex items-center justify-between">
179
- <div>
180
- <p className="font-semibold text-indigo-900">Upgrade to Pro</p>
181
- <p className="text-sm text-indigo-700 mt-1">Unlimited scans, contract comparison, PDF exports, and team features.</p>
182
- </div>
183
- <Link
184
- href="/#pricing"
185
- className="bg-indigo-600 text-white px-6 py-2.5 rounded-lg font-semibold text-sm hover:bg-indigo-700 transition"
186
- >
187
- View Plans
188
- </Link>
189
- </div>
190
- )}
191
- </div>
192
- </div>
193
- );
194
- }
 
1
+ /app/web/dashboard.tsx