index.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { useState } from 'react';
  2. import { useSelector } from 'react-redux';
  3. import { styled } from '@mui/material/styles';
  4. import IconButton from '@mui/material/IconButton';
  5. import Menu from '@mui/material/Menu';
  6. import MenuItem from '@mui/material/MenuItem';
  7. import NotificationsNoneIcon from '@mui/icons-material/NotificationsNone';
  8. import VolumeOffIcon from '@mui/icons-material/VolumeOff';
  9. import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
  10. import MoreVertIcon from '@mui/icons-material/MoreVert';
  11. import CheckBoxIcon from '@mui/icons-material/CheckBox';
  12. import { getChat } from '../../../../../../redux/chat/selector'
  13. import { muteChat } from '../../../../../../api-data'
  14. const StyledMenu = styled((props:any) => (
  15. <Menu
  16. elevation={0}
  17. anchorOrigin={{
  18. vertical: 'top',
  19. horizontal: 'right',
  20. }}
  21. transformOrigin={{
  22. vertical: 'bottom',
  23. horizontal: 'right',
  24. }}
  25. {...props}
  26. />
  27. ))(({ theme }:any) => ({
  28. '& .MuiPaper-root': {
  29. borderRadius: 10,
  30. marginTop: theme.spacing(-2),
  31. minWidth: 220,
  32. color:
  33. theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
  34. boxShadow:
  35. 'rgb(255, 255, 255) 0px 0px 0px 0px, rgba(0, 0, 0, 0.05) 0px 0px 0px 1px, rgba(0, 0, 0, 0.1) 0px 10px 15px -3px, rgba(0, 0, 0, 0.05) 0px 4px 6px -2px',
  36. '& .MuiMenu-list': {
  37. padding: '14px 14px',
  38. },
  39. '& .MuiMenuItem-root': {
  40. marginBottom: theme.spacing(1),
  41. '& .MuiSvgIcon-root': {
  42. fontSize: 21,
  43. color: theme.palette.text.secondary,
  44. marginRight: theme.spacing(4),
  45. }
  46. },
  47. },
  48. }));
  49. interface IMenuList {
  50. setModalDelete:any,
  51. setIsSomeSelected: React.Dispatch<React.SetStateAction<boolean>>,
  52. }
  53. const MenuList = ({setModalDelete,setIsSomeSelected}:IMenuList) => {
  54. const [anchorEl, setAnchorEl] = useState<any>(null);
  55. const open = Boolean(anchorEl);
  56. const { companionId, mute } = useSelector(getChat)
  57. const handleClick = (e: React.MouseEvent<HTMLButtonElement>): void => {
  58. e.stopPropagation()
  59. setAnchorEl(e.currentTarget)
  60. }
  61. const handleClose = (type: string | undefined): void => {
  62. if (type === 'mute') muteChat(companionId)
  63. if (type === 'deleteModal') setModalDelete(true)
  64. setAnchorEl(null)
  65. }
  66. return (
  67. <>
  68. <IconButton onClick={handleClick} aria-label="delete" size="medium">
  69. <MoreVertIcon fontSize='medium'/>
  70. </IconButton>
  71. <StyledMenu
  72. id="demo-positioned-menu"
  73. aria-labelledby="demo-positioned-button"
  74. anchorEl={anchorEl}
  75. open={open}
  76. onClose={handleClose}
  77. >
  78. <MenuItem onClick={() => handleClose('mute')}>
  79. {mute ? <NotificationsNoneIcon /> : <VolumeOffIcon />}
  80. {mute ? 'Unmute':'Mute'}
  81. </MenuItem>
  82. <MenuItem onClick={() => {
  83. setIsSomeSelected(true)
  84. handleClose(undefined)
  85. }}>
  86. <CheckBoxIcon />
  87. Select message
  88. </MenuItem>
  89. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('deleteModal')}>
  90. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  91. Delete chat
  92. </MenuItem>
  93. </StyledMenu>
  94. </>
  95. );
  96. }
  97. export default MenuList