{"size": 1754, "ext": "js", "max_stars_repo_path": "src/components/header.js", "max_stars_repo_name": "Aghazjunaid/React_Product_Dashboard", "max_stars_repo_stars_event_min_datetime": "2021-07-25T09:41:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-25T09:41:13.000Z", "max_issues_repo_path": "src/components/header.js", "max_issues_repo_name": "Aghazjunaid/React_Product_Dashboard", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/header.js", "max_forks_repo_name": "Aghazjunaid/React_Product_Dashboard", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.7288135593, "max_line_length": 79, "alphanum_fraction": 0.484036488}
import React from "react";
import { Navbar, Nav, Container, NavDropdown } from "react-bootstrap";
import { NavLink, Link } from "react-router-dom";
import { useHistory } from "react-router-dom";

function Header() {
  const history = useHistory();

  const user = JSON.parse(localStorage.getItem("userData"));

  function logout() {
    localStorage.clear();
    history.push("/login");
  }
  return (
    <>
        <Navbar bg="danger" variant="dark">
          <Link to="/" className="navbar-brand font-weight-bold">
            Admin Dashboard
          </Link>
          <Nav className="mr-auto">
            {localStorage.getItem("userData") ? (
              <>
                <NavLink to="/" className="nav-link ">
                  ProductListing
                </NavLink>
                <NavLink to="/add" className="nav-link ">
                  AddProduct
                </NavLink>
                <NavLink to="/search" className="nav-link">
                  SearchProduct
                </NavLink>
              </>
            ) : (
              <>
                <NavLink to="/login" className="nav-link">
                  LogIn
                </NavLink>
                <NavLink to="/register" className="nav-link">
                  Register
                </NavLink>
              </>
            )}
          </Nav>
          {localStorage.getItem("userData") ? (
            <Nav>
              <NavDropdown title={user.data.name} id="collasible-nav-dropdown">
                <NavDropdown.Item>Profile</NavDropdown.Item>
                <NavDropdown.Item onClick={logout}>Logout</NavDropdown.Item>
              </NavDropdown>
            </Nav>
          ) : null}
        </Navbar>
    </>
  );
}

export default Header;
