-
Notifications
You must be signed in to change notification settings - Fork 1
/
Header.js
70 lines (64 loc) · 2.14 KB
/
Header.js
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
import React, { useContext } from "react";
import { StateContext } from "../contextAPI/StateProvider";
import { Link } from "react-router-dom";
import { userList } from "../utils";
import DefaultAvatar from "../assets/default-user.png";
import Brightness4RoundedIcon from "@material-ui/icons/Brightness4Rounded";
function Header() {
const [{ user }, dispatch] = useContext(StateContext);
const currentUserName = user?.email.split("@")[0];
const currentEmail = user?.email;
const firstLetterCapitalInUserName =
user && currentUserName.charAt(0).toUpperCase() + currentUserName.slice(1);
const handleTheme = () => {
let x = document.getElementsByTagName("BODY")[0];
x.classList.toggle("dark-mode");
}
return (
<>
<header className="dashboarf-header" id="header">
<Link to="/" className="logo link">
<span>Frontend</span>Team
</Link>
<div className="header-right">
<div className="theme-icon" onClick={handleTheme}>
<Brightness4RoundedIcon />
</div>
<div className="user-details">
{user ? (
<>
<span>
{userList?.map((user, i) => {
if (
user.name.substr(0,user.name.indexOf(' ')).toUpperCase() === currentUserName.toUpperCase()
) {
return (
<img
key={i}
src={user.image}
className="user-image"
onError={(e) => {
e.target.src = DefaultAvatar;
}}
/>
);
}
})}
</span>
<div className="user-info">
{firstLetterCapitalInUserName}
<div>{currentEmail}</div>
</div>
</>
) : (
<Link to="/register">
<div>Login</div>
</Link>
)}
</div>
</div>
</header>
</>
);
}
export default Header;