Rev 5144 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
/* eslint-disable camelcase */
/* eslint-disable react/prop-types */
import React, { useEffect, useState } from 'react'
import { connect } from 'react-redux'
import { debounce } from '../../../utils'
import { searchEntities } from '../../../services/search'
import { addNotification } from '../../../redux/notification/notification.actions'
import Profile from '../../../components/Profile'
import SearchList from '../../../components/SearchList'
import Spinner from '../../../shared/loading-spinner/Spinner'
import EmptySection from '../../../shared/empty-section/EmptySection'
import TitleSection from '../../../components/TitleSection'
const PeopleYouMayKnow = ({ addNotification }) => {
const [entities, setEntities] = useState([])
const [loading, setLoading] = useState(false)
useEffect(() => {
fetchEntities()
}, [])
const fetchEntities = async (searchValue) => {
setLoading(true)
const response = await searchEntities('connection/people-blocked', searchValue)
if (!response.success) {
addNotification({ style: 'danger', msg: response.data })
setLoading(false)
return
}
setEntities(response.data)
setLoading(false)
}
const handleSearch = debounce((value) => fetchEntities(value), 500)
return (
<section className="companies-info container">
<TitleSection title={LABELS.PEOPLE_BLOCKED} />
<SearchList onChange={handleSearch} />
<div className="companies-list">
{loading && <Spinner />}
{(!loading && Boolean(!entities.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
{(!loading && Boolean(entities.length)) &&
entities.map(({ image, link_unblock, link_view, name }, index) =>
<Profile
image={image}
name={name}
key={index}
link_view={link_view}
link_unblock={link_unblock}
fetchCallback={fetchEntities}
/>
)}
</div>
</section>
)
}
const mapDispatchToProps = {
addNotification: (notification) => addNotification(notification)
}
export default connect(null, mapDispatchToProps)(PeopleYouMayKnow)