Rev 6736 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useEffect, useState } from 'react'import { useDispatch, useSelector } from 'react-redux'import { debounce } from '../../utils'import { searchEntities } from '../../services/items'import { addNotification } from '../../redux/notification/notification.actions'import Spinner from '../../components/UI/Spinner'import SearchBar from '../../components/UI/SearchBar'import TitleSection from '../../components/UI/TitleSection'import EmptySection from '../../components/UI/EmptySection'import ProfileItem from '../../components/profile/ProfileItem'import PaginationComponent from '../../components/UI/PaginationComponent'import LoaderContainer from '../../components/UI/LoaderContainer'const MyConnectionsPage = () => {const [myConnections, setMyConnections] = useState([])const [currentPage, setCurrentPage] = useState(1)const [totalPages, setTotalPages] = useState(1)const [loading, setLoading] = useState(false)const [search, setSearch] = useState('')const labels = useSelector(({ intl }) => intl.labels)const dispatch = useDispatch()const getMyConnections = async (search = '', page = 1) => {setLoading(true)try {const { success, data } = await searchEntities('connection/my-connections',search,page)if (!success) {dispatch(addNotification({ style: 'danger', msg: data }))setLoading(false)return}setMyConnections(data.current.items)setCurrentPage(data.current.page)setTotalPages(data.total.pages)} catch (error) {console.log(error)throw new Error(error)} finally {setLoading(false)}}const handleSearch = debounce((value) => setSearch(value), 500)const onChangePageHandler = (currentPage) => {setCurrentPage(currentPage)}useEffect(() => {getMyConnections(search, currentPage)}, [search, currentPage])return (<main className="companies-info container"><TitleSection title={labels.first_level_persons} /><SearchBar onChange={handleSearch} />{loading ? (<LoaderContainer><Spinner /></LoaderContainer>) : (<ul className="companies-list">{myConnections.length ? (myConnections.map(({ id, ...rest }) => (<ProfileItemkey={id}isTopData{...rest}fetchCallback={getMyConnections}/>))) : (<EmptySectionalign="left"message={labels.datatable_szerorecords}/>)}</ul>)}<PaginationComponentisRowpages={totalPages}currentActivePage={currentPage}onChangePage={onChangePageHandler}/></main>)}export default MyConnectionsPage