| 5 |
stevensc |
1 |
import React, { useEffect, useState } from 'react'
|
|
|
2 |
import { useDispatch, useSelector } from 'react-redux'
|
| 2864 |
stevensc |
3 |
import { Search } from '@mui/icons-material'
|
|
|
4 |
|
| 5 |
stevensc |
5 |
import { debounce } from '../../utils'
|
|
|
6 |
import { searchEntities } from '../../services/items'
|
|
|
7 |
import { addNotification } from '../../redux/notification/notification.actions'
|
|
|
8 |
|
|
|
9 |
import Spinner from '../../components/UI/Spinner'
|
| 2864 |
stevensc |
10 |
import Input from '../../components/UI/inputs/Input'
|
| 5 |
stevensc |
11 |
import TitleSection from '../../components/UI/TitleSection'
|
|
|
12 |
import EmptySection from '../../components/UI/EmptySection'
|
|
|
13 |
import ProfileItem from '../../components/profile/ProfileItem'
|
|
|
14 |
import PaginationComponent from '../../components/UI/PaginationComponent'
|
|
|
15 |
|
|
|
16 |
const PeopleYouMayKnowPage = () => {
|
|
|
17 |
const [peopleYouMayKnow, setPeopleYouMayKnow] = useState([])
|
|
|
18 |
const [currentPage, setCurrentPage] = useState(1)
|
|
|
19 |
const [totalPages, setTotalPages] = useState(1)
|
|
|
20 |
const [loading, setLoading] = useState(false)
|
|
|
21 |
const [search, setSearch] = useState('')
|
|
|
22 |
|
|
|
23 |
const labels = useSelector(({ intl }) => intl.labels)
|
|
|
24 |
const dispatch = useDispatch()
|
|
|
25 |
|
|
|
26 |
const getPeopleYouMayKnow = async (search = '', page = 1) => {
|
|
|
27 |
setLoading(true)
|
|
|
28 |
try {
|
|
|
29 |
const { success, data } = await searchEntities(
|
|
|
30 |
'connection/people-you-may-know',
|
|
|
31 |
search,
|
|
|
32 |
page
|
|
|
33 |
)
|
|
|
34 |
|
|
|
35 |
if (!success) {
|
|
|
36 |
dispatch(addNotification({ style: 'danger', msg: data }))
|
|
|
37 |
setLoading(false)
|
|
|
38 |
return
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
setPeopleYouMayKnow(data.current.items)
|
|
|
42 |
setCurrentPage(data.current.page)
|
|
|
43 |
setTotalPages(data.total.pages)
|
|
|
44 |
} catch (error) {
|
| 2194 |
stevensc |
45 |
dispatch(addNotification({ style: 'danger', msg: error.message }))
|
| 5 |
stevensc |
46 |
} finally {
|
|
|
47 |
setLoading(false)
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
const handleSearch = debounce((value) => setSearch(value), 500)
|
|
|
52 |
|
|
|
53 |
const onChangePageHandler = (currentPage) => {
|
|
|
54 |
setCurrentPage(currentPage)
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
useEffect(() => {
|
|
|
58 |
getPeopleYouMayKnow(search, currentPage)
|
|
|
59 |
}, [search, currentPage])
|
|
|
60 |
|
|
|
61 |
return (
|
| 932 |
stevensc |
62 |
<main className='companies-info container'>
|
| 5 |
stevensc |
63 |
<TitleSection title={labels.people_you_may_know} />
|
| 2864 |
stevensc |
64 |
<Input icon={<Search />} onChange={handleSearch} />
|
| 5 |
stevensc |
65 |
{loading ? (
|
| 2864 |
stevensc |
66 |
<Spinner />
|
| 5 |
stevensc |
67 |
) : (
|
| 932 |
stevensc |
68 |
<ul className='companies-list'>
|
| 5 |
stevensc |
69 |
{peopleYouMayKnow.length ? (
|
|
|
70 |
peopleYouMayKnow.map(({ id, ...rest }) => (
|
|
|
71 |
<ProfileItem
|
|
|
72 |
key={id}
|
|
|
73 |
{...rest}
|
|
|
74 |
fetchCallback={() => getPeopleYouMayKnow(search, currentPage)}
|
|
|
75 |
/>
|
|
|
76 |
))
|
|
|
77 |
) : (
|
|
|
78 |
<EmptySection
|
| 932 |
stevensc |
79 |
align='left'
|
| 5 |
stevensc |
80 |
message={labels.datatable_szerorecords}
|
|
|
81 |
/>
|
|
|
82 |
)}
|
|
|
83 |
</ul>
|
|
|
84 |
)}
|
|
|
85 |
<PaginationComponent
|
|
|
86 |
isRow
|
|
|
87 |
pages={totalPages}
|
|
|
88 |
currentActivePage={currentPage}
|
|
|
89 |
onChangePage={onChangePageHandler}
|
|
|
90 |
/>
|
|
|
91 |
</main>
|
|
|
92 |
)
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
export default PeopleYouMayKnowPage
|