| 4679 |
stevensc |
1 |
/* eslint-disable react/prop-types */
|
|
|
2 |
import React, { useEffect, useState } from 'react'
|
|
|
3 |
import axios from '../../../utils/axios'
|
|
|
4 |
import { connect } from 'react-redux'
|
|
|
5 |
import { addNotification } from '../../../redux/notification/notification.actions'
|
|
|
6 |
|
|
|
7 |
const ComunicationOptions = ({ sessionLink, Icon, title, url, childs }) => {
|
|
|
8 |
const [messagesCount, setMessagesCount] = useState(0)
|
|
|
9 |
const [loading, setLoading] = useState(false);
|
|
|
10 |
|
|
|
11 |
useEffect(() => {
|
|
|
12 |
let timer;
|
|
|
13 |
if (!loading) {
|
|
|
14 |
timer = setTimeout(() => checkSession(), 1000);
|
|
|
15 |
}
|
|
|
16 |
return () => {
|
|
|
17 |
clearTimeout(timer);
|
|
|
18 |
};
|
|
|
19 |
}, [loading])
|
|
|
20 |
|
|
|
21 |
const checkSession = async () => {
|
|
|
22 |
try {
|
|
|
23 |
setLoading(true)
|
|
|
24 |
const { data: response } = await axios.get(sessionLink)
|
|
|
25 |
const { total_messages } = response.data
|
|
|
26 |
|
|
|
27 |
if (response.success) {
|
|
|
28 |
setMessagesCount(Number(total_messages))
|
|
|
29 |
}
|
|
|
30 |
setLoading(false)
|
|
|
31 |
} catch (error) {
|
|
|
32 |
console.log(error)
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
return (
|
|
|
37 |
<li>
|
| 4742 |
stevensc |
38 |
<a href={url} className="header__option mobile">
|
| 4679 |
stevensc |
39 |
{Icon && <Icon className="header__option-icon" />}
|
|
|
40 |
<span>{title}</span>
|
|
|
41 |
<span className={`badge ${messagesCount ? 'd-block' : 'd-none'}`} style={{ top: '10px' }}>
|
|
|
42 |
{messagesCount}
|
|
|
43 |
</span>
|
|
|
44 |
</a>
|
|
|
45 |
{!!childs.length &&
|
|
|
46 |
<nav className='nav__options-dropdown'>
|
|
|
47 |
<ul>{childs.map((linkOption, index) =>
|
|
|
48 |
<li key={index}>
|
| 4680 |
stevensc |
49 |
<li className='d-flex align-items-center justify-content-between' key={index}>
|
|
|
50 |
<a href={linkOption.href}>{linkOption.label}</a>
|
| 4682 |
stevensc |
51 |
{(linkOption.label === 'Inmail' && messagesCount) &&
|
| 4683 |
stevensc |
52 |
<span className={`badge ${messagesCount ? 'd-block position-relative' : 'd-none'}`} style={{left: 0, transform: 'none'}}>
|
| 4682 |
stevensc |
53 |
{messagesCount}
|
|
|
54 |
</span>}
|
| 4680 |
stevensc |
55 |
</li>
|
| 4679 |
stevensc |
56 |
</li>
|
|
|
57 |
)}
|
|
|
58 |
</ul>
|
|
|
59 |
</nav>
|
|
|
60 |
}
|
|
|
61 |
</li>
|
|
|
62 |
)
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
const mapDispatchToProps = {
|
|
|
66 |
addNotification: (notification) => addNotification(notification),
|
|
|
67 |
};
|
|
|
68 |
|
|
|
69 |
export default connect(null, mapDispatchToProps)(ComunicationOptions)
|