5175 |
stevensc |
1 |
/* eslint-disable react/prop-types */
|
|
|
2 |
/* eslint-disable camelcase */
|
|
|
3 |
import React, { useEffect, useState } from 'react'
|
|
|
4 |
import { connect } from 'react-redux'
|
|
|
5 |
import { debounce } from '../../../../utils'
|
|
|
6 |
import { searchEntities } from '../../../../services/search'
|
|
|
7 |
import { addNotification } from '../../../../redux/notification/notification.actions'
|
|
|
8 |
import Spinner from '../../../../shared/loading-spinner/Spinner'
|
|
|
9 |
import Profile from '../../../../components/Profile'
|
|
|
10 |
import SearchList from '../../../../components/SearchList'
|
|
|
11 |
import TitleSection from '../../../../components/TitleSection'
|
|
|
12 |
import EmptySection from '../../../../shared/empty-section/EmptySection'
|
|
|
13 |
import AddGroupModal from './add-group-modal/AddGroupModal'
|
1 |
www |
14 |
|
5175 |
stevensc |
15 |
const MyGroups = ({ groupTypes, industries, addNotification }) => {
|
|
|
16 |
const [groups, setGroups] = useState([])
|
|
|
17 |
const [loading, setLoading] = useState(true)
|
|
|
18 |
const [showAddGroupModal, setShowAddGroupModal] = useState(false)
|
1 |
www |
19 |
|
5175 |
stevensc |
20 |
useEffect(() => {
|
|
|
21 |
getGroups()
|
|
|
22 |
}, [])
|
1 |
www |
23 |
|
5175 |
stevensc |
24 |
const getGroups = async (searchValue = '') => {
|
|
|
25 |
setLoading(true)
|
|
|
26 |
const response = await searchEntities('group/my-groups', searchValue)
|
1 |
www |
27 |
|
5175 |
stevensc |
28 |
if (!response.success) {
|
|
|
29 |
addNotification({ style: 'danger', msg: response.data })
|
|
|
30 |
setLoading(false)
|
|
|
31 |
return
|
|
|
32 |
}
|
1 |
www |
33 |
|
5175 |
stevensc |
34 |
setGroups(response.data)
|
|
|
35 |
setLoading(false)
|
|
|
36 |
}
|
1 |
www |
37 |
|
|
|
38 |
const handleShowAddGroupModal = () => {
|
5175 |
stevensc |
39 |
setShowAddGroupModal(!showAddGroupModal)
|
|
|
40 |
}
|
1 |
www |
41 |
|
5175 |
stevensc |
42 |
const handleSearch = debounce((value) => getGroups(value), 500)
|
|
|
43 |
|
1 |
www |
44 |
return (
|
5175 |
stevensc |
45 |
<section className="companies-info container">
|
|
|
46 |
<TitleSection title={LABELS.MY_GROUPS} allowAdd onAdd={handleShowAddGroupModal} />
|
|
|
47 |
<SearchList onChange={handleSearch} />
|
|
|
48 |
<div className="companies-list">
|
|
|
49 |
{loading && <Spinner />}
|
|
|
50 |
{(!loading && Boolean(!groups.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
|
|
|
51 |
{(!loading && Boolean(groups.length)) &&
|
|
|
52 |
groups.map(
|
|
|
53 |
({ image, link_delete, link_edit, link_view, name, privacy }, id) =>
|
|
|
54 |
<Profile
|
|
|
55 |
image={image}
|
|
|
56 |
name={name}
|
|
|
57 |
status={privacy}
|
|
|
58 |
link_view={link_view}
|
|
|
59 |
link_edit={link_edit}
|
|
|
60 |
link_delete={link_delete}
|
|
|
61 |
key={id}
|
|
|
62 |
fetchCallback={getGroups}
|
|
|
63 |
btnAcceptTitle={LABELS.GROUP_VIEW}
|
|
|
64 |
btnEditTitle={`${LABELS.EDIT} ${LABELS.GROUP.toLowerCase()}`}
|
|
|
65 |
btnCancelTitle={`${LABELS.DELETE} ${LABELS.GROUP.toLowerCase()}`}
|
|
|
66 |
/>
|
|
|
67 |
)}
|
|
|
68 |
</div>
|
1 |
www |
69 |
<AddGroupModal
|
|
|
70 |
show={showAddGroupModal}
|
|
|
71 |
onHide={handleShowAddGroupModal}
|
5175 |
stevensc |
72 |
getGroups={getGroups}
|
1 |
www |
73 |
groupTypes={groupTypes}
|
|
|
74 |
industries={industries}
|
|
|
75 |
/>
|
5175 |
stevensc |
76 |
</section>
|
|
|
77 |
)
|
|
|
78 |
}
|
1 |
www |
79 |
|
|
|
80 |
const mapDispatchToProps = {
|
5175 |
stevensc |
81 |
addNotification: (notification) => addNotification(notification)
|
|
|
82 |
}
|
1 |
www |
83 |
|
5175 |
stevensc |
84 |
export default connect(null, mapDispatchToProps)(MyGroups)
|