index.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. }
  92. const HeaderBar = ({chatDivRef,selectedArr,isSomeSelected,setIsSomeSelected,handleClearSelect,openPinned,pinnedMessagesMemo}:IHeaderBar) => {
  93. const classes = useStyles()
  94. const dispatch = useDispatch()
  95. const { companionId } = useSelector(getChatMemo)
  96. const [modal, setModal] = useState<boolean>(false)
  97. const handleClosePinned = (e: any) => {
  98. e.stopPropagation()
  99. dispatch(actionOpenPinned(false))
  100. }
  101. const handleOpenPinned = () => dispatch(actionOpenPinned(true))
  102. const handleOpenCredentials = (e: any) => {
  103. e.stopPropagation()
  104. dispatch(actionRightIsOpen('credentials'))
  105. }
  106. const handleOpenModal = (): void => setModal(true)
  107. const handleDeleteModal = (e: any) => {
  108. const id = e.target.id
  109. if (id === 'overlay') return setModal(false)
  110. if (id === 'cancel') {
  111. handleClearSelect()
  112. setModal(false)
  113. }
  114. if (id === 'delete') {
  115. removeSelectedMessagesById(companionId,selectedArr)
  116. handleClearSelect()
  117. setModal(false)
  118. }
  119. }
  120. return (<>
  121. {!isSomeSelected&&openPinned &&pinnedMessagesMemo.length > 0&&
  122. <AppBar position="static">
  123. <Toolbar className={classes.toolBarPinned}>
  124. <div onClick={handleOpenCredentials} className={classes.pinnedBack}>
  125. <IconButton onClick={handleClosePinned}
  126. aria-label="delete" size="medium">
  127. <ArrowBackIcon className={classes.iconArrow} fontSize='medium'/>
  128. </IconButton>
  129. <Typography style={{ marginLeft:20, color: '#474747'}} variant="h6" color="initial">
  130. {`${pinnedMessagesMemo.length} pinned messages`}
  131. </Typography>
  132. </div>
  133. <Buttons setIsSomeSelected={setIsSomeSelected}/>
  134. </Toolbar>
  135. </AppBar>}
  136. {!openPinned && !isSomeSelected &&
  137. <AppBar position="static">
  138. <Toolbar className={classes.toolBar}>
  139. <Credentials/>
  140. <div className={classes.toolBarRight}>
  141. <PinnedBar chatDivRef={chatDivRef} handleOpenPinned={handleOpenPinned}/>
  142. <Buttons setIsSomeSelected={setIsSomeSelected}/>
  143. </div>
  144. </Toolbar>
  145. </AppBar>}
  146. {isSomeSelected &&
  147. <AppBar position="static">
  148. <Toolbar className={classes.toolBar}>
  149. <Button color='primary' onClick={handleOpenModal}
  150. variant="contained" className={classes.buttonDelete}
  151. style={{visibility: selectedArr.length === 0 ? 'hidden' : 'visible',
  152. fontWeight:500}}>
  153. {`DELETE ${selectedArr.length}`}
  154. </Button>
  155. <Button onClick={handleClearSelect} style={{color:'#1d74c5',fontWeight:500}}>
  156. CANCEL
  157. </Button>
  158. </Toolbar>
  159. {modal &&
  160. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  161. <div className={classes.modalDelete}>
  162. <h3 style={{color: '#2c2c2c'}}>Delete messages</h3>
  163. <p style={{ color: '#050505' }}>Are you sure you want to delete messages?</p>
  164. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  165. DELETE MESSAGES
  166. </Button>
  167. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  168. CANCEL
  169. </Button>
  170. </div>
  171. </div>}
  172. </AppBar>}
  173. </>
  174. )
  175. }
  176. export default HeaderBar