Rev 2322 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
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 TitleSection from '../../../components/TitleSection'
import EmptySection from '../../../shared/empty-section/EmptySection'
const RequestsSent = () => {
const [sendRequests, setSendRequests] = useState([])
const [loading, setLoading] = useState(true)
useEffect(() => {
getSendRequests()
}, [])
const getSendRequests = async (searchValue = '') => {
setLoading(true)
const response = await searchEntities('group/requests-sent', searchValue)
if (!response.success) {
addNotification({ style: 'danger', msg: response.data })
setLoading(false)
return
}
setSendRequests(response.data)
setLoading(false)
}
const handleSearch = debounce((value) => getSendRequests(value), 500)
return (
<section className="companies-info container">
<TitleSection title={LABELS.REQUESTS_SENT} />
<SearchList onChange={handleSearch} />
<div className="companies-list">
{loading && <Spinner />}
{(!loading && Boolean(!sendRequests.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
{(!loading && Boolean(sendRequests.length)) &&
sendRequests.map((request, index) =>
<Profile
{...request}
key={index}
fetchCallback={getSendRequests}
btnAcceptTitle={LABELS.GROUP_VIEW}
/>
)}
</div>
</section>
)
}
const mapDispatchToProps = {
addNotification: (notification) => addNotification(notification)
}
export default connect(null, mapDispatchToProps)(RequestsSent)