Header.jsx
2.27 KB
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
import React from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { useAuth } from '../../context/AuthContext';
import { useCart } from '../../context/CartContext';
const Header = () => {
const { user, logout, isAuthenticated } = useAuth();
const { getCartItemsCount } = useCart();
const navigate = useNavigate();
const handleLogout = () => {
logout();
navigate('/');
};
return (
<header style={headerStyle}>
<div style={containerStyle}>
<Link to="/" style={logoStyle}>
<h1>Ecommerce Store</h1>
</Link>
<nav style={navStyle}>
<Link to="/" style={linkStyle}>Home</Link>
<Link to="/products" style={linkStyle}>Products</Link>
{isAuthenticated ? (
<>
<Link to="/cart" style={linkStyle}>
Cart ({getCartItemsCount()})
</Link>
<Link to="/profile" style={linkStyle}>Profile</Link>
<Link to="/orders" style={linkStyle}>Orders</Link>
<button onClick={handleLogout} style={logoutButtonStyle}>
Logout
</button>
</>
) : (
<>
<Link to="/login" style={linkStyle}>Login</Link>
<Link to="/register" style={linkStyle}>Register</Link>
</>
)}
</nav>
</div>
</header>
);
};
const headerStyle = {
backgroundColor: '#282c34',
padding: '1rem 0',
color: 'white',
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
};
const containerStyle = {
maxWidth: '1200px',
margin: '0 auto',
padding: '0 1rem',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
};
const logoStyle = {
color: 'white',
textDecoration: 'none',
fontSize: '1.5rem',
fontWeight: 'bold',
};
const navStyle = {
display: 'flex',
alignItems: 'center',
gap: '1.5rem',
};
const linkStyle = {
color: 'white',
textDecoration: 'none',
padding: '0.5rem 1rem',
borderRadius: '4px',
transition: 'background-color 0.3s',
};
const logoutButtonStyle = {
backgroundColor: 'transparent',
color: 'white',
border: '1px solid white',
padding: '0.5rem 1rem',
borderRadius: '4px',
cursor: 'pointer',
transition: 'background-color 0.3s',
};
export default Header;