AutorÃa | Ultima modificación | Ver Log |
/* eslint-disable react/prop-types */
/* eslint-disable camelcase */
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 Spinner from '../../../shared/loading-spinner/Spinner'
import Profile from '../../../components/Profile'
import SearchList from '../../../components/SearchList'
import EmptySection from '../../../shared/empty-section/EmptySection'
import PaginationComponent from '../../../shared/pagination/PaginationComponent'
import TitleSection from '../../../components/TitleSection'
const PeopleViewedProfile = ({ addNotification }) => {
const [entities, setEntities] = useState([])
const [loading, setLoading] = useState(false)
const [search, setSearch] = useState('')
const [page, setPage] = useState(1)
const [pages, setPages] = useState(1)
useEffect(() => {
fetchEntities(search, page)
}, [search, page])
const fetchEntities = async (searchValue = '', page = 1) => {
setLoading(true)
const response = await searchEntities('profile/people-viewed-profile', searchValue, page)
if (!response.success) {
addNotification({ style: 'danger', msg: response.data })
setLoading(false)
return
}
setEntities(response.data.current.items)
setPages(response.data.total.pages)
setPage(response.data.current.page)
setLoading(false)
}
const onChangePageHandler = (currentPage) => {
setPage(currentPage)
window.scrollTo(0, 0)
}
const handleSearch = debounce((value) => setSearch(value), 500)
return (
<section className="companies-info container">
<TitleSection title={LABELS.WHO_HAS_SEEN_MY_PROFILE} />
<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(({ name, image, link_inmail, link_view }, id) =>
<Profile
key={id}
image={image}
name={name}
link_inmail={link_inmail}
link_view={link_view}
fetchCallback={fetchEntities}
/>
)}
</div>
<PaginationComponent
onChangePage={onChangePageHandler}
pages={pages}
currentActivePage={page}
isRow={true}
/>
</section>
)
}
const mapDispatchToProps = {
addNotification: (notification) => addNotification(notification)
}
export default connect(null, mapDispatchToProps)(PeopleViewedProfile)