Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

MiniChatColumn.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React, { useEffect, useMemo } from "react";
  2. import PropTypes from "prop-types";
  3. import { MiniChatColumnContainer } from "./MiniChatColumn.styled";
  4. import MiniChatCard from "../../Cards/MiniChatCard/MiniChatCard";
  5. import { useDispatch, useSelector } from "react-redux";
  6. import {
  7. selectLatestChats,
  8. selectSelectedChat,
  9. } from "../../../store/selectors/chatSelectors";
  10. import { fetchChats } from "../../../store/actions/chat/chatActions";
  11. import MiniChatColumnHeader from "./MiniChatColumnHeader/MiniChatColumnHeaderTitle";
  12. import { useLocation } from "react-router-dom";
  13. import { selectOffer } from "../../../store/selectors/offersSelectors";
  14. const MiniChatColumn = () => {
  15. const chats = useSelector(selectLatestChats);
  16. const selectedChat = useSelector(selectSelectedChat);
  17. const offer = useSelector(selectOffer);
  18. const location = useLocation();
  19. const dispatch = useDispatch();
  20. const newChat = useMemo(() => {
  21. if (location.state?.offerId) {
  22. return {
  23. interlocutorData: {
  24. image: offer?.companyData?.image,
  25. name: offer?.companyData?.company?.name,
  26. },
  27. offerData: {
  28. name: offer?.offer?.name,
  29. },
  30. };
  31. }
  32. return {};
  33. }, [offer, location.state]);
  34. useEffect(() => {
  35. dispatch(fetchChats());
  36. }, []);
  37. return (
  38. <MiniChatColumnContainer>
  39. <MiniChatColumnHeader />
  40. {location.state?.offerId && <MiniChatCard chat={newChat} selected />}
  41. {chats.map((item) => {
  42. return (
  43. <MiniChatCard
  44. key={Date.now() * Math.random()}
  45. chat={item}
  46. selected={
  47. item?.chat?._id === selectedChat?.chat?._id
  48. }
  49. />
  50. );
  51. })}
  52. </MiniChatColumnContainer>
  53. );
  54. };
  55. MiniChatColumn.propTypes = {
  56. children: PropTypes.node,
  57. };
  58. export default MiniChatColumn;