feat: add window with profile and logout buttons. add notification component
This commit is contained in:
@@ -39,10 +39,55 @@
|
||||
color: #ff4d4d;
|
||||
}
|
||||
|
||||
.accountWrapper {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.account {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
position: absolute;
|
||||
top: calc(100% + 12px);
|
||||
right: 0;
|
||||
background: var(--bg-card, #1a1a2e);
|
||||
border: 1px solid var(--glass-border);
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
min-width: 180px;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.dropdownItem {
|
||||
display: block;
|
||||
padding: 12px 16px;
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
text-decoration: none;
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
transition: background 0.15s, color 0.15s;
|
||||
}
|
||||
|
||||
.dropdownItem:hover {
|
||||
background: var(--glass-border);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.dropdownItem.danger:hover {
|
||||
color: var(--error);
|
||||
}
|
||||
|
||||
.avatar {
|
||||
|
||||
@@ -2,6 +2,11 @@ import logo from '@shared/assets/logo-full-white.png'
|
||||
import styles from './WalletHeader.module.css'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { ROUTES } from '@shared/config/routes'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { logout } from '@features/auth/api/registrationApi'
|
||||
import { Notification } from '@shared/ui'
|
||||
|
||||
const TICKERS = [
|
||||
{ symbol: 'BTC', price: '$66,916.00', change: 0.12, },
|
||||
@@ -10,26 +15,73 @@ const TICKERS = [
|
||||
]
|
||||
|
||||
export function WalletHeader() {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [error, setError] = useState(false)
|
||||
const ref = useRef<HTMLDivElement>(null)
|
||||
const navigate = useNavigate()
|
||||
|
||||
const { mutate: logoutMutate } = useMutation({
|
||||
mutationFn: logout,
|
||||
onSuccess: () => navigate(ROUTES.HOME),
|
||||
onError: () => setError(true),
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
function handleClickOutside(e: MouseEvent) {
|
||||
if (ref.current && !ref.current.contains(e.target as Node)) {
|
||||
setOpen(false)
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside)
|
||||
}, [])
|
||||
|
||||
function handleLogout() {
|
||||
logoutMutate()
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<nav className={styles.nav}>
|
||||
<a href="/" className={styles.logo}>
|
||||
<img src={logo} alt="ЭКСА" />
|
||||
</a>
|
||||
<div className={styles.ticker}>
|
||||
{TICKERS.map(({ symbol, price, change }) => (
|
||||
<div key={symbol} className={styles.tick}>
|
||||
<b>{symbol}</b>
|
||||
<span>{price}</span>
|
||||
<span className={change >= 0 ? styles.up : styles.dn}>
|
||||
{change >= 0 ? '+' : ''}{change}%
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<Link to={ROUTES.PROFILE} className={styles.account}>
|
||||
<div className={styles.avatar} />
|
||||
<span>Test account</span>
|
||||
</Link>
|
||||
</nav>
|
||||
<>
|
||||
<nav className={styles.nav}>
|
||||
<a href="/" className={styles.logo}>
|
||||
<img src={logo} alt="ЭКСА" />
|
||||
</a>
|
||||
<div className={styles.ticker}>
|
||||
{TICKERS.map(({ symbol, price, change }) => (
|
||||
<div key={symbol} className={styles.tick}>
|
||||
<b>{symbol}</b>
|
||||
<span>{price}</span>
|
||||
<span className={change >= 0 ? styles.up : styles.dn}>
|
||||
{change >= 0 ? '+' : ''}{change}%
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className={styles.accountWrapper} ref={ref}>
|
||||
<button className={styles.account} onClick={() => setOpen(v => !v)}>
|
||||
<div className={styles.avatar} />
|
||||
<span>Test account</span>
|
||||
</button>
|
||||
{open && (
|
||||
<div className={styles.dropdown}>
|
||||
<Link to={ROUTES.PROFILE} className={styles.dropdownItem} onClick={() => setOpen(false)}>
|
||||
Личный кабинет
|
||||
</Link>
|
||||
<button className={`${styles.dropdownItem} ${styles.danger}`} onClick={handleLogout}>
|
||||
Выйти
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</nav>
|
||||
{error && (
|
||||
<Notification
|
||||
status="error"
|
||||
message="Произошла ошибка сервера"
|
||||
onClose={() => setError(false)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user