Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5328 | Rev 5331 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 5328 Rev 5329
Línea 1... Línea 1...
1
/* eslint-disable camelcase */
1
/* eslint-disable camelcase */
2
/* eslint-disable react/prop-types */
2
/* eslint-disable react/prop-types */
3
import React, { useState, useRef, useEffect } from 'react'
3
import React, { useEffect, useRef, useState } from 'react'
4
import { axios } from '../../../utils'
4
import { axios } from '../../../utils'
5
import styled from 'styled-components'
-
 
6
import Emojione from './emojione/Emojione'
-
 
7
import SendFileModal from './send-file-modal/SendFileModal'
-
 
8
import ConfirmModal from '../../../shared/confirm-modal/ConfirmModal'
-
 
9
import MessageTemplate from './messageTemplate/MessageTemplate'
-
 
10
import { Modal } from 'react-bootstrap'
5
import { Modal } from 'react-bootstrap'
11
import { useForm } from 'react-hook-form'
6
import { useForm } from 'react-hook-form'
12
import FormErrorFeedback from '../../../shared/form-error-feedback/FormErrorFeedback'
-
 
13
import 'react-datetime/css/react-datetime.css'
-
 
14
import Datetime from 'react-datetime'
-
 
15
import { addNotification } from '../../../redux/notification/notification.actions'
7
import { addNotification } from '../../../redux/notification/notification.actions'
16
import Spinner from '../../../shared/loading-spinner/Spinner'
8
import { getMessages } from '../../../redux/conversation/conversation.actions'
17
import { useDispatch, useSelector } from 'react-redux'
9
import { useDispatch, useSelector } from 'react-redux'
-
 
10
import styled from 'styled-components'
-
 
11
import Datetime from 'react-datetime'
18
import SearchIcon from '@mui/icons-material/Search'
12
import SearchIcon from '@mui/icons-material/Search'
-
 
13
import Emojione from './emojione/Emojione'
-
 
14
import SendFileModal from './send-file-modal/SendFileModal'
-
 
15
import MessageTemplate from './messageTemplate/MessageTemplate'
-
 
16
import ConfirmModal from '../../../shared/confirm-modal/ConfirmModal'
19
import EmptySection from '../../../shared/empty-section/EmptySection'
17
import EmptySection from '../../../shared/empty-section/EmptySection'
20
import { getMessages } from '../../../redux/conversation/conversation.actions'
18
import FormErrorFeedback from '../../../shared/form-error-feedback/FormErrorFeedback'
-
 
19
 
-
 
20
import 'react-datetime/css/react-datetime.css'
Línea 21... Línea 21...
21
 
21
 
22
const StyledShowOptions = styled.div`
22
const StyledShowOptions = styled.div`
23
  height: 342px;
23
  height: 342px;
24
  flex-direction: column;
24
  flex-direction: column;
Línea 59... Línea 59...
59
      border-bottom: 1px solid #e2e2e2;
59
      border-bottom: 1px solid #e2e2e2;
60
    }
60
    }
61
  }
61
  }
62
`
62
`
Línea -... Línea 63...
-
 
63
 
-
 
64
const OPTIONS = {
-
 
65
  GROUP: 'group',
-
 
66
  CONFERENCE: 'conference',
-
 
67
  ADD_CONTACTS: 'addContacts',
-
 
68
  LIST_CONTACTS: 'listContacts',
-
 
69
  INITIAL: null
-
 
70
}
63
 
71
 
64
const PersonalChat = ({ entity, onClose, onMinimize, onRead, not_seen_messages, minimized, timezones }) => {
72
const PersonalChat = ({ entity, onClose, onMinimize, onRead, not_seen_messages, minimized, timezones }) => {
65
  const {
73
  const {
66
    id,
74
    id,
67
    image,
75
    image,
Línea 81... Línea 89...
81
  } = entity
89
  } = entity
Línea 82... Línea 90...
82
 
90
 
83
  const { messages, currentPage, lastPage, loading } = useSelector((state) => state.conversation)
91
  const { messages, currentPage, lastPage, loading } = useSelector((state) => state.conversation)
Línea 84... Línea 92...
84
  const dispatch = useDispatch()
92
  const dispatch = useDispatch()
Línea 85... Línea 93...
85
 
93
 
86
  const [optionTab, setOptionTab] = useState('default')
94
  const [optionTab, setOptionTab] = useState(OPTIONS.INITIAL)
Línea 87... Línea -...
87
 
-
 
88
  const [availableContactsToAdd, setAvailableContactsToAdd] = useState([])
95
 
89
  const [groupContactsList, setGroupContactsList] = useState([])
96
  const [availableContactsToAdd, setAvailableContactsToAdd] = useState([])
90
 
97
  const [groupContactsList, setGroupContactsList] = useState([])
91
  const [showOptions, setShowOptions] = useState(false)
98
 
Línea 100... Línea 107...
100
 
107
 
101
  // refs
108
  // refs
102
  const conversationListEl = useRef(null)
109
  const conversationListEl = useRef(null)
103
  const loader = useRef(null)
110
  const loader = useRef(null)
104
  const modalActionUrl = useRef('')
-
 
105
  const chatboxEl = useRef(null)
111
  const modalActionUrl = useRef('')
Línea 106... Línea 112...
106
  const textAreaEl = useRef(null)
112
  const textAreaEl = useRef(null)
107
 
113
 
108
  const handleActive = () => {
114
  const handleActive = () => {
Línea 154... Línea 160...
154
      setShowEmojiTab(false)
160
      setShowEmojiTab(false)
155
      // setResponseMessage(null)
161
      // setResponseMessage(null)
156
    }
162
    }
157
  }
163
  }
Línea 158... Línea 164...
158
 
164
 
159
  const handleShowOptions = () => {
165
  const showOptions = (tab = OPTIONS.INITIAL) => {
160
    onMinimize(entity, false)
-
 
161
    setShowOptions(!showOptions)
-
 
162
  }
-
 
163
 
-
 
164
  const handleChangeTab = (tab) => {
166
    onMinimize(entity, false)
165
    setOptionTab(tab)
167
    setOptionTab(tab)
Línea 166... Línea 168...
166
  }
168
  }
167
 
169
 
Línea 220... Línea 222...
220
      cursorPosition + unicode.length,
222
      cursorPosition + unicode.length,
221
      cursorPosition + unicode.length
223
      cursorPosition + unicode.length
222
    )
224
    )
223
  }
225
  }
Línea 224... Línea -...
224
 
-
 
225
  // useEffect(() => {
-
 
226
  //   setMessages([...oldMessages, ...newMessages]);
-
 
227
  // }, [newMessages, oldMessages]);
-
 
228
 
-
 
229
  // getMessageOnMaximize and subscribe to infinite Loader
-
 
230
  useEffect(async () => {
-
 
231
    const options = {
-
 
232
      root: null,
-
 
233
      rootMargin: '20px',
-
 
234
      treshold: 1.0
-
 
235
    }
-
 
236
    const observer = new IntersectionObserver(handleObserver, options)
-
 
237
    if (!minimized) {
-
 
238
      await handleGetMessages()
-
 
239
      // loader observer
-
 
240
      if (loader.current) {
-
 
241
        observer.observe(loader.current)
-
 
242
      }
-
 
243
    }
-
 
244
    return () => {
-
 
245
      if (loader.current) {
-
 
246
        observer.unobserve(loader.current)
-
 
247
      }
-
 
248
    }
-
 
249
  }, [minimized])
-
 
250
 
-
 
251
  // LoadMore on change page
-
 
252
  useEffect(() => {
-
 
253
    let loadMore = () => handleLoadMore()
-
 
254
    loadMore()
-
 
255
    return () => {
-
 
256
      loadMore = null
-
 
257
    }
-
 
258
  }, [currentPage])
-
 
259
 
-
 
260
  // getMessagesInterval
-
 
261
  useEffect(() => {
-
 
262
    if (window.location.pathname === '/group/my-groups') {
-
 
263
      const items = document.getElementsByClassName('sc-jSgupP')
-
 
264
      if (items && items.length > 0) { items[0].style.display = 'none' }
-
 
265
    }
-
 
266
  }, [minimized])
-
 
267
 
-
 
268
  useEffect(() => {
-
 
269
    let timer
-
 
270
    if (!minimized && !loading) {
-
 
271
      timer = setTimeout(() => handleGetMessages(), 1000)
-
 
272
    }
-
 
273
    return () => {
-
 
274
      clearTimeout(timer)
-
 
275
    }
-
 
276
  }, [minimized, loading])
-
 
277
 
226
 
Línea 278... Línea 227...
278
  const handleConfirmModalShow = () => setConfirmModalShow(!confirmModalShow)
227
  const handleConfirmModalShow = () => setConfirmModalShow(!confirmModalShow)
Línea 279... Línea 228...
279
 
228
 
Línea 305... Línea 254...
305
        ))}
254
        ))}
306
      </>
255
      </>
307
    )
256
    )
308
  }
257
  }
Línea 309... Línea -...
309
 
-
 
310
  // useEffect for tabs changing
-
 
311
  useEffect(() => {
-
 
312
    if (optionTab === 'addContacts') loadPersonsAvailable()
-
 
313
    if (optionTab === 'listContacts') loadGroupContacts()
-
 
314
  }, [optionTab])
-
 
315
 
258
 
316
  const loadPersonsAvailable = async () => {
259
  const loadPersonsAvailable = async () => {
317
    await axios.get(url_get_contacts_availables_for_group).then((response) => {
260
    await axios.get(url_get_contacts_availables_for_group).then((response) => {
318
      const resData = response.data
261
      const resData = response.data
319
      if (resData.success) {
262
      if (resData.success) {
Línea 342... Línea 285...
342
 
285
 
343
  const tabsOptions = {
286
  const tabsOptions = {
344
    group:
287
    group:
345
      <ul>
288
      <ul>
346
        {url_get_contact_group_list &&
289
        {url_get_contact_group_list &&
347
          <li className="optionsTab__option" onClick={() => handleChangeTab('listContacts')}>
290
          <li className="optionsTab__option" onClick={() => showOptions(OPTIONS.LIST_CONTACTS)}>
348
            <span className="optionsTab__option__icon">
291
            <span className="optionsTab__option__icon">
349
              <i className="fa fa-group" />
292
              <i className="fa fa-group" />
350
              Integrantes
293
              Integrantes
351
            </span>
294
            </span>
352
          </li>
295
          </li>
353
        }
296
        }
354
        {url_add_user_to_group &&
297
        {url_add_user_to_group &&
355
          <li className="optionsTab__option" onClick={() => handleChangeTab('addContacts')}>
298
          <li className="optionsTab__option" onClick={() => showOptions(OPTIONS.ADD_CONTACTS)}>
356
            <span className="optionsTab__option__icon">
299
            <span className="optionsTab__option__icon">
357
              <i className="fa fa-user-plus"></i>
300
              <i className="fa fa-user-plus"></i>
358
            </span>
301
            </span>
359
            {CHAT_LABELS.ADD_CONTACTS}
302
            {CHAT_LABELS.ADD_CONTACTS}
Línea 467... Línea 410...
467
          : <div className="addPersonToGroupTab__person">{CHAT_LABELS.NOT_CONTACTS}</div>
410
          : <div className="addPersonToGroupTab__person">{CHAT_LABELS.NOT_CONTACTS}</div>
468
        }
411
        }
469
      </>
412
      </>
470
  }
413
  }
Línea -... Línea 414...
-
 
414
 
-
 
415
  // useEffect(() => {
-
 
416
  //   setMessages([...oldMessages, ...newMessages]);
-
 
417
  // }, [newMessages, oldMessages]);
-
 
418
 
-
 
419
  // getMessageOnMaximize and subscribe to infinite Loader
-
 
420
  useEffect(async () => {
-
 
421
    const options = {
-
 
422
      root: null,
-
 
423
      rootMargin: '20px',
-
 
424
      treshold: 1.0
-
 
425
    }
-
 
426
    const observer = new IntersectionObserver(handleObserver, options)
-
 
427
    if (!minimized) {
-
 
428
      await handleGetMessages()
-
 
429
      // loader observer
-
 
430
      if (loader.current) {
-
 
431
        observer.observe(loader.current)
-
 
432
      }
-
 
433
    }
-
 
434
    return () => {
-
 
435
      if (loader.current) {
-
 
436
        observer.unobserve(loader.current)
-
 
437
      }
-
 
438
    }
-
 
439
  }, [minimized])
-
 
440
 
-
 
441
  // LoadMore on change page
-
 
442
  useEffect(() => {
-
 
443
    let loadMore = () => handleLoadMore()
-
 
444
    loadMore()
-
 
445
    return () => {
-
 
446
      loadMore = null
-
 
447
    }
-
 
448
  }, [currentPage])
-
 
449
 
-
 
450
  // getMessagesInterval
-
 
451
  useEffect(() => {
-
 
452
    if (window.location.pathname === '/group/my-groups') {
-
 
453
      const items = document.getElementsByClassName('sc-jSgupP')
-
 
454
      if (items && items.length > 0) { items[0].style.display = 'none' }
-
 
455
    }
-
 
456
  }, [minimized])
-
 
457
 
-
 
458
  useEffect(() => {
-
 
459
    let timer
-
 
460
    if (!minimized && !loading) {
-
 
461
      timer = setTimeout(() => handleGetMessages(), 1000)
-
 
462
    }
-
 
463
    return () => {
-
 
464
      clearTimeout(timer)
-
 
465
    }
-
 
466
  }, [minimized, loading])
-
 
467
 
-
 
468
  // useEffect for tabs changing
-
 
469
  useEffect(() => {
-
 
470
    if (optionTab === 'addContacts') loadPersonsAvailable()
-
 
471
    if (optionTab === 'listContacts') loadGroupContacts()
-
 
472
  }, [optionTab])
471
 
473
 
472
  return (
474
  return (
473
    <>
475
    <>
Línea 474... Línea 476...
474
      <div className="personal-chat">
476
      <div className="personal-chat">
475
 
477
 
476
        <div className={`chat-header ${not_seen_messages ? 'notify' : ''}`}>
478
        <div className={`chat-header ${not_seen_messages ? 'notify' : ''}`}>
477
          <img src={image} alt="avatar-image" />
479
          <img src={image} alt="avatar-image" />
478
          <div className="info-content">
480
          <div className="info-content">
479
            <a href={profile} target="_blank" rel="noreferrer">{name}</a>
481
            <a href={profile} target="_blank" rel="noreferrer">{name}</a>
480
            {type === 'user' && <small className={online ? 'online' : 'offline'} >{online ? 'En línea' : 'Desconectado'}</small>}
-
 
481
          </div>
482
            {type === 'user' && <small className={online ? 'online' : 'offline'} >{online ? 'En línea' : 'Desconectado'}</small>}
482
 
483
          </div>
483
          <div className="options">
-
 
484
            <i className="cursor-pointer fa fa-gear"
484
          <div className="options">
485
              onClick={() => {
-
 
486
                if (type === 'user') handleChangeTab('conference')
-
 
487
                handleShowOptions()
485
            <i className="cursor-pointer fa fa-gear"
488
              }} />
486
              onClick={() => showOptions(type === 'user' ? OPTIONS.CONFERENCE : OPTIONS.GROUP)} />
489
            <i className={'cursor-pointer fa fa-minus-circle'} onClick={handleActive} />
487
            <i className={'cursor-pointer fa fa-minus-circle'} onClick={handleActive} />
490
            <i className="cursor-pointer fa fa-times-circle" onClick={handleCloseChat} />
488
            <i className="cursor-pointer fa fa-times-circle" onClick={handleCloseChat} />
Línea 491... Línea 489...
491
          </div>
489
          </div>
Línea -... Línea 490...
-
 
490
        </div>
492
        </div>
491
 
493
 
492
        <div className="panel-body" style={{ display: !minimized ? 'block' : 'none' }}>
494
        <div className="panel-body" style={{ display: !minimized ? 'block' : 'none' }}>
493
 
495
 
494
        {optionTab
496
          <StyledShowOptions className={` ${showOptions ? 'show' : 'hide'}`}>
495
          ? <StyledShowOptions>
497
            <span className="optionBack" onClick={() => optionTab !== 'default' ? handleChangeTab('default') : handleShowOptions()}>
496
            <span className="optionBack" onClick={() => showOptions()}>
498
              <i className="fa icon-arrow-left" />
497
              <i className="fa icon-arrow-left" />
499
            </span>
498
            </span>
500
            <div className="optionsTab">
-
 
501
              {tabsOptions[optionTab]}
499
            <div className="optionsTab">
502
            </div>
500
              {tabsOptions[optionTab]}
503
          </StyledShowOptions>
501
            </div>
504
 
502
          </StyledShowOptions>
505
          <div className="chat-conversation" style={{ display: showOptions ? 'none' : 'block' }}>
503
          : <div className="chat-conversation">
506
            <div className="reverseChatBox" ref={conversationListEl}>
504
            <div className="reverseChatBox" ref={conversationListEl}>
Línea 553... Línea 551...
553
 
551
 
554
              </div>
552
              </div>
Línea 555... Línea 553...
555
            </div>
553
            </div>
-
 
554
 
556
 
555
          </div>
-
 
556
        }
557
          </div>
557
        </div>
558
        </div>
558
 
559
      </div>
559
      </div>
560
      <ConfirmModal
560
      <ConfirmModal
561
        show={confirmModalShow}
561
        show={confirmModalShow}
Línea 565... Línea 565...
565
      <ConferenceModal
565
      <ConferenceModal
566
        show={showConferenceModal}
566
        show={showConferenceModal}
567
        timezones={timezones}
567
        timezones={timezones}
568
        zoomUrl={url_zoom}
568
        zoomUrl={url_zoom}
569
        onCreate={() => {
569
        onCreate={() => {
570
          handleShowOptions()
570
          showOptions()
571
          displayConferenceModal()
571
          displayConferenceModal()
572
        }}
572
        }}
573
      />
573
      />
574
      <SendFileModal
574
      <SendFileModal
575
        show={shareFileModalShow}
575
        show={shareFileModalShow}