Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6734 | Rev 6885 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
6734 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'
6725 stevensc 6
 
6734 stevensc 7
import Spinner from '../../components/UI/Spinner'
8
import SearchBar from '../../components/UI/SearchBar'
6725 stevensc 9
import TitleSection from '../../components/UI/TitleSection'
6734 stevensc 10
import EmptySection from '../../components/UI/EmptySection'
11
import ProfileItem from '../../components/profile/ProfileItem'
6736 stevensc 12
import LoaderContainer from '../../components/UI/LoaderContainer'
6725 stevensc 13
 
14
const PeopleYouMayKnowPage = () => {
6734 stevensc 15
  const [peopleYouMayKnow, setPeopleYouMayKnow] = useState([])
16
  const [loading, setLoading] = useState(false)
17
  const [search, setSearch] = useState('')
18
 
6725 stevensc 19
  const labels = useSelector(({ intl }) => intl.labels)
6734 stevensc 20
  const dispatch = useDispatch()
6725 stevensc 21
 
6734 stevensc 22
  const getPeopleYouMayKnow = async (search = '') => {
23
    setLoading(true)
24
    try {
25
      const { success, data } = await searchEntities(
26
        'connection/people-you-may-know',
27
        search
28
      )
6725 stevensc 29
 
6734 stevensc 30
      if (!success) {
31
        dispatch(addNotification({ style: 'danger', msg: data }))
32
        setLoading(false)
33
        return
34
      }
35
 
36
      setPeopleYouMayKnow(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
    getPeopleYouMayKnow(search)
49
  }, [search])
50
 
6725 stevensc 51
  return (
52
    <main className="companies-info container">
53
      <TitleSection title={labels.people_you_may_know} />
6734 stevensc 54
      <SearchBar onChange={handleSearch} />
55
      {loading ? (
6736 stevensc 56
        <LoaderContainer>
57
          <Spinner />
58
        </LoaderContainer>
6734 stevensc 59
      ) : (
60
        <ul className="companies-list">
61
          {peopleYouMayKnow.length ? (
62
            peopleYouMayKnow.map(({ id, ...rest }) => (
63
              <ProfileItem
64
                key={id}
65
                isTopData
66
                {...rest}
67
                fetchCallback={getPeopleYouMayKnow}
68
              />
69
            ))
70
          ) : (
71
            <EmptySection
72
              align="left"
73
              message={labels.datatable_szerorecords}
74
            />
75
          )}
76
        </ul>
77
      )}
6725 stevensc 78
    </main>
79
  )
80
}
81
 
82
export default PeopleYouMayKnowPage