Proyectos de Subversion LeadersLinked - Backend

Rev

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