Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2507 | 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 SearchList from '../../../components/SearchList'
import Profile from '../../../components/Profile'
import TitleSection from '../../../components/TitleSection'
import EmptySection from '../../../shared/empty-section/EmptySection'

const FollowingCompanies = ({ addNotification }) => {
  const [companies, setCompanies] = useState([])
  const [loading, setLoading] = useState(true)

  useEffect(() => {
    getCompanies()
  }, [])

  const getCompanies = async (searchValue = '') => {
    setLoading(true)
    const response = await searchEntities('company/following-companies', searchValue)

    if (!response.success) {
      addNotification({ style: 'danger', msg: response.data })
      setLoading(false)
      return
    }

    setCompanies(response.data)
    setLoading(false)
  }

  const handleSearch = debounce((value) => getCompanies(value), 500)

  return (
    <section className="companies-info container">
      <TitleSection title={LABELS.COMPANIES_I_FOLLOW} />
      <SearchList onChange={handleSearch} />
      <div className="companies-list">
        {loading && <Spinner />}
        {(!loading && Boolean(!companies.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
        {(!loading && Boolean(companies.length)) &&
          companies.map(({ image, name, link_view, link_unfollow }, index) =>
            <Profile
              key={index}
              name={name}
              image={image}
              link_view={link_view}
              fetchCallback={getCompanies}
              link_unfollow={link_unfollow}
              btnAcceptTitle={LABELS.VIEW_COMPANY}
            />
          )}
      </div>
    </section>
  )
}

const mapDispatchToProps = {
  addNotification: (notification) => addNotification(notification)
}

export default connect(null, mapDispatchToProps)(FollowingCompanies)