2024-12-23 18:42:18 +00:00
|
|
|
|
'use client';
|
|
|
|
|
|
|
2025-07-07 18:22:51 +03:00
|
|
|
|
import { useAuth } from '@/hooks/useAuth';
|
2024-12-23 18:42:18 +00:00
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
|
import GlassCard from '@/components/GlassCard';
|
|
|
|
|
|
import { useRouter } from 'next/navigation';
|
2025-07-07 18:22:51 +03:00
|
|
|
|
import { useEffect, useState } from 'react';
|
2024-12-23 18:42:18 +00:00
|
|
|
|
|
|
|
|
|
|
const Container = styled.div`
|
|
|
|
|
|
min-height: 100vh;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
padding-top: 80px;
|
|
|
|
|
|
background-color: #0a0a0a;
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const Content = styled.div`
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
max-width: 600px;
|
|
|
|
|
|
padding: 2rem;
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const ProfileHeader = styled.div`
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
margin-bottom: 2rem;
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const Avatar = styled.div`
|
|
|
|
|
|
width: 120px;
|
|
|
|
|
|
height: 120px;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
background: #2196f3;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
font-size: 3rem;
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
margin: 0 auto 1rem;
|
|
|
|
|
|
border: 4px solid #fff;
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const Name = styled.h1`
|
|
|
|
|
|
color: #fff;
|
|
|
|
|
|
font-size: 2rem;
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const Email = styled.p`
|
|
|
|
|
|
color: rgba(255, 255, 255, 0.7);
|
|
|
|
|
|
margin: 0.5rem 0 0;
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const SignOutButton = styled.button`
|
|
|
|
|
|
background: #ff4444;
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
border: none;
|
|
|
|
|
|
padding: 0.75rem 1.5rem;
|
|
|
|
|
|
border-radius: 0.5rem;
|
|
|
|
|
|
font-size: 1rem;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
transition: background 0.2s;
|
|
|
|
|
|
margin-top: 1rem;
|
|
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
|
background: #ff2020;
|
|
|
|
|
|
}
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
export default function ProfilePage() {
|
2025-07-07 18:22:51 +03:00
|
|
|
|
const { logout } = useAuth();
|
2024-12-23 18:42:18 +00:00
|
|
|
|
const router = useRouter();
|
2025-07-07 18:22:51 +03:00
|
|
|
|
const [userName, setUserName] = useState<string | null>(null);
|
|
|
|
|
|
const [userEmail, setUserEmail] = useState<string | null>(null);
|
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
2024-12-23 18:42:18 +00:00
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2025-07-07 18:22:51 +03:00
|
|
|
|
const token = localStorage.getItem('token');
|
|
|
|
|
|
if (!token) {
|
2024-12-23 18:42:18 +00:00
|
|
|
|
router.push('/login');
|
2025-07-07 18:22:51 +03:00
|
|
|
|
} else {
|
|
|
|
|
|
setUserName(localStorage.getItem('userName'));
|
|
|
|
|
|
setUserEmail(localStorage.getItem('userEmail'));
|
|
|
|
|
|
setLoading(false);
|
2024-12-23 18:42:18 +00:00
|
|
|
|
}
|
2025-07-07 18:22:51 +03:00
|
|
|
|
}, [router]);
|
2024-12-23 18:42:18 +00:00
|
|
|
|
|
2025-07-07 18:22:51 +03:00
|
|
|
|
const handleSignOut = () => {
|
|
|
|
|
|
logout();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (loading) {
|
2024-12-23 18:42:18 +00:00
|
|
|
|
return (
|
|
|
|
|
|
<Container>
|
|
|
|
|
|
<Content>
|
|
|
|
|
|
<GlassCard>
|
|
|
|
|
|
<div>Загрузка...</div>
|
|
|
|
|
|
</GlassCard>
|
|
|
|
|
|
</Content>
|
|
|
|
|
|
</Container>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-07 18:22:51 +03:00
|
|
|
|
if (!userName) {
|
2024-12-23 18:42:18 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Container>
|
|
|
|
|
|
<Content>
|
|
|
|
|
|
<GlassCard>
|
|
|
|
|
|
<ProfileHeader>
|
|
|
|
|
|
<Avatar>
|
2025-07-07 18:22:51 +03:00
|
|
|
|
{userName?.split(' ').map(n => n[0]).join('').toUpperCase() || ''}
|
2024-12-23 18:42:18 +00:00
|
|
|
|
</Avatar>
|
2025-07-07 18:22:51 +03:00
|
|
|
|
<Name>{userName}</Name>
|
|
|
|
|
|
<Email>{userEmail}</Email>
|
|
|
|
|
|
<SignOutButton onClick={handleSignOut}>Выйти</SignOutButton>
|
2024-12-23 18:42:18 +00:00
|
|
|
|
</ProfileHeader>
|
|
|
|
|
|
</GlassCard>
|
|
|
|
|
|
</Content>
|
|
|
|
|
|
</Container>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|