index.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import Toolbar from '@mui/material/Toolbar'
  2. import AppBar from '@mui/material/AppBar';
  3. import { makeStyles,Typography } from '@material-ui/core'
  4. import Button from '@mui/material/Button';
  5. import { useState } from 'react';
  6. import { useSelector,useDispatch } from 'react-redux';
  7. import IconButton from '@mui/material/IconButton';
  8. import ArrowBackIcon from '@mui/icons-material/ArrowBack';
  9. import Credentials from './Credentials'
  10. import Buttons from './Buttons'
  11. import PinnedBar from './PinnedBar';
  12. import { removeSelectedMessagesById } from '../../../../api-data';
  13. import { getChatMemo } from '../../../../redux/chat/selector';
  14. import { actionRightIsOpen,actionOpenPinned } from '../../../../redux/control/action';
  15. import { TPinnedMessages } from '../../../../typescript/redux/pinnedMessages/types';
  16. const useStyles = makeStyles({
  17. toolBar: {
  18. color: '#6e6d6d',
  19. display: 'flex',
  20. justifyContent: 'space-between',
  21. backgroundColor: '#ffffff',
  22. height:'7vh'
  23. },
  24. toolBarPinned: {
  25. color: '#6e6d6d',
  26. display: 'flex',
  27. alignItems: 'center',
  28. alignContent:'center',
  29. backgroundColor: '#ffffff',
  30. height: '7vh',
  31. cursor:'pointer'
  32. },
  33. pinnedBack: {
  34. display: 'flex',
  35. width:'100%',
  36. alignContent: 'center',
  37. alignItems: 'center',
  38. flexWrap: 'nowrap',
  39. },
  40. credentials: {
  41. background: '#fdfdfd',
  42. width:'100%',
  43. height: '100%',
  44. margin:'0 auto'
  45. },
  46. toolBarRight: {
  47. display: 'flex',
  48. },
  49. buttonDelete: {
  50. color: '#f8f8f8',
  51. backgroundColor:'#1d74c5',
  52. },
  53. modalDelete: {
  54. background: '#ffffff',
  55. position: 'absolute',
  56. content:'',
  57. width: '20%',
  58. height:'auto',
  59. left: '40%',
  60. bottom: '48.5%',
  61. borderRadius: 10,
  62. padding: 10,
  63. display: 'flex',
  64. flexDirection:'column'
  65. },
  66. overlay: {
  67. position: 'fixed',
  68. top: 0,
  69. left: 0,
  70. width: '100vw',
  71. height: '100vh',
  72. zIndex: 100,
  73. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  74. overflowY: 'hidden',
  75. },
  76. iconArrow: {
  77. '&:hover': {
  78. transform: 'rotate(360deg)',
  79. transition: 'all 250ms ease-out ',
  80. }
  81. },
  82. })
  83. interface IHeaderBar {
  84. chatDivRef: any | null,
  85. selectedArr: string[] | [],
  86. isSomeSelected: boolean,
  87. setIsSomeSelected: React.Dispatch<React.SetStateAction<boolean>>,
  88. handleClearSelect: () => void,
  89. openPinned: boolean,
  90. pinnedMessagesMemo: TPinnedMessages,
  91. socket:any
  92. }
  93. const HeaderBar = ({chatDivRef,selectedArr,isSomeSelected,setIsSomeSelected,handleClearSelect,openPinned,pinnedMessagesMemo,socket}:IHeaderBar) => {
  94. const classes = useStyles()
  95. const dispatch = useDispatch()
  96. const { companionId } = useSelector(getChatMemo)
  97. const [modal, setModal] = useState<boolean>(false)
  98. const handleClosePinned = (e: any) => {
  99. e.stopPropagation()
  100. dispatch(actionOpenPinned(false))
  101. }
  102. const handleOpenPinned = () => dispatch(actionOpenPinned(true))
  103. const handleOpenCredentials = (e: any) => {
  104. e.stopPropagation()
  105. dispatch(actionRightIsOpen('credentials'))
  106. }
  107. const handleOpenModal = (): void => setModal(true)
  108. const handleDeleteModal = (e: any) => {
  109. const id = e.target.id
  110. if (id === 'overlay') return setModal(false)
  111. if (id === 'cancel') {
  112. handleClearSelect()
  113. setModal(false)
  114. }
  115. if (id === 'delete') {
  116. removeSelectedMessagesById(companionId,selectedArr)
  117. handleClearSelect()
  118. setModal(false)
  119. }
  120. }
  121. return (<>
  122. {!isSomeSelected&&openPinned &&pinnedMessagesMemo.length > 0&&
  123. <AppBar position="static">
  124. <Toolbar className={classes.toolBarPinned}>
  125. <div onClick={handleOpenCredentials} className={classes.pinnedBack}>
  126. <IconButton onClick={handleClosePinned}
  127. aria-label="delete" size="medium">
  128. <ArrowBackIcon className={classes.iconArrow} fontSize='medium'/>
  129. </IconButton>
  130. <Typography style={{ marginLeft:20, color: '#474747'}} variant="h6" color="initial">
  131. {`${pinnedMessagesMemo.length} pinned messages`}
  132. </Typography>
  133. </div>
  134. <Buttons setIsSomeSelected={setIsSomeSelected} socket={socket} />
  135. </Toolbar>
  136. </AppBar>}
  137. {!openPinned && !isSomeSelected &&
  138. <AppBar position="static">
  139. <Toolbar className={classes.toolBar}>
  140. <Credentials/>
  141. <div className={classes.toolBarRight}>
  142. <PinnedBar chatDivRef={chatDivRef} handleOpenPinned={handleOpenPinned}/>
  143. <Buttons setIsSomeSelected={setIsSomeSelected} socket={socket}/>
  144. </div>
  145. </Toolbar>
  146. </AppBar>}
  147. {isSomeSelected &&
  148. <AppBar position="static">
  149. <Toolbar className={classes.toolBar}>
  150. <Button color='primary' onClick={handleOpenModal}
  151. variant="contained" className={classes.buttonDelete}
  152. style={{visibility: selectedArr.length === 0 ? 'hidden' : 'visible',
  153. fontWeight:500}}>
  154. {`DELETE ${selectedArr.length}`}
  155. </Button>
  156. <Button onClick={handleClearSelect} style={{color:'#1d74c5',fontWeight:500}}>
  157. CANCEL
  158. </Button>
  159. </Toolbar>
  160. {modal &&
  161. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  162. <div className={classes.modalDelete}>
  163. <h3 style={{color: '#2c2c2c'}}>Delete messages</h3>
  164. <p style={{ color: '#050505' }}>Are you sure you want to delete messages?</p>
  165. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  166. DELETE MESSAGES
  167. </Button>
  168. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  169. CANCEL
  170. </Button>
  171. </div>
  172. </div>}
  173. </AppBar>}
  174. </>
  175. )
  176. }
  177. export default HeaderBar