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 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 | 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 30x 30x 30x 30x 30x 30x 30x 1x 1x 1x 28x 28x 28x 28x 28x 30x 1x 1x 27x 30x 1x 1x 1x 1x 1x 1x 30x 29x 29x 30x 30x 73x 73x 30x 30x 30x 30x 1x 1x 1x 30x 29x 30x 30x 30x 30x 30x 73x 73x 73x 73x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 2x 2x 2x 2x 2x 3x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 73x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 73x 73x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 73x 30x 30x 30x 30x 30x 73x 2x 2x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 73x 73x 73x 73x 73x 40x 73x 73x 73x 73x 73x 73x 73x 40x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 38x 2x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 40x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 36x 36x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 3x 3x 3x 37x 37x 37x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x 1x 1x 39x 73x 73x 73x 73x 73x 73x 73x 73x 73x | 'use client';
import { useState, useEffect, useRef } from 'react';
import { useRouter } from 'next/navigation';
import {
Loader2,
Upload,
LogOut,
Camera,
Eye,
EyeOff,
MessageCircle,
Mail,
User,
Trash2,
AlertTriangle,
Lock,
Key,
CheckCircle,
} from 'lucide-react';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
import { Switch } from '@/components/ui/switch';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { createClient } from '@/lib/supabase/client';
import { useToast } from '@/hooks/use-toast';
import { getInitials } from '@/lib/utils';
import type { Profile } from '@/types/database';
interface PasswordStatus {
hasPassword: boolean;
hasRealEmail: boolean;
hasPhoneOnly: boolean;
email: string | null;
canSetPassword: boolean;
}
export default function SettingsPage() {
const [isLoading, setIsLoading] = useState(true);
const [profile, setProfile] = useState<Profile | null>(null);
const [isUploading, setIsUploading] = useState(false);
const [isSaving, setIsSaving] = useState(false);
const [isSigningOut, setIsSigningOut] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
// Password management state
const [passwordStatus, setPasswordStatus] = useState<PasswordStatus | null>(null);
const [isLoadingPassword, setIsLoadingPassword] = useState(true);
const [showPasswordForm, setShowPasswordForm] = useState(false);
const [currentPassword, setCurrentPassword] = useState('');
const [newPassword, setNewPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');
const [isUpdatingPassword, setIsUpdatingPassword] = useState(false);
const [showCurrentPassword, setShowCurrentPassword] = useState(false);
const [showNewPassword, setShowNewPassword] = useState(false);
const fileInputRef = useRef<HTMLInputElement>(null);
const router = useRouter();
const { toast } = useToast();
useEffect(() => {
const fetchProfile = async () => {
try {
const supabase = createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) {
router.push('/login');
return;
}
const { data: profileData, error } = await supabase
.from('profiles')
.select('*')
.eq('user_id', user.id)
.single();
if (error) {
throw error;
}
setProfile(profileData);
} catch (error) {
console.error('Error fetching profile:', error);
toast({
variant: 'destructive',
title: 'Error',
description: 'Failed to load settings.',
});
} finally {
setIsLoading(false);
}
};
fetchProfile();
}, [router, toast]);
// Fetch password status
useEffect(() => {
const fetchPasswordStatus = async () => {
try {
const response = await fetch('/api/auth/password/check');
if (response.ok) {
const data = await response.json();
setPasswordStatus(data);
}
} catch (error) {
console.error('Error fetching password status:', error);
} finally {
setIsLoadingPassword(false);
}
};
fetchPasswordStatus();
}, []);
const handleAvatarClick = () => {
fileInputRef.current?.click();
};
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (!file || !profile) return;
// Validate file type
const validTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
if (!validTypes.includes(file.type)) {
toast({
variant: 'destructive',
title: 'Invalid File Type',
description: 'Please upload a JPEG, PNG, GIF, or WebP image.',
});
return;
}
// Validate file size (max 5MB)
if (file.size > 5 * 1024 * 1024) {
toast({
variant: 'destructive',
title: 'File Too Large',
description: 'Please upload an image smaller than 5MB.',
});
return;
}
setIsUploading(true);
try {
const supabase = createClient();
// Generate unique filename
const fileExt = file.name.split('.').pop();
const fileName = `${profile.user_id}/${profile.id}-${Date.now()}.${fileExt}`;
// Upload to Supabase Storage (avatars bucket)
const { error: uploadError } = await supabase.storage.from('avatars').upload(fileName, file, {
cacheControl: '3600',
upsert: true,
});
if (uploadError) {
console.error('Storage upload error:', uploadError);
throw uploadError;
}
// Get public URL
const { data: urlData } = supabase.storage.from('avatars').getPublicUrl(fileName);
const avatarUrl = urlData.publicUrl;
// Update profile with new avatar URL
const { error: updateError } = await supabase
.from('profiles')
.update({
avatar_url: avatarUrl,
updated_at: new Date().toISOString(),
})
.eq('id', profile.id);
if (updateError) {
throw updateError;
}
setProfile((prev) => (prev ? { ...prev, avatar_url: avatarUrl } : null));
toast({
title: 'Avatar Updated',
description: 'Your profile photo has been updated.',
});
} catch (error) {
console.error('Error uploading avatar:', error);
toast({
variant: 'destructive',
title: 'Upload Failed',
description: 'Failed to upload avatar. Please try again.',
});
} finally {
setIsUploading(false);
// Reset file input
if (fileInputRef.current) {
fileInputRef.current.value = '';
}
}
};
const updateSetting = async (field: keyof Profile, value: boolean) => {
if (!profile) return;
setIsSaving(true);
try {
const supabase = createClient();
const { error } = await supabase
.from('profiles')
.update({
[field]: value,
updated_at: new Date().toISOString(),
})
.eq('id', profile.id);
if (error) {
throw error;
}
setProfile((prev) => (prev ? { ...prev, [field]: value } : null));
toast({
title: 'Settings Updated',
description: 'Your settings have been saved.',
});
} catch (error) {
console.error('Error updating setting:', error);
toast({
variant: 'destructive',
title: 'Error',
description: 'Failed to update settings. Please try again.',
});
} finally {
setIsSaving(false);
}
};
const handleSignOut = async () => {
setIsSigningOut(true);
try {
const supabase = createClient();
const { error } = await supabase.auth.signOut();
if (error) {
throw error;
}
router.push('/login');
} catch (error) {
console.error('Error signing out:', error);
toast({
variant: 'destructive',
title: 'Error',
description: 'Failed to sign out. Please try again.',
});
setIsSigningOut(false);
}
};
const handlePasswordUpdate = async (e: React.FormEvent) => {
e.preventDefault();
// Validation
if (newPassword.length < 8) {
toast({
variant: 'destructive',
title: 'Invalid Password',
description: 'Password must be at least 8 characters.',
});
return;
}
if (newPassword !== confirmPassword) {
toast({
variant: 'destructive',
title: "Passwords Don't Match",
description: 'New password and confirmation must match.',
});
return;
}
setIsUpdatingPassword(true);
try {
const response = await fetch('/api/auth/password/update', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
currentPassword: passwordStatus?.hasPassword ? currentPassword : undefined,
newPassword,
}),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Failed to update password');
}
toast({
title: 'Success',
description: data.message,
});
// Reset form and update status
setCurrentPassword('');
setNewPassword('');
setConfirmPassword('');
setShowPasswordForm(false);
setPasswordStatus((prev) =>
prev ? { ...prev, hasPassword: true, canSetPassword: false } : null
);
} catch (error) {
console.error('Password update error:', error);
toast({
variant: 'destructive',
title: 'Error',
description: error instanceof Error ? error.message : 'Failed to update password.',
});
} finally {
setIsUpdatingPassword(false);
}
};
const handleDeleteAccount = async () => {
setIsDeleting(true);
try {
const response = await fetch('/api/account/delete/request', {
method: 'POST',
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Failed to request account deletion');
}
setDeleteDialogOpen(false);
toast({
title: 'Confirmation Email Sent',
description: 'Please check your inbox to confirm account deletion.',
});
} catch (error) {
console.error('Error requesting account deletion:', error);
toast({
variant: 'destructive',
title: 'Error',
description: error instanceof Error ? error.message : 'Failed to request account deletion.',
});
} finally {
setIsDeleting(false);
}
};
if (isLoading) {
return (
<div className="flex min-h-[400px] items-center justify-center">
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
</div>
);
}
if (!profile) {
return null;
}
return (
<div className="space-y-6">
<div>
<h1 className="text-3xl font-bold">Settings</h1>
<p className="text-muted-foreground">Manage your profile settings and preferences</p>
</div>
{/* Profile Photo */}
<Card>
<CardHeader>
<CardTitle>Profile Photo</CardTitle>
<CardDescription>Upload a photo to personalize your profile</CardDescription>
</CardHeader>
<CardContent>
<div className="flex items-center gap-6">
<div className="relative">
<Avatar className="h-24 w-24">
<AvatarImage
src={profile.avatar_url || undefined}
alt={profile.display_name || 'Avatar'}
/>
<AvatarFallback className="text-2xl">
{profile.display_name ? (
getInitials(profile.display_name)
) : (
<User className="h-10 w-10" />
)}
</AvatarFallback>
</Avatar>
<button
onClick={handleAvatarClick}
disabled={isUploading}
className="absolute -bottom-1 -right-1 flex h-8 w-8 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg transition-transform hover:scale-105 disabled:opacity-50"
>
{isUploading ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<Camera className="h-4 w-4" />
)}
</button>
<input
ref={fileInputRef}
type="file"
accept="image/jpeg,image/png,image/gif,image/webp"
className="hidden"
onChange={handleFileChange}
/>
</div>
<div className="space-y-1">
<p className="text-sm font-medium">Upload a new photo</p>
<p className="text-xs text-muted-foreground">JPEG, PNG, GIF, or WebP. Max 5MB.</p>
<Button
variant="outline"
size="sm"
onClick={handleAvatarClick}
disabled={isUploading}
>
<Upload className="mr-2 h-4 w-4" />
{isUploading ? 'Uploading...' : 'Choose File'}
</Button>
</div>
</div>
</CardContent>
</Card>
{/* Visibility Settings */}
<Card>
<CardHeader>
<CardTitle>Visibility Settings</CardTitle>
<CardDescription>Control what visitors can see on your profile</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
{profile.is_published ? (
<Eye className="h-5 w-5 text-green-500" />
) : (
<EyeOff className="h-5 w-5 text-muted-foreground" />
)}
<div>
<Label htmlFor="is_published" className="text-base font-medium">
Profile Published
</Label>
<p className="text-sm text-muted-foreground">
When enabled, your profile is visible to the public
</p>
</div>
</div>
<Switch
id="is_published"
checked={profile.is_published}
onCheckedChange={(checked) => updateSetting('is_published', checked)}
disabled={isSaving}
/>
</div>
<div className="border-t pt-6">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<MessageCircle className="h-5 w-5 text-[#25d366]" />
<div>
<Label htmlFor="show_whatsapp" className="text-base font-medium">
Show WhatsApp Number
</Label>
<p className="text-sm text-muted-foreground">
Allow visitors to see and contact you via WhatsApp
</p>
</div>
</div>
<Switch
id="show_whatsapp"
checked={profile.show_whatsapp}
onCheckedChange={(checked) => updateSetting('show_whatsapp', checked)}
disabled={isSaving}
/>
</div>
</div>
<div className="border-t pt-6">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<Mail className="h-5 w-5 text-blue-500" />
<div>
<Label htmlFor="show_email" className="text-base font-medium">
Show Email Address
</Label>
<p className="text-sm text-muted-foreground">
Allow visitors to see and contact you via email
</p>
</div>
</div>
<Switch
id="show_email"
checked={profile.show_email}
onCheckedChange={(checked) => updateSetting('show_email', checked)}
disabled={isSaving}
/>
</div>
</div>
</CardContent>
</Card>
{/* Security - Password Management */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Lock className="h-5 w-5" />
Security
</CardTitle>
<CardDescription>Manage your password and account security</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
{isLoadingPassword ? (
<div className="flex items-center gap-2 text-muted-foreground">
<Loader2 className="h-4 w-4 animate-spin" />
Loading security settings...
</div>
) : passwordStatus ? (
<>
{/* Password Status */}
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
{passwordStatus.hasPassword ? (
<CheckCircle className="h-5 w-5 text-green-500" />
) : (
<Key className="h-5 w-5 text-amber-500" />
)}
<div>
<p className="font-medium">
{passwordStatus.hasPassword ? 'Password Set' : 'No Password Set'}
</p>
<p className="text-sm text-muted-foreground">
{passwordStatus.hasPassword
? 'You can sign in with your email and password'
: passwordStatus.hasRealEmail
? 'Set a password to sign in without magic link'
: 'Verify your email first to set a password'}
</p>
</div>
</div>
{passwordStatus.hasRealEmail && (
<Button
variant="outline"
size="sm"
onClick={() => setShowPasswordForm(!showPasswordForm)}
>
{passwordStatus.hasPassword ? 'Change Password' : 'Set Password'}
</Button>
)}
</div>
{/* Password Form */}
{showPasswordForm && passwordStatus.hasRealEmail && (
<form onSubmit={handlePasswordUpdate} className="space-y-4 border-t pt-4">
{passwordStatus.hasPassword && (
<div className="space-y-2">
<Label htmlFor="current-password">Current Password</Label>
<div className="relative">
<Input
id="current-password"
type={showCurrentPassword ? 'text' : 'password'}
value={currentPassword}
onChange={(e) => setCurrentPassword(e.target.value)}
placeholder="Enter current password"
required
/>
<button
type="button"
onClick={() => setShowCurrentPassword(!showCurrentPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
>
{showCurrentPassword ? (
<EyeOff className="h-4 w-4" />
) : (
<Eye className="h-4 w-4" />
)}
</button>
</div>
</div>
)}
<div className="space-y-2">
<Label htmlFor="new-password">
{passwordStatus.hasPassword ? 'New Password' : 'Password'}
</Label>
<div className="relative">
<Input
id="new-password"
type={showNewPassword ? 'text' : 'password'}
value={newPassword}
onChange={(e) => setNewPassword(e.target.value)}
placeholder="Enter new password"
minLength={8}
required
/>
<button
type="button"
onClick={() => setShowNewPassword(!showNewPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
>
{showNewPassword ? (
<EyeOff className="h-4 w-4" />
) : (
<Eye className="h-4 w-4" />
)}
</button>
</div>
<p className="text-xs text-muted-foreground">Must be at least 8 characters</p>
</div>
<div className="space-y-2">
<Label htmlFor="confirm-password">Confirm Password</Label>
<Input
id="confirm-password"
type="password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
placeholder="Confirm new password"
minLength={8}
required
/>
</div>
<div className="flex gap-2">
<Button
type="button"
variant="outline"
onClick={() => {
setShowPasswordForm(false);
setCurrentPassword('');
setNewPassword('');
setConfirmPassword('');
}}
disabled={isUpdatingPassword}
>
Cancel
</Button>
<Button type="submit" disabled={isUpdatingPassword}>
{isUpdatingPassword ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
{passwordStatus.hasPassword ? 'Changing...' : 'Setting...'}
</>
) : passwordStatus.hasPassword ? (
'Change Password'
) : (
'Set Password'
)}
</Button>
</div>
</form>
)}
{/* Email Info */}
{passwordStatus.email && (
<div className="flex items-center justify-between border-t pt-4">
<div className="flex items-center gap-3">
<Mail className="h-5 w-5 text-blue-500" />
<div>
<p className="font-medium">Email</p>
<p className="text-sm text-muted-foreground">{passwordStatus.email}</p>
</div>
</div>
</div>
)}
{/* Phone-only users info */}
{passwordStatus.hasPhoneOnly && !passwordStatus.hasRealEmail && (
<div className="rounded-lg bg-amber-50 p-4 dark:bg-amber-950/30">
<p className="text-sm text-amber-800 dark:text-amber-200">
You signed up with your phone number. To set a password, first verify your email
address in the{' '}
<a href="/settings/verification/email" className="font-medium underline">
Verification Settings
</a>
.
</p>
</div>
)}
</>
) : (
<p className="text-sm text-muted-foreground">
Unable to load security settings. Please refresh the page.
</p>
)}
</CardContent>
</Card>
{/* Account */}
<Card>
<CardHeader>
<CardTitle>Account</CardTitle>
<CardDescription>Manage your account settings</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
{/* Account Info */}
<div className="space-y-4">
<div className="flex items-center justify-between py-2">
<div>
<p className="font-medium">Username</p>
<p className="text-sm text-muted-foreground">@{profile.username}</p>
</div>
<code className="rounded bg-muted px-2 py-1 text-sm">
proofid.in/{profile.username}
</code>
</div>
<div className="flex items-center justify-between border-t py-2">
<div>
<p className="font-medium">Identity Code</p>
<p className="text-sm text-muted-foreground">Your unique ProofID identifier</p>
</div>
<code className="identity-code rounded bg-primary/10 px-2 py-1 text-sm text-primary">
{profile.identity_code}
</code>
</div>
<div className="flex items-center justify-between border-t py-2">
<div>
<p className="font-medium">Subscription</p>
<p className="text-sm text-muted-foreground">
Current plan:{' '}
{profile.subscription_tier?.charAt(0).toUpperCase() +
profile.subscription_tier?.slice(1) || 'Free'}
</p>
</div>
<Button variant="outline" size="sm" asChild>
<a href="/subscription">Manage</a>
</Button>
</div>
</div>
{/* Sign Out */}
<div className="flex items-center justify-between border-t pt-4">
<div>
<p className="font-medium">Sign Out</p>
<p className="text-sm text-muted-foreground">
Sign out of your account on this device
</p>
</div>
<Button variant="destructive" onClick={handleSignOut} disabled={isSigningOut}>
{isSigningOut ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Signing out...
</>
) : (
<>
<LogOut className="mr-2 h-4 w-4" />
Sign Out
</>
)}
</Button>
</div>
</CardContent>
</Card>
{/* Danger Zone */}
<Card className="border-destructive/50">
<CardHeader>
<CardTitle className="text-destructive">Danger Zone</CardTitle>
<CardDescription>Irreversible actions for your account</CardDescription>
</CardHeader>
<CardContent>
<div className="flex items-center justify-between">
<div>
<p className="font-medium">Delete Account</p>
<p className="text-sm text-muted-foreground">
Permanently delete your account and all data
</p>
</div>
<Dialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
<DialogTrigger asChild>
<Button
variant="outline"
className="border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground"
>
<Trash2 className="mr-2 h-4 w-4" />
Delete Account
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle className="flex items-center gap-2 text-destructive">
<AlertTriangle className="h-5 w-5" />
Delete Account
</DialogTitle>
<DialogDescription>
This action is permanent and cannot be undone.
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="rounded-lg bg-destructive/10 p-4">
<p className="text-sm font-medium text-destructive">
Deleting your account will permanently remove:
</p>
<ul className="mt-2 list-inside list-disc text-sm text-destructive/80">
<li>Your profile and identity code</li>
<li>All work samples and packages</li>
<li>All testimonials and requests</li>
<li>Your subscription (no refund)</li>
</ul>
</div>
<p className="text-sm text-muted-foreground">
We'll send a confirmation email to verify this request.
</p>
</div>
<DialogFooter>
<Button
variant="outline"
onClick={() => setDeleteDialogOpen(false)}
disabled={isDeleting}
>
Cancel
</Button>
<Button variant="destructive" onClick={handleDeleteAccount} disabled={isDeleting}>
{isDeleting ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Sending...
</>
) : (
'Send Confirmation Email'
)}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
</CardContent>
</Card>
</div>
);
}
|