| 5138 |
stevensc |
1 |
/* eslint-disable react/prop-types */
|
| 5129 |
stevensc |
2 |
/* eslint-disable camelcase */
|
|
|
3 |
import React, { useEffect, useState } from 'react'
|
|
|
4 |
import { connect } from 'react-redux'
|
| 5130 |
stevensc |
5 |
import { debounce } from '../../../utils'
|
| 5129 |
stevensc |
6 |
import { addNotification } from '../../../redux/notification/notification.actions'
|
| 5130 |
stevensc |
7 |
import { searchEntities } from '../../../services/search'
|
| 5129 |
stevensc |
8 |
import Profile from '../../../components/Profile'
|
|
|
9 |
import SearchList from '../../../components/SearchList'
|
| 5130 |
stevensc |
10 |
import TitleSection from '../../../components/TitleSection'
|
|
|
11 |
import EmptySection from '../../../shared/empty-section/EmptySection'
|
| 5129 |
stevensc |
12 |
import Spinner from '../../../shared/loading-spinner/Spinner'
|
| 1 |
www |
13 |
|
| 5138 |
stevensc |
14 |
const InvitationsReceived = ({ addNotification }) => {
|
| 5129 |
stevensc |
15 |
const [invitationsReceived, setInvitationsReceived] = useState([])
|
|
|
16 |
const [loading, setLoading] = useState(false)
|
| 1 |
www |
17 |
|
|
|
18 |
useEffect(() => {
|
| 5129 |
stevensc |
19 |
fetchInvitations()
|
|
|
20 |
}, [])
|
| 1 |
www |
21 |
|
| 2393 |
stevensc |
22 |
const fetchInvitations = async (searchValue = '') => {
|
| 5129 |
stevensc |
23 |
setLoading(true)
|
| 5130 |
stevensc |
24 |
const response = await searchEntities('connection/invitations-received', searchValue)
|
| 5138 |
stevensc |
25 |
|
|
|
26 |
if (!response.success) {
|
|
|
27 |
addNotification({ style: 'danger', msg: response.data })
|
|
|
28 |
setLoading(false)
|
|
|
29 |
return
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
setInvitationsReceived(response.data)
|
| 5129 |
stevensc |
33 |
setLoading(false)
|
|
|
34 |
}
|
| 1 |
www |
35 |
|
| 5130 |
stevensc |
36 |
const handleSearch = (value) => debounce(fetchInvitations(value), 500)
|
|
|
37 |
|
| 1 |
www |
38 |
return (
|
| 5129 |
stevensc |
39 |
<section className="companies-info container">
|
| 5138 |
stevensc |
40 |
<TitleSection title={LABELS.INVITATIONS_RECEIVED} />
|
|
|
41 |
<SearchList onChange={handleSearch} />
|
|
|
42 |
<div className="companies-list">
|
|
|
43 |
{loading && <Spinner />}
|
| 5139 |
stevensc |
44 |
{(!loading && Boolean(!invitationsReceived.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
|
|
|
45 |
{(!loading && Boolean(invitationsReceived.length)) &&
|
| 5138 |
stevensc |
46 |
invitationsReceived.map(({ name, image, link_approve, link_reject, link_view }, id) =>
|
|
|
47 |
<Profile
|
|
|
48 |
key={id}
|
|
|
49 |
image={image}
|
|
|
50 |
name={name}
|
|
|
51 |
link_approve={link_approve}
|
|
|
52 |
link_reject={link_reject}
|
|
|
53 |
link_view={link_view}
|
|
|
54 |
fetchCallback={fetchInvitations}
|
|
|
55 |
/>
|
|
|
56 |
)}
|
|
|
57 |
</div>
|
| 1 |
www |
58 |
</section>
|
| 5129 |
stevensc |
59 |
)
|
|
|
60 |
}
|
| 1 |
www |
61 |
|
|
|
62 |
const mapDispatchToProps = {
|
| 5129 |
stevensc |
63 |
addNotification: (notification) => addNotification(notification)
|
|
|
64 |
}
|
| 1 |
www |
65 |
|
| 5129 |
stevensc |
66 |
export default connect(null, mapDispatchToProps)(InvitationsReceived)
|