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

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