NewChatPage.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import React, { useState } from "react";
  2. import { connect } from "react-redux";
  3. import { useDropzone } from "react-dropzone";
  4. import { Link } from "react-router-dom";
  5. import Button from "react-bootstrap/esm/Button";
  6. import {Input, InputDebounce} from '../helpers/UserSearch'
  7. import { actionSetChatInfo } from "../actions";
  8. import { CChatAvatar } from "../components/Avatar";
  9. const ChatPage = ({ onChat, chat, myProfile, create }) => {
  10. const [img, setImg] = useState(null);
  11. const [title, setTitle] = useState(chat?.title || "");
  12. const [members, setMembers] = useState(chat?.members || [myProfile])
  13. const { getRootProps, getInputProps, isDragActive } = useDropzone({
  14. accept: "image/*",
  15. maxFiles: 1,
  16. onDrop: (acceptedFiles) => {
  17. setImg(acceptedFiles[0]);
  18. },
  19. });
  20. function prepareMembers(members) {
  21. const newMembers = []
  22. for (const member of members) {
  23. if (create) {
  24. if (member._id !== myProfile?._id) {
  25. newMembers.push({ _id: member._id })
  26. }
  27. } else {
  28. newMembers.push({ _id: member._id })
  29. }
  30. }
  31. return newMembers
  32. }
  33. return (
  34. <div className="newChatContainer">
  35. <div {...getRootProps({ className: "dropZoneStyle" })}>
  36. <input {...getInputProps()} />
  37. {isDragActive ? (
  38. <p className="dropZoneStyleBr">Drop the files here ...</p>
  39. ) : (
  40. <CChatAvatar text="upload chat avatar" className="profileStyle" />
  41. )}
  42. </div>
  43. <div className="profileContainer">
  44. <div className="loginNickSetting">
  45. <div className="inputContainer">
  46. <label for="loginInput">Enter the name of the chat: </label>
  47. <input
  48. className="form-control-editing form-control"
  49. id="loginInput"
  50. type="text"
  51. value={title}
  52. onChange={(e) => {
  53. setTitle(e.target.value);
  54. }}
  55. />
  56. </div>
  57. <div className="inputContainer">
  58. </div>
  59. <div className="df">
  60. <Button
  61. variant="primary"
  62. className="buttonSetting"
  63. onClick={() => {
  64. onChat("media", img, title, prepareMembers(members), chat?.id);
  65. console.log("media", title, members, img);
  66. }}
  67. >
  68. <Link
  69. to="/changesdonechats"
  70. style={{
  71. color: "white",
  72. textDecoration: "none",
  73. }}
  74. >
  75. Apply Changes
  76. </Link>
  77. </Button>
  78. <Link to="/main" className="changepasLink">
  79. Back to all chats
  80. </Link>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. );
  86. };
  87. export const CNewChatPage = connect(
  88. (state) => ({
  89. myProfile: state.promise.myProfile?.payload || {},
  90. }),
  91. { onChat: actionSetChatInfo }
  92. )(ChatPage);