index.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 Divider from '@mui/material/Divider';
  10. import Credentials from './Credentials'
  11. import Buttons from './Buttons'
  12. import PinnedBar from './PinnedBar';
  13. import { removeSelectedMessagesById } from '../../../../api-data';
  14. import { getChatMemo } from '../../../../redux/chat/selector';
  15. import { actionRightIsOpen,actionOpenPinned } from '../../../../redux/control/action';
  16. import { TPinnedMessages } from '../../../../typescript/redux/pinnedMessages/types';
  17. const useStyles = makeStyles({
  18. toolBar: {
  19. color: '#6e6d6d',
  20. display: 'flex',
  21. justifyContent: 'space-between',
  22. backgroundColor: '#ffffff',
  23. height:'7vh'
  24. },
  25. toolBarPinned: {
  26. color: '#6e6d6d',
  27. display: 'flex',
  28. alignItems: 'center',
  29. alignContent:'center',
  30. backgroundColor: '#ffffff',
  31. height: '7vh',
  32. cursor:'pointer'
  33. },
  34. pinnedBack: {
  35. display: 'flex',
  36. width:'100%',
  37. alignContent: 'center',
  38. alignItems: 'center',
  39. flexWrap: 'nowrap',
  40. },
  41. credentials: {
  42. background: '#fdfdfd',
  43. width:'100%',
  44. height: '100%',
  45. margin:'0 auto'
  46. },
  47. toolBarRight: {
  48. display: 'flex',
  49. },
  50. buttonDelete: {
  51. color: '#f8f8f8',
  52. backgroundColor:'#1d74c5',
  53. },
  54. modalDelete: {
  55. background: '#ffffff',
  56. position: 'absolute',
  57. content:'',
  58. width: '20%',
  59. height:'auto',
  60. left: '40%',
  61. bottom: '48.5%',
  62. borderRadius: 10,
  63. padding: 10,
  64. display: 'flex',
  65. flexDirection:'column'
  66. },
  67. overlay: {
  68. position: 'fixed',
  69. top: 0,
  70. left: 0,
  71. width: '100vw',
  72. height: '100vh',
  73. zIndex: 100,
  74. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  75. overflowY: 'hidden',
  76. },
  77. iconArrow: {
  78. '&:hover': {
  79. transform: 'rotate(360deg)',
  80. transition: 'all 250ms ease-out ',
  81. }
  82. },
  83. })
  84. interface IHeaderBar {
  85. chatDivRef: any | null,
  86. selectedArr: string[] | [],
  87. isSomeSelected: boolean,
  88. setIsSomeSelected: React.Dispatch<React.SetStateAction<boolean>>,
  89. handleClearSelect: () => void,
  90. openPinned: boolean,
  91. pinnedMessagesMemo:TPinnedMessages
  92. }
  93. const HeaderBar = ({chatDivRef,selectedArr,isSomeSelected,setIsSomeSelected,handleClearSelect,openPinned,pinnedMessagesMemo}: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. {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}/>
  135. </Toolbar>
  136. </AppBar>}
  137. {openPinned&&isSomeSelected&&<Divider variant="inset"/>}
  138. {!openPinned && !isSomeSelected &&
  139. <AppBar position="static">
  140. <Toolbar className={classes.toolBar}>
  141. <Credentials/>
  142. <div className={classes.toolBarRight}>
  143. <PinnedBar chatDivRef={chatDivRef} handleOpenPinned={handleOpenPinned}/>
  144. <Buttons setIsSomeSelected={setIsSomeSelected}/>
  145. </div>
  146. </Toolbar>
  147. </AppBar>}
  148. {isSomeSelected &&
  149. <AppBar position="static">
  150. <Toolbar className={classes.toolBar}>
  151. <Button color='primary' onClick={handleOpenModal}
  152. variant="contained" className={classes.buttonDelete}
  153. style={{visibility: selectedArr.length === 0 ? 'hidden' : 'visible',
  154. fontWeight:500}}>
  155. {`DELETE ${selectedArr.length}`}
  156. </Button>
  157. <Button onClick={handleClearSelect} style={{color:'#1d74c5',fontWeight:500}}>
  158. CANCEL
  159. </Button>
  160. </Toolbar>
  161. {modal &&
  162. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  163. <div className={classes.modalDelete}>
  164. <h3 style={{color: '#2c2c2c'}}>Delete messages</h3>
  165. <p style={{ color: '#050505' }}>Are you sure you want to delete messages?</p>
  166. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  167. DELETE MESSAGES
  168. </Button>
  169. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  170. CANCEL
  171. </Button>
  172. </div>
  173. </div>}
  174. </AppBar>}
  175. </>
  176. )
  177. }
  178. export default HeaderBar