Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | 1x 1x 21x 21x 21x 21x 21x 21x 21x 21x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 21x 90x 36x 90x 18x 18x 18x 36x 36x 36x 36x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 20x 20x 20x 20x 21x 21x 21x 21x 21x 21x 21x 21x 20x 20x 20x 20x 22x 22x 22x 21x 22x 20x 20x 20x 20x 20x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 20x 20x 20x 22x 1x 1x 1x 22x 22x 22x 22x 22x 22x 22x 22x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 22x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 19x 19x 19x 19x 19x 19x 19x 19x 19x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 1x 1x 1x 1x 1x 1x 1x 1x 20x 20x 20x 22x 22x 22x 22x 22x 22x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 22x 22x 22x 22x 22x 22x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 22x 22x 22x 22x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 2x 2x 2x 22x 22x | // Force dynamic rendering - always fetch fresh user data
export const dynamic = 'force-dynamic';
import { Suspense } from 'react';
import Link from 'next/link';
import {
Eye,
MousePointer,
MessageCircle,
TrendingUp,
ArrowRight,
ExternalLink,
ShieldCheck,
BadgeCheck,
CheckCircle,
Landmark,
Clock,
} from 'lucide-react';
import { createClient } from '@/lib/supabase/server';
import { getUser } from '@/lib/supabase/server';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { IdentityBadge } from '@/components/profile/IdentityBadge';
import { EmailVerifiedToast } from '@/components/dashboard/EmailVerifiedToast';
async function getDashboardData(userId: string) {
const supabase = await createClient();
const { data: profile } = await supabase
.from('profiles')
.select('*')
.eq('user_id', userId)
.single();
if (!profile) return null;
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
const { data: analytics } = await supabase
.from('analytics')
.select('event_type')
.eq('profile_id', profile.id)
.gte('created_at', thirtyDaysAgo.toISOString());
const stats = {
views: 0,
clicks: 0,
whatsappClicks: 0,
};
analytics?.forEach((event) => {
if (event.event_type === 'profile_view') {
stats.views++;
} else if (event.event_type === 'whatsapp_click') {
stats.whatsappClicks++;
stats.clicks++;
} else if (
['sample_click', 'email_click', 'linkedin_click', 'website_click'].includes(event.event_type)
) {
stats.clicks++;
}
});
const [
samplesResult,
testimonialsResult,
packagesResult,
verificationsResult,
verificationTypesResult,
] = await Promise.all([
supabase.from('samples').select('id', { count: 'exact' }).eq('profile_id', profile.id),
supabase.from('testimonials').select('id', { count: 'exact' }).eq('profile_id', profile.id),
supabase.from('packages').select('id', { count: 'exact' }).eq('profile_id', profile.id),
supabase.from('user_verifications').select('*, verification_types(*)').eq('user_id', userId),
supabase.from('verification_types').select('*').eq('is_active', true).order('display_order'),
]);
return {
profile,
stats,
counts: {
samples: samplesResult.count || 0,
testimonials: testimonialsResult.count || 0,
packages: packagesResult.count || 0,
},
verifications: verificationsResult.data || [],
verificationTypes: verificationTypesResult.data || [],
};
}
function isRealEmail(email: string | undefined | null): boolean {
if (!email) return false;
return !email.endsWith('@proofid.internal');
}
export default async function DashboardPage() {
const user = await getUser();
if (!user) return null;
const data = await getDashboardData(user.id);
if (!data) return null;
const { profile, stats, counts, verifications } = data;
const completedVerifications = verifications.filter(
(v: { status: string }) => v.status === 'verified'
);
const hasRealEmailVerified = isRealEmail(user.email) && !!user.email_confirmed_at;
const isGoogleUser = user.app_metadata?.provider === 'google';
const statCards = [
{
title: 'Profile Views',
value: stats.views,
description: 'Last 30 days',
icon: Eye,
color: 'text-blue-500',
},
{
title: 'Total Clicks',
value: stats.clicks,
description: 'Last 30 days',
icon: MousePointer,
color: 'text-green-500',
},
{
title: 'WhatsApp Clicks',
value: stats.whatsappClicks,
description: 'Last 30 days',
icon: MessageCircle,
color: 'text-emerald-500',
},
{
title: 'CTR',
value: stats.views > 0 ? `${((stats.clicks / stats.views) * 100).toFixed(1)}%` : '0%',
description: 'Click-through rate',
icon: TrendingUp,
color: 'text-purple-500',
},
];
const quickActions = [
{
title: 'Add Work Sample',
description: `${counts.samples} samples added`,
href: '/samples',
action: 'Add Sample',
},
{
title: 'Add Testimonial',
description: `${counts.testimonials} testimonials`,
href: '/testimonials',
action: 'Add Testimonial',
},
{
title: 'Add Package',
description: `${counts.packages} packages`,
href: '/packages',
action: 'Add Package',
},
];
return (
<div className="space-y-8">
<Suspense fallback={null}>
<EmailVerifiedToast />
</Suspense>
{/* Welcome Header */}
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
<div>
<h1 className="text-3xl font-bold">{`Welcome back, ${profile.display_name}!`}</h1>
<p className="text-muted-foreground">Here is an overview of your ProofID profile.</p>
</div>
<Button asChild>
<Link href={`/${profile.username}`} target="_blank">
View Public Profile
<ExternalLink className="ml-2 h-4 w-4" />
</Link>
</Button>
</div>
{/* Identity Card */}
<Card>
<CardHeader>
<CardTitle>Your Identity</CardTitle>
<CardDescription>Share this with recruiters and clients</CardDescription>
</CardHeader>
<CardContent>
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
<div className="space-y-2">
<div className="flex items-center gap-2 text-sm">
<span className="text-muted-foreground">Profile URL:</span>
<code className="rounded bg-muted px-2 py-1">proofid.in/{profile.username}</code>
</div>
<div className="flex items-center gap-2 text-sm">
<span className="text-muted-foreground">Identity Code:</span>
<IdentityBadge code={profile.identity_code} />
</div>
</div>
<div className="flex items-center gap-2 text-sm">
<span className="text-muted-foreground">Verification URL:</span>
<code className="rounded bg-muted px-2 py-1 text-xs">
proofid.in/verify/{profile.identity_code}
</code>
</div>
</div>
</CardContent>
</Card>
{/* Verification Status Card */}
<Card>
<CardHeader>
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div>
<CardTitle className="flex items-center gap-2">
<ShieldCheck className="h-5 w-5 text-primary" />
Verification Status
</CardTitle>
<CardDescription>Increase trust with verified badges on your profile</CardDescription>
</div>
<div className="flex flex-wrap gap-2">
{hasRealEmailVerified && (
<Badge className="shrink-0 border-green-200 bg-green-500/10 text-green-600">
<BadgeCheck className="mr-1 h-3 w-3" />
Email Verified
</Badge>
)}
{user.phone_confirmed_at && (
<Badge className="shrink-0 border-blue-200 bg-blue-500/10 text-blue-600">
<BadgeCheck className="mr-1 h-3 w-3" />
Phone Verified
</Badge>
)}
{!hasRealEmailVerified && !user.phone_confirmed_at && (
<Badge variant="outline" className="text-muted-foreground">
Not Verified
</Badge>
)}
</div>
</div>
</CardHeader>
<CardContent>
<div className="space-y-4">
<div className="grid gap-3 sm:grid-cols-2">
{/* Email Verification */}
{hasRealEmailVerified ? (
<div className="flex items-center justify-between rounded-lg border border-green-500/30 bg-green-500/10 p-3 dark:border-green-400/30 dark:bg-green-400/10">
<div>
<p className="text-sm font-medium text-green-700 dark:text-green-400">
Email Verified
</p>
<p className="text-xs text-green-600/70 dark:text-green-500/70">
{isGoogleUser ? 'Email confirmed via Google' : 'Email address confirmed'}
</p>
</div>
<Badge className="bg-green-500 text-white">
<BadgeCheck className="mr-1 h-3 w-3" />
Verified
</Badge>
</div>
) : (
<div className="flex items-center justify-between rounded-lg border p-3">
<div>
<p className="text-sm font-medium">Email Verification</p>
<p className="text-xs text-muted-foreground">
{isRealEmail(user.email) ? 'Confirm your email' : 'Add & verify email'}
</p>
</div>
<Button size="sm" variant="outline" asChild>
<Link href="/settings/verification/email">
{isRealEmail(user.email) ? 'Verify' : 'Add Email'}
</Link>
</Button>
</div>
)}
{/* Phone Verification */}
{user.phone_confirmed_at ? (
<div className="flex items-center justify-between rounded-lg border border-green-500/30 bg-green-500/10 p-3 dark:border-green-400/30 dark:bg-green-400/10">
<div>
<p className="text-sm font-medium text-green-700 dark:text-green-400">
Phone Verified
</p>
<p className="text-xs text-green-600/70 dark:text-green-500/70">
Phone number confirmed
</p>
</div>
<Badge className="bg-green-500 text-white">
<BadgeCheck className="mr-1 h-3 w-3" />
Verified
</Badge>
</div>
) : (
<div className="flex items-center justify-between rounded-lg border p-3">
<div>
<p className="text-sm font-medium">Phone Verification</p>
<p className="text-xs text-muted-foreground">Verify via OTP</p>
</div>
<Button size="sm" variant="outline" asChild>
<Link href="/settings/verification/phone">Verify</Link>
</Button>
</div>
)}
{/* Aadhaar - Coming Soon */}
<div className="flex items-center justify-between rounded-lg border border-dashed border-muted-foreground/30 bg-muted/30 p-3 opacity-70">
<div>
<p className="text-sm font-medium text-muted-foreground">Aadhaar Verification</p>
<p className="text-xs text-muted-foreground/70">Verify via DigiLocker</p>
</div>
<Badge
variant="outline"
className="border-amber-300 bg-amber-50 text-amber-700 dark:border-amber-700 dark:bg-amber-950/30 dark:text-amber-400"
>
<Clock className="mr-1 h-3 w-3" />
Coming Soon
</Badge>
</div>
{/* PAN - Coming Soon */}
<div className="flex items-center justify-between rounded-lg border border-dashed border-muted-foreground/30 bg-muted/30 p-3 opacity-70">
<div>
<p className="text-sm font-medium text-muted-foreground">PAN Verification</p>
<p className="text-xs text-muted-foreground/70">Verify PAN card</p>
</div>
<Badge
variant="outline"
className="border-amber-300 bg-amber-50 text-amber-700 dark:border-amber-700 dark:bg-amber-950/30 dark:text-amber-400"
>
<Clock className="mr-1 h-3 w-3" />
Coming Soon
</Badge>
</div>
</div>
{/* Composite Verification Badges */}
{(() => {
const verificationCodes = new Set(
completedVerifications.map(
(v: { verification_types: { code?: string } | null }) =>
v.verification_types?.code
)
);
const accountVerified = hasRealEmailVerified && !!user.phone_confirmed_at;
const hasAadhaar = verificationCodes.has('aadhaar');
const hasPan = verificationCodes.has('pan');
const hasLocalId =
verificationCodes.has('passport') ||
verificationCodes.has('driving_license') ||
verificationCodes.has('voter_id');
const governmentVerified = hasAadhaar && hasPan && hasLocalId;
if (!accountVerified && !governmentVerified) return null;
return (
<div className="border-t pt-3">
<p className="mb-2 text-sm font-medium">Your Verification Badges</p>
<div className="flex flex-wrap gap-2">
{accountVerified && (
<Badge className="border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-800 dark:bg-blue-950/30 dark:text-blue-300">
<CheckCircle className="mr-1.5 h-3.5 w-3.5" />
Account Verified
</Badge>
)}
{governmentVerified && (
<Badge className="border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-800 dark:bg-emerald-950/30 dark:text-emerald-300">
<Landmark className="mr-1.5 h-3.5 w-3.5" />
Government Verified
</Badge>
)}
</div>
</div>
);
})()}
</div>
</CardContent>
</Card>
{/* Stats Grid */}
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
{statCards.map((stat) => (
<Card key={stat.title}>
<CardContent className="pt-6">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-muted-foreground">{stat.title}</p>
<p className="text-3xl font-bold">{stat.value}</p>
<p className="text-xs text-muted-foreground">{stat.description}</p>
</div>
<stat.icon className={`h-8 w-8 ${stat.color}`} />
</div>
</CardContent>
</Card>
))}
</div>
{/* Quick Actions */}
<div>
<h2 className="mb-4 text-xl font-semibold">Quick Actions</h2>
<div className="grid gap-4 sm:grid-cols-3">
{quickActions.map((action) => (
<Card key={action.title} className="card-hover">
<CardContent className="flex items-center justify-between pt-6">
<div>
<p className="font-medium">{action.title}</p>
<p className="text-sm text-muted-foreground">{action.description}</p>
</div>
<Button variant="outline" size="sm" asChild>
<Link href={action.href}>
{action.action}
<ArrowRight className="ml-1 h-3 w-3" />
</Link>
</Button>
</CardContent>
</Card>
))}
</div>
</div>
{/* Profile Completion Tips */}
{(counts.samples === 0 || counts.testimonials === 0 || !profile.whatsapp) && (
<Card className="border-primary/50 bg-primary/5">
<CardHeader>
<CardTitle className="text-lg">Complete Your Profile</CardTitle>
<CardDescription>Profiles with more content get more engagement</CardDescription>
</CardHeader>
<CardContent>
<ul className="space-y-2 text-sm">
{counts.samples === 0 && (
<li className="flex items-center gap-2">
<span className="h-2 w-2 rounded-full bg-yellow-500" />
<span>Add your first work sample to showcase your skills</span>
</li>
)}
{counts.testimonials === 0 && (
<li className="flex items-center gap-2">
<span className="h-2 w-2 rounded-full bg-yellow-500" />
<span>Add a testimonial to build trust with potential clients</span>
</li>
)}
{!profile.whatsapp && (
<li className="flex items-center gap-2">
<span className="h-2 w-2 rounded-full bg-yellow-500" />
<span>Add your WhatsApp number for direct client contact</span>
</li>
)}
</ul>
</CardContent>
</Card>
)}
</div>
);
}
|