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