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.

NavbarComponent.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. import React, { useState, useMemo, useRef, useEffect } from "react";
  2. import {
  3. AppBar,
  4. // Badge,
  5. Box,
  6. IconButton,
  7. Toolbar,
  8. Typography,
  9. List,
  10. // ListItem,
  11. ListItemButton,
  12. ListItemIcon,
  13. ListItemText,
  14. useMediaQuery,
  15. Button,
  16. } from "@mui/material";
  17. import HrLogo from "../../assets/images/HR.png";
  18. // import x from "../../assets/images/x.png";
  19. import avatarLogo from "../../assets/images/Avatar.png";
  20. import { useTheme } from "@mui/system";
  21. import MenuOutlinedIcon from "@mui/icons-material/MenuOutlined";
  22. // import ShoppingBasketIcon from "@mui/icons-material/ShoppingBasket";
  23. // import Brightness4Icon from "@mui/icons-material/Brightness4";
  24. // import Brightness7Icon from "@mui/icons-material/Brightness7";
  25. // import MenuList from "./MenuListComponent";
  26. import Drawer from "./DrawerComponent";
  27. // import { ColorModeContext } from "../../context/ColorModeContext";
  28. import { useTranslation } from "react-i18next";
  29. import CloseIcon from "@mui/icons-material/Close";
  30. import LogoutIcon from "@mui/icons-material/Logout";
  31. import UserProfile from "../Profile/UserProfile";
  32. import { useSelector } from "react-redux";
  33. //import { userSelector } from "../../store/selectors/userSelectors";
  34. import { Link, useLocation } from "react-router-dom";
  35. import rs from "../../assets/images/rs.png";
  36. import en from "../../assets/images/en.png";
  37. const NavbarComponent = () => {
  38. const navItems = [
  39. "users",
  40. "files"
  41. ];
  42. const { pathname } = useLocation();
  43. const [openDrawer, setOpenDrawer] = useState(false);
  44. const [preview, setPreview] = useState(false);
  45. const theme = useTheme();
  46. const matches = useMediaQuery(theme.breakpoints.down("sm"));
  47. // const toggleColorMode = useContext(ColorModeContext);
  48. let userRef = useRef();
  49. let btnRef = useRef();
  50. // get authenticated user
  51. const { user } = useSelector((s) => s.user);
  52. const { t, i18n } = useTranslation();
  53. const handleToggleDrawer = () => {
  54. setOpenDrawer(!openDrawer);
  55. };
  56. const changeLanguageHandler = () => {
  57. i18n.language === "en"
  58. ? i18n.changeLanguage("rs")
  59. : i18n.changeLanguage("en");
  60. };
  61. const userPreviewHandler = () => {
  62. setPreview(!preview);
  63. };
  64. const filterNavItems = () => {
  65. return navItems.filter(n => ((n === "users" && user.role === "SuperAdmin") || n !== "users"))
  66. }
  67. useEffect(() => {
  68. let handler = (e) => {
  69. if (userRef.current) {
  70. if (
  71. !userRef.current.contains(e.target) &&
  72. !btnRef.current.contains(e.target)
  73. ) {
  74. setPreview(false);
  75. }
  76. }
  77. };
  78. document.addEventListener("mousedown", handler, { capture: true });
  79. return () => {
  80. document.removeEventListener("mousedown", handler, { capture: true });
  81. };
  82. }, []);
  83. const drawerContent = useMemo(
  84. () => (
  85. <div style={{ width: "100vw", padding: "36px" }}>
  86. <div
  87. className="flex-center"
  88. style={{ justifyContent: "space-between", marginBottom: "20px" }}
  89. >
  90. <Typography
  91. sx={{ fontWeight: 600, fontSize: "18px", letterSpacing: "1.5px" }}
  92. >
  93. {t("nav.navigation")}
  94. </Typography>
  95. <IconButton onClick={handleToggleDrawer}>
  96. <CloseIcon />
  97. </IconButton>
  98. </div>
  99. <div className="flex-center flex-col">
  100. <img src={avatarLogo} width="64px" height="64px" />
  101. <Typography
  102. variant="h5"
  103. sx={{ fontSize: "18px", marginTop: "15px" }}
  104. className="text-blue"
  105. >
  106. {user.firstName + " " + user.lastName}
  107. </Typography>
  108. <Typography
  109. variant="body1"
  110. sx={{ fontSize: "14px", marginTop: "8px" }}
  111. className="text-grey9d"
  112. >
  113. HR {t("common.specialist")}
  114. </Typography>
  115. <div className="change-language">
  116. <IconButton
  117. className={`c-btn--primary-outlined c-btn ${
  118. i18n.language === "rs" && "change-language-active-button"
  119. }`}
  120. onClick={changeLanguageHandler}
  121. >
  122. <img
  123. style={{
  124. position: "relative",
  125. }}
  126. src={rs}
  127. />
  128. RS
  129. </IconButton>
  130. <IconButton
  131. className={`c-btn--primary-outlined c-btn ${
  132. i18n.language === "en" && "change-language-active-button"
  133. }`}
  134. onClick={changeLanguageHandler}
  135. >
  136. <img
  137. style={{
  138. position: "relative",
  139. }}
  140. src={en}
  141. />
  142. EN
  143. </IconButton>
  144. </div>
  145. <div className="hr" style={{ width: "90%", marginTop: "18px" }}></div>
  146. </div>
  147. <List>
  148. {navItems.map((n) => (
  149. <ListItemButton key={n} onClick={handleToggleDrawer}>
  150. <ListItemIcon>
  151. <ListItemText
  152. variant="body1"
  153. sx={{
  154. // marginRight: "50px",
  155. cursor: "pointer",
  156. textAlign: "left",
  157. lineHeight: "17.6px",
  158. fontWeight: "400",
  159. color: "#353535",
  160. marginY: "0",
  161. padding: "0",
  162. textDecoration: "none",
  163. }}
  164. className="text-black"
  165. as={Link}
  166. to={`/${n}`}
  167. >
  168. {t("nav." + n)}
  169. </ListItemText>
  170. </ListItemIcon>
  171. </ListItemButton>
  172. ))}
  173. {/* <ListItem divider>
  174. <IconButton onClick={toggleColorMode}>
  175. <ListItemText>Toggle {theme.palette.mode} mode</ListItemText>
  176. {theme.palette.mode === "dark" ? (
  177. <Brightness7Icon />
  178. ) : (
  179. <Brightness4Icon />
  180. )}
  181. </IconButton>
  182. </ListItem> */}
  183. </List>
  184. {/* <button style={{width:'90%', margin: 'auto'}} className="flex-center"> */}
  185. {/* <Typography>s</Typography> */}
  186. <div className="flex-center">
  187. <Button
  188. sx={{
  189. padding: "18px 72px",
  190. border: "1px solid #226cb0",
  191. borderRadius: "9px",
  192. background: "white",
  193. width: "90%",
  194. marginTop: "50px",
  195. }}
  196. startIcon={<LogoutIcon />}
  197. >
  198. {t("nav.signOut")}
  199. </Button>
  200. </div>
  201. </div>
  202. ),
  203. [handleToggleDrawer]
  204. );
  205. return (
  206. <AppBar
  207. elevation={0}
  208. sx={{
  209. backgroundColor: "transparent",
  210. position: "relative",
  211. width: "100%",
  212. padding: "0",
  213. }}
  214. >
  215. <Toolbar
  216. sx={{
  217. padding: "0px",
  218. margin: "0px",
  219. width: "100%",
  220. }}
  221. >
  222. <Box
  223. component="div"
  224. sx={{
  225. display: "flex",
  226. justifyContent: "space-between",
  227. alignItems: "center",
  228. width: "100%",
  229. padding: "0px",
  230. margin: "0px",
  231. // md: {paddingX: "72px"}
  232. // paddingX: "72px"
  233. }}
  234. >
  235. <Box
  236. sx={{
  237. display: "flex",
  238. justifyContent: "center",
  239. alignItems: "center",
  240. width: matches ? "100%" : "auto",
  241. }}
  242. >
  243. {matches ? (
  244. <Box
  245. className="responsive-nav-cont"
  246. style={{
  247. display: "flex",
  248. alignItems: "center",
  249. justifyContent: "space-between",
  250. }}
  251. >
  252. <img
  253. style={{ height: "37px", width: "37px", marginLeft: "0px" }}
  254. src={HrLogo}
  255. className="responsive-logo"
  256. />
  257. <div
  258. style={{
  259. display: "flex",
  260. alignItems: "center",
  261. }}
  262. className="icons-cont"
  263. >
  264. {/* <img src={searchIcon} /> */}
  265. <IconButton
  266. sx={{ marginLeft: "27px" }}
  267. onClick={handleToggleDrawer}
  268. >
  269. <MenuOutlinedIcon />
  270. </IconButton>
  271. </div>
  272. </Box>
  273. ) : (
  274. <Box>
  275. {/* <IconButton onClick={handleToggleDrawer}>
  276. <MenuOutlinedIcon />
  277. </IconButton> */}
  278. <img
  279. style={{ height: "37px", width: "37px", marginLeft: "72px" }}
  280. src={HrLogo}
  281. />
  282. </Box>
  283. )}
  284. </Box>
  285. {matches ? (
  286. <Drawer
  287. open={openDrawer}
  288. toggleOpen={handleToggleDrawer}
  289. content={drawerContent}
  290. />
  291. ) : (
  292. <Box
  293. sx={{
  294. display: "flex",
  295. alignItems: "center",
  296. paddingRight: "20px",
  297. justifyContent: "flex-end",
  298. // HEIGHT OF THE NAVBAR IN md & xl SIZE
  299. width: "1076px",
  300. borderBottom: "1px solid #F4F4F4",
  301. boxSizing: "border-box",
  302. }}
  303. className="navLinks-cont"
  304. >
  305. {filterNavItems().map((n) => (
  306. <Typography
  307. variant="body1"
  308. key={n}
  309. sx={{
  310. marginRight: "50px",
  311. cursor: "pointer",
  312. textAlign: "right",
  313. lineHeight: "20.11px",
  314. fontWeight: "400",
  315. // color: "text.primary",
  316. marginY: "0",
  317. padding: "0",
  318. textDecoration: "none",
  319. }}
  320. className={pathname === `/${n}` ? "text-blue" : "text-black"}
  321. as={Link}
  322. to={`/${n}`}
  323. >
  324. {t("nav." + n)}
  325. </Typography>
  326. ))}
  327. <div
  328. onClick={userPreviewHandler}
  329. className="full-rounded user-avatar text-uppercase"
  330. ref={btnRef}
  331. >
  332. {/* user.profilePic ? user.profilePic : */}
  333. {user.firstName[0] + "" + user.lastName[0]}
  334. </div>
  335. </Box>
  336. )}
  337. {!matches && <UserProfile innerRef={userRef} show={preview} />}
  338. {/* <Box>
  339. <MenuList />
  340. </Box> */}
  341. </Box>
  342. </Toolbar>
  343. </AppBar>
  344. );
  345. };
  346. export default NavbarComponent;