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