You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
3 years ago
|
import React, { useState, useEffect } from "react";
|
||
|
import { Layout, Menu, notification } from "antd";
|
||
|
|
||
|
import UserService from "../service/UserService";
|
||
|
|
||
|
const { Header } = Layout;
|
||
3 years ago
|
|
||
3 years ago
|
export default function Head() {
|
||
|
const [username, setUsername] = useState("");
|
||
|
const token = UserService.getToken();
|
||
|
|
||
|
useEffect(() => {
|
||
|
if (token) {
|
||
|
UserService.getUser().then((user) => setUsername(user.fullName));
|
||
|
}
|
||
|
}, []);
|
||
|
|
||
|
const onLogout = () => {
|
||
|
notification.error({
|
||
|
message: "Not yet implemented",
|
||
|
description: "To log out, please clear the cookies.",
|
||
|
});
|
||
|
};
|
||
|
|
||
|
return (
|
||
|
<Header style={{ background: "#fff" }}>
|
||
|
<Menu mode="horizontal" style={{ float: "right" }}>
|
||
|
{token ? (
|
||
|
<>
|
||
|
<Menu.Item>
|
||
|
<a href="/profile">{username}</a>
|
||
|
</Menu.Item>
|
||
|
<Menu.Item onClick={onLogout}>Log Out</Menu.Item>
|
||
|
</>
|
||
|
) : (
|
||
|
<>
|
||
|
<Menu.Item>
|
||
|
<a href="/login">Login</a>
|
||
|
</Menu.Item>
|
||
|
<Menu.Item>
|
||
|
<a href="/register">Register</a>
|
||
|
</Menu.Item>
|
||
|
</>
|
||
|
)}
|
||
|
</Menu>
|
||
|
</Header>
|
||
|
);
|
||
|
}
|