Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3610 stevensc 1
import React, { useRef, useState } from 'react';
2
import { useDispatch } from 'react-redux';
3
 
4
import { axios, scrollToBottom } from '@utils';
5
import { useMessages } from '@hooks';
6
import { addNotification } from '@store/notification/notification.actions';
7
 
8
import Chat from '@components/chat/Chat';
9
import MessagesList from './MessageList0';
10
import ConfirmModal from '@components/modals/ConfirmModal';
11
import Options from '@components/UI/Option';
12
 
13
const InmailChat = ({ conversation, changeConversation }) => {
14
  const [isShowConfirm, setIsShowConfirm] = useState(false);
15
  const messagesList = useRef(null);
16
  const dispatch = useDispatch();
17
 
18
  const { messages, loadMore, loading, report } = useMessages(conversation?.messages_link);
19
 
20
  const deleteConversation = () => {
21
    axios.post(conversation.delete_link).then((response) => {
22
      const { success, data } = response.data;
23
 
24
      if (!success) {
25
        dispatch(addNotification({ style: 'danger', msg: data }));
26
        return;
27
      }
28
 
29
      dispatch(addNotification({ style: 'success', msg: data }));
30
      toggleConfirmModal();
31
      changeConversation(null);
32
    });
33
  };
34
 
35
  const toggleConfirmModal = () => {
36
    setIsShowConfirm(!isShowConfirm);
37
  };
38
 
39
  return (
40
    <>
41
      <Chat>
42
        <Chat.Header onClose={() => changeConversation(null)}>
43
          <Chat.Title url={conversation.profile}>{conversation.name}</Chat.Title>
44
          <Options>
45
            {conversation.delete_link && (
46
              <Options.Item onClick={toggleConfirmModal}>Borrar convesación</Options.Item>
47
            )}
48
          </Options>
49
        </Chat.Header>
50
 
51
        <MessagesList
52
          messages={messages}
53
          onReport={report}
54
          onPagination={loadMore}
55
          loading={loading}
56
          scrollRef={messagesList}
57
        />
58
 
59
        <Chat.SubmitForm
60
          sendUrl={conversation.send_link}
61
          uploadUrl={conversation.send_link}
62
          onSubmit={() => scrollToBottom(messagesList)}
63
        />
64
      </Chat>
65
      <ConfirmModal
66
        show={isShowConfirm}
67
        onClose={toggleConfirmModal}
68
        onAccept={deleteConversation}
69
      />
70
    </>
71
  );
72
};
73
 
74
export default InmailChat;