5164 |
stevensc |
1 |
/* eslint-disable camelcase */
|
|
|
2 |
import React, { useEffect, useState } from 'react'
|
|
|
3 |
import { debounce } from '../../../utils'
|
|
|
4 |
import { useDispatch } from 'react-redux'
|
|
|
5 |
import { addNotification } from '../../../redux/notification/notification.actions'
|
|
|
6 |
import { searchEntities } from '../../../services/search'
|
|
|
7 |
import Spinner from '../../../shared/loading-spinner/Spinner'
|
|
|
8 |
import AddCompanyModal from './add-company-modal/AddCompanyModal'
|
|
|
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 |
|
5164 |
stevensc |
14 |
const MyCompanies = ({ companySizes, industries }) => {
|
|
|
15 |
const [companies, setCompanies] = useState([])
|
|
|
16 |
const [loading, setLoading] = useState(true)
|
|
|
17 |
const [showAddCompanyModal, setShowCompanyModal] = useState(false)
|
|
|
18 |
const dispatch = useDispatch()
|
1 |
www |
19 |
|
5164 |
stevensc |
20 |
useEffect(() => {
|
|
|
21 |
getCompanies()
|
|
|
22 |
}, [])
|
1 |
www |
23 |
|
5164 |
stevensc |
24 |
const getCompanies = async (searchValue = '') => {
|
|
|
25 |
setLoading(true)
|
|
|
26 |
const response = await searchEntities('company/my-companies', searchValue)
|
1 |
www |
27 |
|
5164 |
stevensc |
28 |
if (!response.success) {
|
|
|
29 |
dispatch(addNotification({ style: 'danger', msg: response.data }))
|
|
|
30 |
setLoading(false)
|
|
|
31 |
return
|
|
|
32 |
}
|
1 |
www |
33 |
|
5164 |
stevensc |
34 |
setCompanies(response.data)
|
|
|
35 |
setLoading(false)
|
|
|
36 |
}
|
1 |
www |
37 |
|
5164 |
stevensc |
38 |
const handleShowAddCompanyModal = () => {
|
|
|
39 |
setShowCompanyModal(!showAddCompanyModal)
|
|
|
40 |
}
|
1 |
www |
41 |
|
5164 |
stevensc |
42 |
const handleSearch = debounce((value) => getCompanies(value), 500)
|
1 |
www |
43 |
|
|
|
44 |
return (
|
5164 |
stevensc |
45 |
<section className="companies-info container">
|
|
|
46 |
<TitleSection title={LABELS.MY_COMPANIES} allowAdd onAdd={handleShowAddCompanyModal} />
|
|
|
47 |
<SearchList onChange={handleSearch} />
|
|
|
48 |
<div className="companies-list">
|
|
|
49 |
{loading && <Spinner />}
|
|
|
50 |
{(!loading && Boolean(!companies.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
|
|
|
51 |
{(!loading && Boolean(companies.length)) &&
|
|
|
52 |
companies.map(({ image, link_my_company, link_view, name, status }, id) =>
|
|
|
53 |
<Profile
|
|
|
54 |
link_admin={link_my_company}
|
|
|
55 |
key={id}
|
|
|
56 |
name={name}
|
|
|
57 |
image={image}
|
|
|
58 |
status={status}
|
|
|
59 |
link_view={link_view}
|
|
|
60 |
btnAcceptTitle={LABELS.VIEW_COMPANY}
|
|
|
61 |
/>
|
|
|
62 |
)}
|
|
|
63 |
</div>
|
1 |
www |
64 |
<AddCompanyModal
|
|
|
65 |
show={showAddCompanyModal}
|
|
|
66 |
onHide={handleShowAddCompanyModal}
|
5164 |
stevensc |
67 |
fetchCompanies={getCompanies}
|
1 |
www |
68 |
companySizes={companySizes}
|
|
|
69 |
industries={industries}
|
|
|
70 |
/>
|
5164 |
stevensc |
71 |
</section>
|
|
|
72 |
)
|
|
|
73 |
}
|
1 |
www |
74 |
|
5164 |
stevensc |
75 |
export default MyCompanies
|