Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4815 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 4815 Rev 4946
Línea 1... Línea 1...
1
/* eslint-disable react/prop-types */
1
/* eslint-disable react/prop-types */
2
import React, { useEffect, useRef, useState } from 'react'
2
import React, { useEffect, useRef, useState } from 'react'
3
import axios from '../../../utils/axios'
-
 
4
import { connect } from 'react-redux'
3
import { connect } from 'react-redux'
5
import { addNotification } from '../../../redux/notification/notification.actions'
4
import { addNotification } from '../../../redux/notification/notification.actions'
6
import useOutsideClick from '../../../hooks/useOutsideClick'
5
import useOutsideClick from '../../../hooks/useOutsideClick'
Línea 7... Línea 6...
7
 
6
 
8
const ComunicationOptions = ({ sessionLink, Icon, title, url, childs }) => {
7
const ComunicationOptions = ({
-
 
8
    messagesCount = 0,
-
 
9
    Icon = null,
-
 
10
    title = '',
-
 
11
    url = '',
-
 
12
    childs = []
9
    const [messagesCount, setMessagesCount] = useState(0)
13
}) => {
10
    const [displayMenu, setDisplayMenu] = useState(false)
-
 
11
    const [loading, setLoading] = useState(false);
14
    const [displayMenu, setDisplayMenu] = useState(false)
12
    const outsideClick = useOutsideClick(menu)
15
    const outsideClick = useOutsideClick(menu)
Línea 13... Línea -...
13
    const menu = useRef(null)
-
 
14
 
-
 
15
    const checkSession = async () => {
-
 
16
        try {
-
 
17
            setLoading(true)
-
 
18
            const { data: response } = await axios.get(sessionLink)
-
 
19
            const { total_messages } = response.data
-
 
20
 
-
 
21
            if (response.success) {
-
 
22
                setMessagesCount(Number(total_messages))
-
 
23
            }
-
 
24
            setLoading(false)
-
 
25
        } catch (error) {
-
 
26
            console.log(error)
-
 
27
        }
-
 
28
    }
16
    const menu = useRef(null)
29
 
17
 
30
    const handleClick = (e) => {
18
    const handleClick = (e) => {
31
        e.preventDefault()
19
        e.preventDefault()
Línea 32... Línea 20...
32
        setDisplayMenu(!displayMenu)
20
        setDisplayMenu(!displayMenu)
33
    }
-
 
34
 
-
 
35
    useEffect(() => {
-
 
36
        let timer;
-
 
37
        if (!loading) {
-
 
38
            timer = setTimeout(() => checkSession(), 1000);
-
 
39
        }
-
 
40
        return () => {
-
 
41
            clearTimeout(timer);
-
 
42
        };
-
 
43
    }, [loading])
21
    }
44
 
22
 
Línea 45... Línea 23...
45
    useEffect(() => {
23
    useEffect(() => {
46
        if (outsideClick) setDisplayMenu(false)
24
        if (outsideClick) setDisplayMenu(false)
Línea 75... Línea 53...
75
    )
53
    )
76
}
54
}
Línea 77... Línea 55...
77
 
55
 
78
const mapDispatchToProps = {
56
const mapDispatchToProps = {
79
    addNotification: (notification) => addNotification(notification),
57
    addNotification: (notification) => addNotification(notification),
Línea 80... Línea 58...
80
};
58
}
81
 
59