Notification.tsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. import { useRef, useState } from "react";
  2. // material-ui
  3. import { useTheme } from "@mui/material/styles";
  4. import {
  5. Avatar,
  6. Badge,
  7. Box,
  8. ClickAwayListener,
  9. Divider,
  10. List,
  11. ListItemButton,
  12. ListItemAvatar,
  13. ListItemText,
  14. ListItemSecondaryAction,
  15. Paper,
  16. Popper,
  17. Tooltip,
  18. Typography,
  19. useMediaQuery
  20. } from "@mui/material";
  21. // project import
  22. import MainCard from "@/components/MainCard";
  23. import IconButton from "@/components/@extended/IconButton";
  24. import Transitions from "@/components/@extended/Transitions";
  25. // assets
  26. import { BellOutlined, CheckCircleOutlined, GiftOutlined, MessageOutlined, SettingOutlined } from "@ant-design/icons";
  27. // sx styles
  28. const avatarSX = {
  29. width: 36,
  30. height: 36,
  31. fontSize: "1rem"
  32. };
  33. const actionSX = {
  34. mt: "6px",
  35. ml: 1,
  36. top: "auto",
  37. right: "auto",
  38. alignSelf: "flex-start",
  39. transform: "none"
  40. };
  41. // ==============================|| HEADER CONTENT - NOTIFICATION ||============================== //
  42. const Notification = () => {
  43. const theme = useTheme();
  44. const matchesXs = useMediaQuery(theme.breakpoints.down("md"));
  45. const anchorRef = useRef<any>(null);
  46. const [read, setRead] = useState(2);
  47. const [open, setOpen] = useState(false);
  48. const handleToggle = () => {
  49. setOpen((prevOpen) => !prevOpen);
  50. };
  51. const handleClose = (event: MouseEvent | TouchEvent) => {
  52. if (anchorRef.current && anchorRef.current.contains(event.target)) {
  53. return;
  54. }
  55. setOpen(false);
  56. };
  57. const iconBackColorOpen = theme.palette.mode === "dark" ? "grey.200" : "grey.300";
  58. const iconBackColor = theme.palette.mode === "dark" ? "background.default" : "grey.100";
  59. return (
  60. <Box sx={{ flexShrink: 0, ml: 0.75 }}>
  61. <IconButton
  62. color="secondary"
  63. variant="light"
  64. sx={{ color: "text.primary", bgcolor: open ? iconBackColorOpen : iconBackColor }}
  65. aria-label="open profile"
  66. ref={anchorRef}
  67. aria-controls={open ? "profile-grow" : undefined}
  68. aria-haspopup="true"
  69. onClick={handleToggle}
  70. >
  71. <Badge badgeContent={read} color="primary">
  72. <BellOutlined />
  73. </Badge>
  74. </IconButton>
  75. <Popper
  76. placement={matchesXs ? "bottom" : "bottom-end"}
  77. open={open}
  78. anchorEl={anchorRef.current}
  79. role={undefined}
  80. transition
  81. disablePortal
  82. popperOptions={{
  83. modifiers: [
  84. {
  85. name: "offset",
  86. options: {
  87. offset: [matchesXs ? -5 : 0, 9]
  88. }
  89. }
  90. ]
  91. }}
  92. >
  93. {({ TransitionProps }) => (
  94. <Transitions type="fade" in={open} {...TransitionProps}>
  95. <Paper
  96. sx={{
  97. boxShadow: theme.customShadows.z1,
  98. width: "100%",
  99. minWidth: 285,
  100. maxWidth: 420,
  101. [theme.breakpoints.down("md")]: {
  102. maxWidth: 285
  103. }
  104. }}
  105. >
  106. <ClickAwayListener onClickAway={handleClose}>
  107. <MainCard
  108. title="Notification"
  109. elevation={0}
  110. border={false}
  111. content={false}
  112. secondary={
  113. <>
  114. {read > 0 && (
  115. <Tooltip title="Mark as all read">
  116. <IconButton color="success" size="small" onClick={() => setRead(0)}>
  117. <CheckCircleOutlined style={{ fontSize: "1.15rem" }} />
  118. </IconButton>
  119. </Tooltip>
  120. )}
  121. </>
  122. }
  123. >
  124. <List
  125. component="nav"
  126. sx={{
  127. p: 0,
  128. "& .MuiListItemButton-root": {
  129. py: 0.5,
  130. "&.Mui-selected": { bgcolor: "grey.50", color: "text.primary" },
  131. "& .MuiAvatar-root": avatarSX,
  132. "& .MuiListItemSecondaryAction-root": { ...actionSX, position: "relative" }
  133. }
  134. }}
  135. >
  136. <ListItemButton selected={read > 0}>
  137. <ListItemAvatar>
  138. <Avatar
  139. sx={{
  140. color: "success.main",
  141. bgcolor: "success.lighter"
  142. }}
  143. >
  144. <GiftOutlined />
  145. </Avatar>
  146. </ListItemAvatar>
  147. <ListItemText
  148. primary={
  149. <Typography variant="h6">
  150. It&apos;s{" "}
  151. <Typography component="span" variant="subtitle1">
  152. Cristina danny&apos;s
  153. </Typography>{" "}
  154. birthday today.
  155. </Typography>
  156. }
  157. secondary="2 min ago"
  158. />
  159. <ListItemSecondaryAction>
  160. <Typography variant="caption" noWrap>
  161. 3:00 AM
  162. </Typography>
  163. </ListItemSecondaryAction>
  164. </ListItemButton>
  165. <Divider />
  166. <ListItemButton>
  167. <ListItemAvatar>
  168. <Avatar
  169. sx={{
  170. color: "primary.main",
  171. bgcolor: "primary.lighter"
  172. }}
  173. >
  174. <MessageOutlined />
  175. </Avatar>
  176. </ListItemAvatar>
  177. <ListItemText
  178. primary={
  179. <Typography variant="h6">
  180. <Typography component="span" variant="subtitle1">
  181. Aida Burg
  182. </Typography>{" "}
  183. commented your post.
  184. </Typography>
  185. }
  186. secondary="5 August"
  187. />
  188. <ListItemSecondaryAction>
  189. <Typography variant="caption" noWrap>
  190. 6:00 PM
  191. </Typography>
  192. </ListItemSecondaryAction>
  193. </ListItemButton>
  194. <Divider />
  195. <ListItemButton selected={read > 0}>
  196. <ListItemAvatar>
  197. <Avatar
  198. sx={{
  199. color: "error.main",
  200. bgcolor: "error.lighter"
  201. }}
  202. >
  203. <SettingOutlined />
  204. </Avatar>
  205. </ListItemAvatar>
  206. <ListItemText
  207. primary={
  208. <Typography variant="h6">
  209. Your Profile is Complete &nbsp;
  210. <Typography component="span" variant="subtitle1">
  211. 60%
  212. </Typography>{" "}
  213. </Typography>
  214. }
  215. secondary="7 hours ago"
  216. />
  217. <ListItemSecondaryAction>
  218. <Typography variant="caption" noWrap>
  219. 2:45 PM
  220. </Typography>
  221. </ListItemSecondaryAction>
  222. </ListItemButton>
  223. <Divider />
  224. <ListItemButton>
  225. <ListItemAvatar>
  226. <Avatar
  227. sx={{
  228. color: "primary.main",
  229. bgcolor: "primary.lighter"
  230. }}
  231. >
  232. C
  233. </Avatar>
  234. </ListItemAvatar>
  235. <ListItemText
  236. primary={
  237. <Typography variant="h6">
  238. <Typography component="span" variant="subtitle1">
  239. Cristina Danny
  240. </Typography>{" "}
  241. invited to join{" "}
  242. <Typography component="span" variant="subtitle1">
  243. Meeting.
  244. </Typography>
  245. </Typography>
  246. }
  247. secondary="Daily scrum meeting time"
  248. />
  249. <ListItemSecondaryAction>
  250. <Typography variant="caption" noWrap>
  251. 9:10 PM
  252. </Typography>
  253. </ListItemSecondaryAction>
  254. </ListItemButton>
  255. <Divider />
  256. <ListItemButton sx={{ textAlign: "center", py: `${12}px !important` }}>
  257. <ListItemText
  258. primary={
  259. <Typography variant="h6" color="primary">
  260. View All
  261. </Typography>
  262. }
  263. />
  264. </ListItemButton>
  265. </List>
  266. </MainCard>
  267. </ClickAwayListener>
  268. </Paper>
  269. </Transitions>
  270. )}
  271. </Popper>
  272. </Box>
  273. );
  274. };
  275. export default Notification;