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