Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
6753 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { useDispatch, useSelector } from 'react-redux'
3
import { debounce } from '../../utils'
4
import { searchEntities } from '../../services/items'
5
import { addNotification } from '../../redux/notification/notification.actions'
6
 
7
import Spinner from '../../components/UI/Spinner'
8
import SearchBar from '../../components/UI/SearchBar'
9
import ProfileItem from '../../components/profile/ProfileItem'
10
import TitleSection from '../../components/UI/TitleSection'
11
import EmptySection from '../../components/UI/EmptySection'
12
import LoaderContainer from '../../components/UI/LoaderContainer'
13
 
14
const FollowingCompaniesPage = () => {
15
  const [followingCompanies, setFollowingCompanies] = useState([])
16
  const [loading, setLoading] = useState(false)
17
  const [search, setSearch] = useState('')
18
 
19
  const labels = useSelector(({ intl }) => intl.labels)
20
  const dispatch = useDispatch()
21
 
22
  const getFollowingCompanies = async (search = '') => {
23
    setLoading(true)
24
    try {
25
      const { success, data } = await searchEntities(
26
        'company/following-companies',
27
        search
28
      )
29
 
30
      if (!success) {
31
        dispatch(addNotification({ style: 'danger', msg: data }))
32
        setLoading(false)
33
        return
34
      }
35
 
36
      setFollowingCompanies(data)
37
    } catch (error) {
38
      console.log(error)
39
      throw new Error(error)
40
    } finally {
41
      setLoading(false)
42
    }
43
  }
44
 
45
  const handleSearch = debounce((value) => setSearch(value), 500)
46
 
47
  useEffect(() => {
48
    getFollowingCompanies(search)
49
  }, [search])
50
 
51
  return (
52
    <main className="companies-info container">
53
      <TitleSection title={labels.companies_i_follow} />
54
      <SearchBar onChange={handleSearch} />
55
      {loading ? (
56
        <LoaderContainer>
57
          <Spinner />
58
        </LoaderContainer>
59
      ) : (
60
        <ul className="companies-list">
61
          {followingCompanies.length ? (
62
            followingCompanies.map(({ id, privacy, ...rest }) => (
63
              <ProfileItem
64
                key={id}
65
                fetchCallback={getFollowingCompanies}
66
                btnAcceptTitle={labels.view_company}
67
                {...rest}
68
              />
69
            ))
70
          ) : (
71
            <EmptySection
72
              align="left"
73
              message={labels.datatable_szerorecords}
74
            />
75
          )}
76
        </ul>
77
      )}
78
    </main>
79
  )
80
}
81
 
82
export default FollowingCompaniesPage