| 5121 |
stevensc |
1 |
/* eslint-disable camelcase */
|
|
|
2 |
import React, { useEffect, useState } from 'react'
|
|
|
3 |
import { connect } from 'react-redux'
|
| 5144 |
stevensc |
4 |
import { searchEntities } from '../../../services/search'
|
| 5121 |
stevensc |
5 |
import { addNotification } from '../../../redux/notification/notification.actions'
|
|
|
6 |
import Profile from '../../../components/Profile'
|
|
|
7 |
import SearchList from '../../../components/SearchList'
|
|
|
8 |
import Spinner from '../../../shared/loading-spinner/Spinner'
|
|
|
9 |
import PaginationComponent from '../../../shared/pagination/PaginationComponent'
|
|
|
10 |
import EmptySection from '../../../shared/empty-section/EmptySection'
|
|
|
11 |
import TitleSection from '../../../components/TitleSection'
|
| 5144 |
stevensc |
12 |
import { debounce } from '../../../utils'
|
| 1 |
www |
13 |
|
| 4889 |
stevensc |
14 |
const MyConnections = () => {
|
|
|
15 |
const [myConnections, setMyConnections] = useState([])
|
|
|
16 |
const [currentPage, setCurrentPage] = useState(1)
|
|
|
17 |
const [search, setSearch] = useState('')
|
|
|
18 |
const [pages, setPages] = useState(1)
|
|
|
19 |
const [loading, setLoading] = useState(true)
|
| 1 |
www |
20 |
|
| 5144 |
stevensc |
21 |
useEffect(() => {
|
|
|
22 |
fetchMyConnections(search, currentPage)
|
|
|
23 |
}, [currentPage, search])
|
|
|
24 |
|
|
|
25 |
const fetchMyConnections = async (search = '', page = 1) => {
|
| 4891 |
stevensc |
26 |
setLoading(true)
|
| 5144 |
stevensc |
27 |
|
| 5330 |
stevensc |
28 |
const response = await searchEntities('connection/my-connections', search, page)
|
| 5144 |
stevensc |
29 |
|
|
|
30 |
if (!response.success) {
|
|
|
31 |
addNotification({ style: 'danger', msg: response.data })
|
|
|
32 |
setLoading(false)
|
|
|
33 |
return
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
setMyConnections(response.data.current.items)
|
|
|
37 |
setCurrentPage(response.data.current.page)
|
|
|
38 |
setPages(response.data.total.pages)
|
|
|
39 |
|
| 4891 |
stevensc |
40 |
setLoading(false)
|
|
|
41 |
}
|
| 1 |
www |
42 |
|
| 4889 |
stevensc |
43 |
const handleChangePage = (newPage) => setCurrentPage(newPage)
|
|
|
44 |
|
| 5154 |
stevensc |
45 |
const handleSearch = debounce((value) => setSearch(value), 500)
|
| 4891 |
stevensc |
46 |
|
| 1 |
www |
47 |
return (
|
| 5124 |
stevensc |
48 |
<section className="companies-info container">
|
|
|
49 |
<TitleSection title={LABELS.FIRST_LEVEL_PERSONS} />
|
| 5144 |
stevensc |
50 |
<SearchList onChange={handleSearch} />
|
| 5126 |
stevensc |
51 |
<div className="companies-list">
|
| 5144 |
stevensc |
52 |
{loading && <Spinner />}
|
|
|
53 |
{(!loading && Boolean(!myConnections.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
|
|
|
54 |
{(!loading && Boolean(myConnections.length)) &&
|
|
|
55 |
myConnections.map(({ image, name, link_view, link_inmail, link_cancel, link_block }, id) =>
|
| 5124 |
stevensc |
56 |
<Profile
|
|
|
57 |
isTopData
|
|
|
58 |
key={id}
|
|
|
59 |
image={image}
|
|
|
60 |
name={name}
|
|
|
61 |
link_inmail={link_inmail}
|
|
|
62 |
link_view={link_view}
|
|
|
63 |
link_cancel={link_cancel}
|
|
|
64 |
link_block={link_block}
|
|
|
65 |
fetchCallback={fetchMyConnections}
|
|
|
66 |
/>
|
|
|
67 |
)
|
|
|
68 |
}
|
| 1 |
www |
69 |
</div>
|
| 5124 |
stevensc |
70 |
<PaginationComponent
|
|
|
71 |
onChangePage={handleChangePage}
|
|
|
72 |
pages={pages}
|
|
|
73 |
currentActivePage={currentPage}
|
|
|
74 |
isRow={true}
|
|
|
75 |
/>
|
| 1 |
www |
76 |
</section>
|
| 4889 |
stevensc |
77 |
)
|
|
|
78 |
}
|
| 1 |
www |
79 |
|
|
|
80 |
const mapDispatchToProps = {
|
| 5121 |
stevensc |
81 |
addNotification: (notification) => addNotification(notification)
|
| 4889 |
stevensc |
82 |
}
|
| 1 |
www |
83 |
|
| 5121 |
stevensc |
84 |
export default connect(null, mapDispatchToProps)(MyConnections)
|