126 lines
4.4 KiB
TypeScript
126 lines
4.4 KiB
TypeScript
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|||
|
|
import { Button } from '@/components/ui/button';
|
||
|
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||
|
|
import { useAuth } from '@/hooks/useAuth';
|
||
|
|
import { useNavigate } from 'react-router-dom';
|
||
|
|
import { LogOut, User as UserIcon, Mail, Phone } from 'lucide-react';
|
||
|
|
import { useToast } from '@/components/ui/use-toast';
|
||
|
|
|
||
|
|
export default function AccountPage() {
|
||
|
|
const { user, signOut } = useAuth();
|
||
|
|
const navigate = useNavigate();
|
||
|
|
const { toast } = useToast();
|
||
|
|
|
||
|
|
const handleSignOut = async () => {
|
||
|
|
try {
|
||
|
|
await signOut();
|
||
|
|
toast({
|
||
|
|
title: 'خروج موفق',
|
||
|
|
description: 'با موفقیت خارج شدید'
|
||
|
|
});
|
||
|
|
navigate('/');
|
||
|
|
} catch (error) {
|
||
|
|
toast({
|
||
|
|
title: 'خطا',
|
||
|
|
description: 'خطا در خروج از حساب کاربری',
|
||
|
|
variant: 'destructive'
|
||
|
|
});
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
const getUserInitials = () => {
|
||
|
|
if (user?.email) {
|
||
|
|
return user.email.substring(0, 2).toUpperCase();
|
||
|
|
}
|
||
|
|
if (user?.phone) {
|
||
|
|
return user.phone.slice(-2);
|
||
|
|
}
|
||
|
|
return 'U';
|
||
|
|
};
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="min-h-screen bg-gradient-to-br from-background to-muted p-4 pb-20">
|
||
|
|
<div className="mx-auto max-w-sm">
|
||
|
|
<div className="mb-4">
|
||
|
|
<h1 className="text-2xl font-bold mb-2">حساب کاربری</h1>
|
||
|
|
<p className="text-sm text-muted-foreground">مدیریت اطلاعات و تنظیمات حساب کاربری</p>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<Card>
|
||
|
|
<CardHeader>
|
||
|
|
<CardTitle>اطلاعات کاربری</CardTitle>
|
||
|
|
<CardDescription>جزئیات حساب کاربری شما</CardDescription>
|
||
|
|
</CardHeader>
|
||
|
|
<CardContent className="space-y-4">
|
||
|
|
<div className="flex items-center gap-4">
|
||
|
|
<Avatar className="h-16 w-16">
|
||
|
|
<AvatarImage src={user?.user_metadata?.avatar_url} alt={user?.email || 'User'} />
|
||
|
|
<AvatarFallback className="text-lg">{getUserInitials()}</AvatarFallback>
|
||
|
|
</Avatar>
|
||
|
|
<div className="flex-1 min-w-0">
|
||
|
|
<h3 className="text-lg font-semibold mb-2 truncate">
|
||
|
|
{user?.user_metadata?.full_name || user?.email || user?.phone || 'کاربر'}
|
||
|
|
</h3>
|
||
|
|
<div className="space-y-2 text-sm text-muted-foreground">
|
||
|
|
{user?.email && (
|
||
|
|
<div className="flex items-center gap-2">
|
||
|
|
<Mail className="h-4 w-4 flex-shrink-0" />
|
||
|
|
<span className="truncate">{user.email}</span>
|
||
|
|
</div>
|
||
|
|
)}
|
||
|
|
{user?.phone && (
|
||
|
|
<div className="flex items-center gap-2">
|
||
|
|
<Phone className="h-4 w-4 flex-shrink-0" />
|
||
|
|
<span className="truncate">{user.phone}</span>
|
||
|
|
</div>
|
||
|
|
)}
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div className="border-t pt-6">
|
||
|
|
<div className="space-y-4">
|
||
|
|
<div className="flex items-center justify-between">
|
||
|
|
<div>
|
||
|
|
<div className="font-medium">شناسه کاربری</div>
|
||
|
|
<div className="text-sm text-muted-foreground font-mono">
|
||
|
|
{user?.id?.substring(0, 8)}...
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<UserIcon className="h-5 w-5 text-muted-foreground" />
|
||
|
|
</div>
|
||
|
|
|
||
|
|
{user?.created_at && (
|
||
|
|
<div className="flex items-center justify-between">
|
||
|
|
<div>
|
||
|
|
<div className="font-medium">تاریخ عضویت</div>
|
||
|
|
<div className="text-sm text-muted-foreground">
|
||
|
|
{new Date(user.created_at).toLocaleDateString('fa-IR')}
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
)}
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div className="border-t pt-6">
|
||
|
|
<Button
|
||
|
|
variant="destructive"
|
||
|
|
className="w-full"
|
||
|
|
onClick={handleSignOut}
|
||
|
|
>
|
||
|
|
<LogOut className="ml-2 h-4 w-4" />
|
||
|
|
خروج از حساب کاربری
|
||
|
|
</Button>
|
||
|
|
</div>
|
||
|
|
</CardContent>
|
||
|
|
</Card>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|