Rev 2323 | 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 Spinner from '../../../shared/loading-spinner/Spinner'
import Profile from '../../../components/Profile'
import SearchList from '../../../components/SearchList'
import EmptySection from '../../../shared/empty-section/EmptySection'
import TitleSection from '../../../components/TitleSection'
const JoinedGroups = ({ addNotification }) => {
const [joinedGroups, setJoinedGroups] = useState([])
const [loading, setLoading] = useState(true)
useEffect(() => {
getJoinedGroups()
}, [])
const getJoinedGroups = async (searchValue = '') => {
setLoading(true)
const response = await searchEntities('group/joined-groups', searchValue)
if (!response.success) {
addNotification({ style: 'danger', msg: response.data })
setLoading(false)
return
}
setJoinedGroups(response.data)
setLoading(false)
}
const handleSearch = debounce((value) => getJoinedGroups(value), 500)
return (
<section className="companies-info container">
<TitleSection title={LABELS.JOINED_GROUPS} />
<SearchList onChange={handleSearch} />
<div className="companies-list">
{loading && <Spinner />}
{(!loading && Boolean(!joinedGroups.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
{(!loading && Boolean(joinedGroups.length)) &&
joinedGroups.map(
({ image, name, privacy, link_view, link_leave }, index) =>
<Profile
image={image}
name={name}
status={privacy}
link_view={link_view}
link_leave={link_leave}
key={index}
fetchCallback={getJoinedGroups}
btnAcceptTitle={LABELS.GROUP_VIEW}
/>
)}
</div>
</section>
)
}
const mapDispatchToProps = {
addNotification: (notification) => addNotification(notification)
}
export default connect(null, mapDispatchToProps)(JoinedGroups)