| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- import React, { useState, useMemo, useRef, useEffect } from "react";
- import {
- AppBar,
- // Badge,
- Box,
- IconButton,
- Toolbar,
- Typography,
- List,
- // ListItem,
- ListItemButton,
- ListItemIcon,
- ListItemText,
- useMediaQuery,
- Button,
- } from "@mui/material";
- import HrLogo from "../../assets/images/HR.png";
- // import x from "../../assets/images/x.png";
- import avatarLogo from "../../assets/images/Avatar.png";
- import searchIcon from "../../assets/images/Vector.png";
- import { useTheme } from "@mui/system";
- import MenuOutlinedIcon from "@mui/icons-material/MenuOutlined";
- // import ShoppingBasketIcon from "@mui/icons-material/ShoppingBasket";
- // import Brightness4Icon from "@mui/icons-material/Brightness4";
- // import Brightness7Icon from "@mui/icons-material/Brightness7";
- // import MenuList from "./MenuListComponent";
- import Drawer from "./DrawerComponent";
- // import { ColorModeContext } from "../../context/ColorModeContext";
- import { useTranslation } from "react-i18next";
- import CloseIcon from "@mui/icons-material/Close";
- import LogoutIcon from "@mui/icons-material/Logout";
- import UserProfile from "../Profile/UserProfile";
- import { useSelector } from "react-redux";
- //import { userSelector } from "../../store/selectors/userSelectors";
- import { Link, useLocation } from "react-router-dom";
- import rs from "../../assets/images/rs.png";
- import en from "../../assets/images/en.png";
-
- const NavbarComponent = () => {
- const navItems = [
- "users",
- "files",
- "filesView",
- // "signOut"
- ];
- const { pathname } = useLocation();
- const [openDrawer, setOpenDrawer] = useState(false);
- const [preview, setPreview] = useState(false);
- const theme = useTheme();
- const matches = useMediaQuery(theme.breakpoints.down("sm"));
- // const toggleColorMode = useContext(ColorModeContext);
-
- let userRef = useRef();
- let btnRef = useRef();
-
- // get authenticated user
- const { user } = useSelector((s) => s.user);
-
- const { t, i18n } = useTranslation();
-
- const handleToggleDrawer = () => {
- setOpenDrawer(!openDrawer);
- };
-
- const changeLanguageHandler = () => {
- i18n.language === "en"
- ? i18n.changeLanguage("rs")
- : i18n.changeLanguage("en");
- };
-
- const userPreviewHandler = () => {
- setPreview(!preview);
- };
-
- useEffect(() => {
- let handler = (e) => {
- if (userRef.current) {
- if (
- !userRef.current.contains(e.target) &&
- !btnRef.current.contains(e.target)
- ) {
- setPreview(false);
- }
- }
- };
-
- document.addEventListener("mousedown", handler, { capture: true });
-
- return () => {
- document.removeEventListener("mousedown", handler, { capture: true });
- };
- }, []);
-
- const drawerContent = useMemo(
- () => (
- <div style={{ width: "100vw", padding: "36px" }}>
- <div
- className="flex-center"
- style={{ justifyContent: "space-between", marginBottom: "20px" }}
- >
- <Typography
- sx={{ fontWeight: 600, fontSize: "18px", letterSpacing: "1.5px" }}
- >
- {t("nav.navigation")}
- </Typography>
- {/* <img src={x}/> */}
- <IconButton onClick={handleToggleDrawer}>
- <CloseIcon />
- </IconButton>
- </div>
- <div className="flex-center flex-col">
- <img src={avatarLogo} width="64px" height="64px" />
- <Typography
- variant="h5"
- sx={{ fontSize: "18px", marginTop: "15px" }}
- className="text-blue"
- >
- {user.firstName + " " + user.lastName}
- </Typography>
- <Typography
- variant="body1"
- sx={{ fontSize: "14px", marginTop: "8px" }}
- className="text-grey9d"
- >
- HR {t("common.specialist")}
- </Typography>
- <div className="change-language">
- <IconButton
- className={`c-btn--primary-outlined c-btn ${
- i18n.language === "rs" && "change-language-active-button"
- }`}
- onClick={changeLanguageHandler}
- >
- <img
- style={{
- position: "relative",
- }}
- src={rs}
- />
- RS
- </IconButton>
- <IconButton
- className={`c-btn--primary-outlined c-btn ${
- i18n.language === "en" && "change-language-active-button"
- }`}
- onClick={changeLanguageHandler}
- >
- <img
- style={{
- position: "relative",
- }}
- src={en}
- />
- EN
- </IconButton>
- </div>
- <div className="hr" style={{ width: "90%", marginTop: "18px" }}></div>
- </div>
- <List>
- {navItems.map((n) => (
- <ListItemButton key={n} onClick={handleToggleDrawer}>
- <ListItemIcon>
- <ListItemText
- variant="body1"
- sx={{
- // marginRight: "50px",
- cursor: "pointer",
- textAlign: "left",
- lineHeight: "17.6px",
- fontWeight: "400",
- color: "#353535",
- marginY: "0",
- padding: "0",
- textDecoration: "none",
- }}
- className="text-black"
- as={Link}
- to={`/${n}`}
- >
- {t("nav." + n)}
- </ListItemText>
- </ListItemIcon>
- </ListItemButton>
- ))}
- {/* <ListItem divider>
- <IconButton onClick={toggleColorMode}>
- <ListItemText>Toggle {theme.palette.mode} mode</ListItemText>
- {theme.palette.mode === "dark" ? (
- <Brightness7Icon />
- ) : (
- <Brightness4Icon />
- )}
- </IconButton>
- </ListItem> */}
- </List>
- {/* <button style={{width:'90%', margin: 'auto'}} className="flex-center"> */}
- {/* <Typography>s</Typography> */}
- <div className="flex-center">
- <Button
- sx={{
- padding: "18px 72px",
- border: "1px solid #226cb0",
- borderRadius: "9px",
- background: "white",
- width: "90%",
- marginTop: "50px",
- }}
- startIcon={<LogoutIcon />}
- >
- {t("nav.signOut")}
- </Button>
- </div>
- </div>
- ),
- [handleToggleDrawer]
- );
-
- return (
- <AppBar
- elevation={0}
- sx={{
- backgroundColor: "transparent",
- position: "relative",
- width: "100%",
- padding: "0",
- }}
- >
- <Toolbar
- sx={{
- padding: "0px",
- margin: "0px",
- width: "100%",
- }}
- >
- <Box
- component="div"
- sx={{
- display: "flex",
- justifyContent: "space-between",
- alignItems: "center",
- width: "100%",
- padding: "0px",
- margin: "0px",
- // md: {paddingX: "72px"}
- // paddingX: "72px"
- }}
- >
- <Box
- sx={{
- display: "flex",
- justifyContent: "center",
- alignItems: "center",
- width: matches ? "100%" : "auto",
- }}
- >
- {matches ? (
- <Box
- className="responsive-nav-cont"
- style={{
- display: "flex",
- alignItems: "center",
- justifyContent: "space-between",
- }}
- >
- <img
- style={{ height: "37px", width: "37px", marginLeft: "0px" }}
- src={HrLogo}
- className="responsive-logo"
- />
- <div
- style={{
- display: "flex",
- alignItems: "center",
- }}
- className="icons-cont"
- >
- <img src={searchIcon} />
- <IconButton
- sx={{ marginLeft: "27px" }}
- onClick={handleToggleDrawer}
- >
- <MenuOutlinedIcon />
- </IconButton>
- </div>
- </Box>
- ) : (
- <Box>
- {/* <IconButton onClick={handleToggleDrawer}>
- <MenuOutlinedIcon />
- </IconButton> */}
- <img
- style={{ height: "37px", width: "37px", marginLeft: "72px" }}
- src={HrLogo}
- />
- </Box>
- )}
- </Box>
- {matches ? (
- <Drawer
- open={openDrawer}
- toggleOpen={handleToggleDrawer}
- content={drawerContent}
- />
- ) : (
- <Box
- sx={{
- display: "flex",
- alignItems: "center",
- paddingRight: "20px",
- justifyContent: "flex-end",
- // HEIGHT OF THE NAVBAR IN md & xl SIZE
- width: "1076px",
- borderBottom: "1px solid #F4F4F4",
- boxSizing: "border-box",
- }}
- className="navLinks-cont"
- >
- {navItems.map((n) => (
- <Typography
- variant="body1"
- key={n}
- sx={{
- marginRight: "50px",
- cursor: "pointer",
- textAlign: "right",
- lineHeight: "20.11px",
- fontWeight: "400",
- // color: "text.primary",
- marginY: "0",
- padding: "0",
- textDecoration: "none",
- }}
- className={pathname === `/${n}` ? "text-blue" : "text-black"}
- as={Link}
- to={`/${n}`}
- >
- {t("nav." + n)}
- </Typography>
- ))}
- <div className="search-Icon">
- <img src={searchIcon} />
- </div>
- <div
- onClick={userPreviewHandler}
- className="full-rounded user-avatar text-uppercase"
- ref={btnRef}
- >
- {/* user.profilePic ? user.profilePic : */}
- {user.firstName[0] + "" + user.lastName[0]}
- </div>
- </Box>
- )}
- {!matches && <UserProfile innerRef={userRef} show={preview} />}
- {/* <Box>
- <MenuList />
- </Box> */}
- </Box>
- </Toolbar>
- </AppBar>
- );
- };
-
- export default NavbarComponent;
|