ChatPageHeader.jsx 1.4 KB

123456789101112131415161718192021222324252627282930
  1. import { connect } from "react-redux"
  2. import TableChartOutlinedIcon from '@mui/icons-material/TableChartOutlined';
  3. import { ChatListItemTitle } from "../ChatListItem/ChatListItem.style"
  4. import { ChatMembersAmount, ChatPageHeaderWrap } from "./ChatPageHeader.style"
  5. import ChatInfoDrawer from "../ChatInfoDrawer/ChatInfoDrawer";
  6. import { memo, useState } from "react";
  7. import IconButton from '@mui/material/IconButton';
  8. import { actionOpenModal } from "../../actions/actionsForModal";
  9. const ChatPageHeader = ({ chats, chatId, openModal}) => {
  10. const [isOpen, setOpen] = useState(false);
  11. const amount = chats[chatId]?.members?.length;
  12. return (
  13. <ChatPageHeaderWrap>
  14. <div style={{cursor: "pointer"}} onClick={() => openModal("chatInfoModal")}>
  15. <ChatListItemTitle>{chats[chatId]?.title}</ChatListItemTitle>
  16. <ChatMembersAmount>{amount} {amount === 1 ? 'member' : 'members'}</ChatMembersAmount>
  17. </div>
  18. <div>
  19. <IconButton sx={{ ...(isOpen && { display: 'none' }) }} onClick={() => setOpen(true)}>
  20. <TableChartOutlinedIcon />
  21. </IconButton>
  22. <ChatInfoDrawer open={isOpen} closeChatMenu={() => setOpen(false)}/>
  23. </div>
  24. </ChatPageHeaderWrap>
  25. )
  26. }
  27. export default connect(state => ({chats : state?.chats || []}), {openModal: actionOpenModal})(memo(ChatPageHeader));