Spaces:
Sleeping
Sleeping
v4.1: Complete Settings page — role, team, API keys, dates, admin badge, danger zone
Browse files
web/app/dashboard-pages/settings/page.tsx
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
import { createClient } from "@/lib/supabase/server";
|
| 2 |
import { redirect } from "next/navigation";
|
| 3 |
import Link from "next/link";
|
| 4 |
-
import {
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
async function handleCancel() {
|
| 7 |
"use server";
|
|
@@ -27,6 +30,21 @@ async function handleSignOut() {
|
|
| 27 |
redirect("/");
|
| 28 |
}
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
export default async function SettingsPage() {
|
| 31 |
const supabase = await createClient();
|
| 32 |
const { data: { user } } = await supabase.auth.getUser();
|
|
@@ -38,10 +56,29 @@ export default async function SettingsPage() {
|
|
| 38 |
.single();
|
| 39 |
|
| 40 |
const plan = profile?.plan || "free";
|
|
|
|
|
|
|
| 41 |
const used = profile?.analyses_this_month || 0;
|
| 42 |
-
const limit = plan === "free" ? "10" : "Unlimited";
|
| 43 |
const hasSub = !!profile?.razorpay_subscription_id;
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
return (
|
| 46 |
<div className="min-h-screen bg-white">
|
| 47 |
<div className="max-w-2xl mx-auto px-5 py-12">
|
|
@@ -61,13 +98,52 @@ export default async function SettingsPage() {
|
|
| 61 |
<div className="border border-zinc-200 rounded-xl divide-y divide-zinc-100">
|
| 62 |
<div className="px-5 py-4 flex justify-between items-center">
|
| 63 |
<div><p className="text-sm font-medium">Email</p><p className="text-sm text-zinc-500">{user?.email}</p></div>
|
|
|
|
| 64 |
</div>
|
| 65 |
<div className="px-5 py-4 flex justify-between items-center">
|
| 66 |
<div><p className="text-sm font-medium">Name</p><p className="text-sm text-zinc-500">{profile?.full_name || "Not set"}</p></div>
|
| 67 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
</div>
|
| 69 |
</section>
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
{/* Subscription */}
|
| 72 |
<section className="mb-8">
|
| 73 |
<div className="flex items-center gap-2 mb-3">
|
|
@@ -76,15 +152,40 @@ export default async function SettingsPage() {
|
|
| 76 |
</div>
|
| 77 |
<div className="border border-zinc-200 rounded-xl divide-y divide-zinc-100">
|
| 78 |
<div className="px-5 py-4 flex justify-between items-center">
|
| 79 |
-
<div>
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
<Link href="/#pricing" className="text-sm font-medium border border-zinc-200 px-3 py-1.5 rounded-lg hover:bg-zinc-50 transition-colors">Upgrade</Link>
|
| 82 |
) : null}
|
| 83 |
</div>
|
| 84 |
<div className="px-5 py-4 flex justify-between items-center">
|
| 85 |
-
<div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
</div>
|
| 87 |
-
{hasSub && plan !== "free" && (
|
| 88 |
<div className="px-5 py-4">
|
| 89 |
<form action={handleCancel}>
|
| 90 |
<button type="submit" className="flex items-center gap-2 text-sm text-red-600 font-medium border border-red-200 px-3 py-1.5 rounded-lg hover:bg-red-50 transition-colors">
|
|
@@ -98,15 +199,83 @@ export default async function SettingsPage() {
|
|
| 98 |
</div>
|
| 99 |
</section>
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
{/* Sign out */}
|
| 102 |
-
<section>
|
| 103 |
<form action={handleSignOut}>
|
| 104 |
-
<button type="submit" className="flex items-center gap-2 text-sm text-zinc-500 font-medium border border-zinc-200 px-4 py-2 rounded-lg hover:bg-zinc-50 transition-colors">
|
| 105 |
<LogOut className="w-4 h-4" />
|
| 106 |
Sign out
|
| 107 |
</button>
|
| 108 |
</form>
|
| 109 |
</section>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
</div>
|
| 111 |
</div>
|
| 112 |
);
|
|
|
|
| 1 |
import { createClient } from "@/lib/supabase/server";
|
| 2 |
import { redirect } from "next/navigation";
|
| 3 |
import Link from "next/link";
|
| 4 |
+
import {
|
| 5 |
+
ArrowLeft, User, CreditCard, LogOut, CircleAlert, Key, Users,
|
| 6 |
+
Shield, Crown, Calendar, Hash, Mail, Globe, Trash2, AlertTriangle
|
| 7 |
+
} from "lucide-react";
|
| 8 |
|
| 9 |
async function handleCancel() {
|
| 10 |
"use server";
|
|
|
|
| 30 |
redirect("/");
|
| 31 |
}
|
| 32 |
|
| 33 |
+
async function handleDeleteAccount() {
|
| 34 |
+
"use server";
|
| 35 |
+
const supabase = await createClient();
|
| 36 |
+
const { data: { user } } = await supabase.auth.getUser();
|
| 37 |
+
if (!user) redirect("/auth/login");
|
| 38 |
+
|
| 39 |
+
// Delete user data (analyses, api keys)
|
| 40 |
+
await supabase.from("analyses").delete().eq("user_id", user.id);
|
| 41 |
+
await supabase.from("api_keys").delete().eq("user_id", user.id);
|
| 42 |
+
await supabase.from("profiles").delete().eq("id", user.id);
|
| 43 |
+
|
| 44 |
+
await supabase.auth.signOut();
|
| 45 |
+
redirect("/?deleted=true");
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
export default async function SettingsPage() {
|
| 49 |
const supabase = await createClient();
|
| 50 |
const { data: { user } } = await supabase.auth.getUser();
|
|
|
|
| 56 |
.single();
|
| 57 |
|
| 58 |
const plan = profile?.plan || "free";
|
| 59 |
+
const role = profile?.role || "user";
|
| 60 |
+
const isAdmin = role === "admin";
|
| 61 |
const used = profile?.analyses_this_month || 0;
|
| 62 |
+
const limit = isAdmin ? "Unlimited" : plan === "free" ? "10" : "Unlimited";
|
| 63 |
const hasSub = !!profile?.razorpay_subscription_id;
|
| 64 |
|
| 65 |
+
// Fetch API keys
|
| 66 |
+
const { data: apiKeys } = await supabase
|
| 67 |
+
.from("api_keys")
|
| 68 |
+
.select("id, name, key_prefix, calls_this_month, calls_limit, is_active, created_at")
|
| 69 |
+
.eq("user_id", user?.id)
|
| 70 |
+
.order("created_at", { ascending: false });
|
| 71 |
+
|
| 72 |
+
// Fetch team info
|
| 73 |
+
let team = null;
|
| 74 |
+
let teamMembers = 0;
|
| 75 |
+
if (profile?.team_id) {
|
| 76 |
+
const { data: t } = await supabase.from("teams").select("name, max_seats").eq("id", profile.team_id).single();
|
| 77 |
+
team = t;
|
| 78 |
+
const { count } = await supabase.from("profiles").select("id", { count: "exact", head: true }).eq("team_id", profile.team_id);
|
| 79 |
+
teamMembers = count || 0;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
return (
|
| 83 |
<div className="min-h-screen bg-white">
|
| 84 |
<div className="max-w-2xl mx-auto px-5 py-12">
|
|
|
|
| 98 |
<div className="border border-zinc-200 rounded-xl divide-y divide-zinc-100">
|
| 99 |
<div className="px-5 py-4 flex justify-between items-center">
|
| 100 |
<div><p className="text-sm font-medium">Email</p><p className="text-sm text-zinc-500">{user?.email}</p></div>
|
| 101 |
+
<Mail className="w-4 h-4 text-zinc-300" />
|
| 102 |
</div>
|
| 103 |
<div className="px-5 py-4 flex justify-between items-center">
|
| 104 |
<div><p className="text-sm font-medium">Name</p><p className="text-sm text-zinc-500">{profile?.full_name || "Not set"}</p></div>
|
| 105 |
</div>
|
| 106 |
+
<div className="px-5 py-4 flex justify-between items-center">
|
| 107 |
+
<div><p className="text-sm font-medium">Role</p><p className="text-sm text-zinc-500 capitalize flex items-center gap-1.5">
|
| 108 |
+
{isAdmin && <Crown className="w-3.5 h-3.5 text-amber-500" />}
|
| 109 |
+
{role}
|
| 110 |
+
{isAdmin && <span className="text-[10px] bg-amber-50 text-amber-700 border border-amber-200 px-1.5 py-0.5 rounded">Full access</span>}
|
| 111 |
+
</p></div>
|
| 112 |
+
<Shield className="w-4 h-4 text-zinc-300" />
|
| 113 |
+
</div>
|
| 114 |
+
<div className="px-5 py-4 flex justify-between items-center">
|
| 115 |
+
<div><p className="text-sm font-medium">Account ID</p><p className="text-xs text-zinc-400 font-mono">{user?.id}</p></div>
|
| 116 |
+
<Hash className="w-4 h-4 text-zinc-300" />
|
| 117 |
+
</div>
|
| 118 |
+
<div className="px-5 py-4 flex justify-between items-center">
|
| 119 |
+
<div><p className="text-sm font-medium">Joined</p><p className="text-sm text-zinc-500">{profile?.created_at ? new Date(profile.created_at).toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" }) : "—"}</p></div>
|
| 120 |
+
<Calendar className="w-4 h-4 text-zinc-300" />
|
| 121 |
+
</div>
|
| 122 |
+
<div className="px-5 py-4 flex justify-between items-center">
|
| 123 |
+
<div><p className="text-sm font-medium">Last Updated</p><p className="text-sm text-zinc-500">{profile?.updated_at ? new Date(profile.updated_at).toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" }) : "—"}</p></div>
|
| 124 |
+
</div>
|
| 125 |
</div>
|
| 126 |
</section>
|
| 127 |
|
| 128 |
+
{/* Admin Quick Access */}
|
| 129 |
+
{isAdmin && (
|
| 130 |
+
<section className="mb-8">
|
| 131 |
+
<div className="flex items-center gap-2 mb-3">
|
| 132 |
+
<Crown className="w-4 h-4 text-amber-500" />
|
| 133 |
+
<h2 className="text-sm font-medium text-amber-600 uppercase tracking-wider">Admin</h2>
|
| 134 |
+
</div>
|
| 135 |
+
<Link href="/admin" className="flex items-center gap-3 border border-amber-200 bg-amber-50/50 rounded-xl px-5 py-4 hover:bg-amber-50 transition-colors">
|
| 136 |
+
<div className="w-10 h-10 rounded-lg bg-amber-100 flex items-center justify-center">
|
| 137 |
+
<Crown className="w-5 h-5 text-amber-600" />
|
| 138 |
+
</div>
|
| 139 |
+
<div>
|
| 140 |
+
<p className="text-sm font-semibold text-amber-900">Open Admin Panel</p>
|
| 141 |
+
<p className="text-xs text-amber-600">Manage users, view all scans, teams, API keys, activity logs</p>
|
| 142 |
+
</div>
|
| 143 |
+
</Link>
|
| 144 |
+
</section>
|
| 145 |
+
)}
|
| 146 |
+
|
| 147 |
{/* Subscription */}
|
| 148 |
<section className="mb-8">
|
| 149 |
<div className="flex items-center gap-2 mb-3">
|
|
|
|
| 152 |
</div>
|
| 153 |
<div className="border border-zinc-200 rounded-xl divide-y divide-zinc-100">
|
| 154 |
<div className="px-5 py-4 flex justify-between items-center">
|
| 155 |
+
<div>
|
| 156 |
+
<p className="text-sm font-medium">Plan</p>
|
| 157 |
+
<p className="text-sm text-zinc-500 capitalize flex items-center gap-1.5">
|
| 158 |
+
{plan}
|
| 159 |
+
{isAdmin && <span className="text-[10px] bg-indigo-50 text-indigo-700 border border-indigo-200 px-1.5 py-0.5 rounded">Admin override</span>}
|
| 160 |
+
</p>
|
| 161 |
+
</div>
|
| 162 |
+
{!isAdmin && plan === "free" ? (
|
| 163 |
<Link href="/#pricing" className="text-sm font-medium border border-zinc-200 px-3 py-1.5 rounded-lg hover:bg-zinc-50 transition-colors">Upgrade</Link>
|
| 164 |
) : null}
|
| 165 |
</div>
|
| 166 |
<div className="px-5 py-4 flex justify-between items-center">
|
| 167 |
+
<div>
|
| 168 |
+
<p className="text-sm font-medium">Usage this month</p>
|
| 169 |
+
<p className="text-sm text-zinc-500">{used} / {limit} scans</p>
|
| 170 |
+
</div>
|
| 171 |
+
</div>
|
| 172 |
+
<div className="px-5 py-4 flex justify-between items-center">
|
| 173 |
+
<div>
|
| 174 |
+
<p className="text-sm font-medium">Features</p>
|
| 175 |
+
<div className="mt-1 flex flex-wrap gap-1.5">
|
| 176 |
+
{(isAdmin || plan !== "free") && <span className="text-[10px] bg-emerald-50 text-emerald-700 border border-emerald-200 px-1.5 py-0.5 rounded">Unlimited scans</span>}
|
| 177 |
+
{(isAdmin || plan !== "free") && <span className="text-[10px] bg-blue-50 text-blue-700 border border-blue-200 px-1.5 py-0.5 rounded">File upload</span>}
|
| 178 |
+
{(isAdmin || plan !== "free") && <span className="text-[10px] bg-purple-50 text-purple-700 border border-purple-200 px-1.5 py-0.5 rounded">PDF export</span>}
|
| 179 |
+
{(isAdmin || plan !== "free") && <span className="text-[10px] bg-indigo-50 text-indigo-700 border border-indigo-200 px-1.5 py-0.5 rounded">Comparison</span>}
|
| 180 |
+
<span className="text-[10px] bg-zinc-50 text-zinc-600 border border-zinc-200 px-1.5 py-0.5 rounded">41 clause types</span>
|
| 181 |
+
<span className="text-[10px] bg-zinc-50 text-zinc-600 border border-zinc-200 px-1.5 py-0.5 rounded">ML NER</span>
|
| 182 |
+
<span className="text-[10px] bg-zinc-50 text-zinc-600 border border-zinc-200 px-1.5 py-0.5 rounded">NLI</span>
|
| 183 |
+
<span className="text-[10px] bg-zinc-50 text-zinc-600 border border-zinc-200 px-1.5 py-0.5 rounded">Redlining</span>
|
| 184 |
+
<span className="text-[10px] bg-zinc-50 text-zinc-600 border border-zinc-200 px-1.5 py-0.5 rounded">OCR</span>
|
| 185 |
+
</div>
|
| 186 |
+
</div>
|
| 187 |
</div>
|
| 188 |
+
{hasSub && plan !== "free" && !isAdmin && (
|
| 189 |
<div className="px-5 py-4">
|
| 190 |
<form action={handleCancel}>
|
| 191 |
<button type="submit" className="flex items-center gap-2 text-sm text-red-600 font-medium border border-red-200 px-3 py-1.5 rounded-lg hover:bg-red-50 transition-colors">
|
|
|
|
| 199 |
</div>
|
| 200 |
</section>
|
| 201 |
|
| 202 |
+
{/* Team Info */}
|
| 203 |
+
{team && (
|
| 204 |
+
<section className="mb-8">
|
| 205 |
+
<div className="flex items-center gap-2 mb-3">
|
| 206 |
+
<Users className="w-4 h-4 text-zinc-400" />
|
| 207 |
+
<h2 className="text-sm font-medium text-zinc-500 uppercase tracking-wider">Team</h2>
|
| 208 |
+
</div>
|
| 209 |
+
<div className="border border-zinc-200 rounded-xl divide-y divide-zinc-100">
|
| 210 |
+
<div className="px-5 py-4 flex justify-between items-center">
|
| 211 |
+
<div><p className="text-sm font-medium">Team Name</p><p className="text-sm text-zinc-500">{team.name}</p></div>
|
| 212 |
+
<Link href="/dashboard-pages/team" className="text-sm font-medium text-indigo-600 hover:text-indigo-700">Manage →</Link>
|
| 213 |
+
</div>
|
| 214 |
+
<div className="px-5 py-4 flex justify-between items-center">
|
| 215 |
+
<div><p className="text-sm font-medium">Members</p><p className="text-sm text-zinc-500">{teamMembers} / {team.max_seats}</p></div>
|
| 216 |
+
</div>
|
| 217 |
+
</div>
|
| 218 |
+
</section>
|
| 219 |
+
)}
|
| 220 |
+
|
| 221 |
+
{/* API Keys */}
|
| 222 |
+
{(isAdmin || plan !== "free") && (
|
| 223 |
+
<section className="mb-8">
|
| 224 |
+
<div className="flex items-center gap-2 mb-3">
|
| 225 |
+
<Key className="w-4 h-4 text-zinc-400" />
|
| 226 |
+
<h2 className="text-sm font-medium text-zinc-500 uppercase tracking-wider">API Keys</h2>
|
| 227 |
+
</div>
|
| 228 |
+
<div className="border border-zinc-200 rounded-xl divide-y divide-zinc-100">
|
| 229 |
+
{apiKeys && apiKeys.length > 0 ? apiKeys.map((k: any) => (
|
| 230 |
+
<div key={k.id} className="px-5 py-3.5 flex justify-between items-center">
|
| 231 |
+
<div>
|
| 232 |
+
<p className="text-sm font-medium flex items-center gap-2">
|
| 233 |
+
{k.name}
|
| 234 |
+
<span className={`text-[10px] px-1.5 py-0.5 rounded ${k.is_active ? "bg-emerald-50 text-emerald-700 border border-emerald-200" : "bg-red-50 text-red-700 border border-red-200"}`}>
|
| 235 |
+
{k.is_active ? "Active" : "Revoked"}
|
| 236 |
+
</span>
|
| 237 |
+
</p>
|
| 238 |
+
<p className="text-xs text-zinc-400 font-mono mt-0.5">{k.key_prefix} · {k.calls_this_month}/{k.calls_limit} calls</p>
|
| 239 |
+
</div>
|
| 240 |
+
</div>
|
| 241 |
+
)) : (
|
| 242 |
+
<div className="px-5 py-6 text-center text-sm text-zinc-400">
|
| 243 |
+
No API keys yet.
|
| 244 |
+
</div>
|
| 245 |
+
)}
|
| 246 |
+
</div>
|
| 247 |
+
</section>
|
| 248 |
+
)}
|
| 249 |
+
|
| 250 |
{/* Sign out */}
|
| 251 |
+
<section className="mb-8">
|
| 252 |
<form action={handleSignOut}>
|
| 253 |
+
<button type="submit" className="flex items-center gap-2 text-sm text-zinc-500 font-medium border border-zinc-200 px-4 py-2.5 rounded-lg hover:bg-zinc-50 transition-colors w-full justify-center">
|
| 254 |
<LogOut className="w-4 h-4" />
|
| 255 |
Sign out
|
| 256 |
</button>
|
| 257 |
</form>
|
| 258 |
</section>
|
| 259 |
+
|
| 260 |
+
{/* Danger Zone */}
|
| 261 |
+
{!isAdmin && (
|
| 262 |
+
<section>
|
| 263 |
+
<div className="flex items-center gap-2 mb-3">
|
| 264 |
+
<AlertTriangle className="w-4 h-4 text-red-400" />
|
| 265 |
+
<h2 className="text-sm font-medium text-red-400 uppercase tracking-wider">Danger Zone</h2>
|
| 266 |
+
</div>
|
| 267 |
+
<div className="border border-red-200 rounded-xl p-5 bg-red-50/30">
|
| 268 |
+
<p className="text-sm text-zinc-700 font-medium">Delete account</p>
|
| 269 |
+
<p className="text-xs text-zinc-500 mt-1 mb-3">Permanently delete your account, all analyses, and API keys. This cannot be undone.</p>
|
| 270 |
+
<form action={handleDeleteAccount}>
|
| 271 |
+
<button type="submit" className="flex items-center gap-2 text-sm text-red-600 font-medium border border-red-300 bg-white px-3 py-1.5 rounded-lg hover:bg-red-50 transition-colors">
|
| 272 |
+
<Trash2 className="w-3.5 h-3.5" />
|
| 273 |
+
Delete my account
|
| 274 |
+
</button>
|
| 275 |
+
</form>
|
| 276 |
+
</div>
|
| 277 |
+
</section>
|
| 278 |
+
)}
|
| 279 |
</div>
|
| 280 |
</div>
|
| 281 |
);
|