Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15828 | Rev 15833 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
15824 stevensc 1
import React, { useEffect, useState } from "react";
2
import { axios } from "../../../utils";
3
 
15801 stevensc 4
import Sidebar from "./Sidebar";
5
import Chat from "../chat/Chat";
15824 stevensc 6
import Modal from "react-bootstrap/Modal";
7
import EmptySection from "../../../shared/empty-section/EmptySection";
11347 nelberth 8
 
15824 stevensc 9
const DesktopChat = ({ chatUsers, chatGroups }) => {
10
  const [selectedConversation, setSelectedConversation] = useState(null);
11
  const [visible, setVisible] = useState(false);
12
 
15829 stevensc 13
  const handleChangeConversation = (conversation) => {
14
    setSelectedConversation(conversation);
15801 stevensc 15
  };
11347 nelberth 16
 
15824 stevensc 17
  const onClose = () => {
18
    setVisible(false);
15801 stevensc 19
  };
11347 nelberth 20
 
15824 stevensc 21
  const handleCloseChat = () => {
22
    console.log(">>: close chat");
15801 stevensc 23
  };
15824 stevensc 24
 
25
  return (
26
    <>
15829 stevensc 27
      <main className="conversation-page px-0 pb-3">
15824 stevensc 28
        <Sidebar
29
          onClick={(conversation) => handleChangeConversation(conversation)}
30
          conversations={[...chatUsers, ...chatGroups]}
31
          selectedConversation={selectedConversation}
32
        />
33
        {!selectedConversation ? (
15828 stevensc 34
          <EmptySection message="Selecciona una conversación" align="center" />
15824 stevensc 35
        ) : (
36
          <Chat entity={selectedConversation} onCloseChat={handleCloseChat} />
37
        )}
38
      </main>
39
      <DesktopChat.ChatModal show={visible} onClose={onClose} />
40
    </>
41
  );
42
};
43
 
44
const ChatModal = ({ show, onClose }) => {
45
  const [inmailPersons, setInmailPersons] = useState([]);
46
  const [search, setSearch] = useState("");
47
 
48
  const handleChange = (searchValue) => {
49
    setSearch(searchValue);
15801 stevensc 50
  };
11347 nelberth 51
 
15824 stevensc 52
  const searchUsers = async () => {
15801 stevensc 53
    try {
15824 stevensc 54
      const { data: response } = await axios.get(
55
        `/helpers/search-people?search=${search}`
56
      );
57
      const { success, data } = response;
58
 
59
      if (!success) {
60
        console.log("Ha ocurrido un error");
15801 stevensc 61
      }
15824 stevensc 62
 
63
      setInmailPersons(data);
15801 stevensc 64
    } catch (error) {
65
      console.log(">>: error > ", error);
11347 nelberth 66
    }
15801 stevensc 67
  };
11347 nelberth 68
 
15801 stevensc 69
  const handleInmailPerson = (uuid) => {
70
    onClose();
71
    window.location.href = "/inmail/" + uuid;
72
    setTimeout(() => {
73
      window.location.reload();
74
    }, 1000);
75
  };
11347 nelberth 76
 
15824 stevensc 77
  useEffect(() => {
78
    searchUsers();
79
  }, [search]);
11347 nelberth 80
 
15801 stevensc 81
  return (
15824 stevensc 82
    <Modal show={show} onHide={onClose}>
83
      <Modal.Header closeButton>
84
        <Modal.Title>Crear sala de Chat</Modal.Title>
85
      </Modal.Header>
86
      <Modal.Body>
87
        <div class="form-group">
88
          <label for="search-people">Direccion de email</label>
89
          <input
90
            type="email"
91
            className="form-control"
92
            aria-describedby="Buscador de personas"
93
            placeholder="Escribe el nombre de la persona"
94
            onChange={handleChange}
95
          />
15801 stevensc 96
        </div>
15824 stevensc 97
        <div className="container">
98
          {inmailPersons.map((element) => {
99
            return (
100
              <div className="row" key={element.value}>
101
                <div className="col-8">
102
                  <p> {element.text} </p>
103
                </div>
104
                <div className="col-4">
105
                  <button
106
                    className="btn btn-primary"
107
                    onClick={() => handleInmailPerson(element.value)}
108
                  >
109
                    <i className="fa fa-check" />
110
                  </button>
111
                </div>
15801 stevensc 112
              </div>
15824 stevensc 113
            );
114
          })}
15801 stevensc 115
        </div>
15824 stevensc 116
      </Modal.Body>
117
      <Modal.Footer>
118
        <button onClick={onClose} className="btn btn-secondary">
119
          Cerrar
120
        </button>
121
      </Modal.Footer>
122
    </Modal>
15801 stevensc 123
  );
124
};
15824 stevensc 125
 
126
DesktopChat.ChatModal = ChatModal;
127
 
128
export default DesktopChat;