6753 |
stevensc |
1 |
import React, { useEffect, useState } from 'react'
|
|
|
2 |
import { useDispatch, useSelector } from 'react-redux'
|
|
|
3 |
import { debounce } from '../../utils'
|
|
|
4 |
import { searchEntities } from '../../services/items'
|
|
|
5 |
import { addNotification } from '../../redux/notification/notification.actions'
|
|
|
6 |
|
|
|
7 |
import Spinner from '../../components/UI/Spinner'
|
|
|
8 |
import SearchBar from '../../components/UI/SearchBar'
|
|
|
9 |
import ProfileItem from '../../components/profile/ProfileItem'
|
|
|
10 |
import TitleSection from '../../components/UI/TitleSection'
|
|
|
11 |
import EmptySection from '../../components/UI/EmptySection'
|
|
|
12 |
import LoaderContainer from '../../components/UI/LoaderContainer'
|
|
|
13 |
|
|
|
14 |
const CompanyInvitationsReceivedPage = () => {
|
|
|
15 |
const [invitationsReceived, setInvitationsReceived] = useState([])
|
|
|
16 |
const [loading, setLoading] = useState(false)
|
|
|
17 |
const [search, setSearch] = useState('')
|
|
|
18 |
|
|
|
19 |
const labels = useSelector(({ intl }) => intl.labels)
|
|
|
20 |
const dispatch = useDispatch()
|
|
|
21 |
|
|
|
22 |
const getInvitationsReceived = async (search = '') => {
|
|
|
23 |
setLoading(true)
|
|
|
24 |
try {
|
|
|
25 |
const { success, data } = await searchEntities(
|
|
|
26 |
'company/invitations-received',
|
|
|
27 |
search
|
|
|
28 |
)
|
|
|
29 |
|
|
|
30 |
if (!success) {
|
|
|
31 |
dispatch(addNotification({ style: 'danger', msg: data }))
|
|
|
32 |
setLoading(false)
|
|
|
33 |
return
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
setInvitationsReceived(data)
|
|
|
37 |
} catch (error) {
|
|
|
38 |
console.log(error)
|
|
|
39 |
throw new Error(error)
|
|
|
40 |
} finally {
|
|
|
41 |
setLoading(false)
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
const handleSearch = debounce((value) => setSearch(value), 500)
|
|
|
46 |
|
|
|
47 |
useEffect(() => {
|
|
|
48 |
getInvitationsReceived(search)
|
|
|
49 |
}, [search])
|
|
|
50 |
|
|
|
51 |
return (
|
|
|
52 |
<main className="companies-info container">
|
|
|
53 |
<TitleSection title={labels.invitations_received} />
|
|
|
54 |
<SearchBar onChange={handleSearch} />
|
|
|
55 |
{loading ? (
|
|
|
56 |
<LoaderContainer>
|
|
|
57 |
<Spinner />
|
|
|
58 |
</LoaderContainer>
|
|
|
59 |
) : (
|
|
|
60 |
<ul className="companies-list">
|
|
|
61 |
{invitationsReceived.length ? (
|
|
|
62 |
invitationsReceived.map(({ id, privacy, ...rest }) => (
|
|
|
63 |
<ProfileItem
|
|
|
64 |
key={id}
|
|
|
65 |
fetchCallback={getInvitationsReceived}
|
|
|
66 |
btnAcceptTitle={labels.view_company}
|
|
|
67 |
btnCancelTitle={labels.request_cancel}
|
|
|
68 |
{...rest}
|
|
|
69 |
/>
|
|
|
70 |
))
|
|
|
71 |
) : (
|
|
|
72 |
<EmptySection
|
|
|
73 |
align="left"
|
|
|
74 |
message={labels.datatable_szerorecords}
|
|
|
75 |
/>
|
|
|
76 |
)}
|
|
|
77 |
</ul>
|
|
|
78 |
)}
|
|
|
79 |
</main>
|
|
|
80 |
)
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
export default CompanyInvitationsReceivedPage
|