Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6725 | Rev 6736 | 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'
6725 stevensc 12
 
13
const PeopleYouMayKnowPage = () => {
6734 stevensc 14
  const [peopleYouMayKnow, setPeopleYouMayKnow] = useState([])
15
  const [loading, setLoading] = useState(false)
16
  const [search, setSearch] = useState('')
17
 
6725 stevensc 18
  const labels = useSelector(({ intl }) => intl.labels)
6734 stevensc 19
  const dispatch = useDispatch()
6725 stevensc 20
 
6734 stevensc 21
  const getPeopleYouMayKnow = async (search = '') => {
22
    setLoading(true)
23
    try {
24
      const { success, data } = await searchEntities(
25
        'connection/people-you-may-know',
26
        search
27
      )
6725 stevensc 28
 
6734 stevensc 29
      if (!success) {
30
        dispatch(addNotification({ style: 'danger', msg: data }))
31
        setLoading(false)
32
        return
33
      }
34
 
35
      setPeopleYouMayKnow(data)
36
    } catch (error) {
37
      console.log(error)
38
      throw new Error(error)
39
    } finally {
40
      setLoading(false)
41
    }
42
  }
43
 
44
  const handleSearch = debounce((value) => setSearch(value), 500)
45
 
46
  useEffect(() => {
47
    getPeopleYouMayKnow(search)
48
  }, [search])
49
 
6725 stevensc 50
  return (
51
    <main className="companies-info container">
52
      <TitleSection title={labels.people_you_may_know} />
6734 stevensc 53
      <SearchBar onChange={handleSearch} />
54
      {loading ? (
55
        <Spinner />
56
      ) : (
57
        <ul className="companies-list">
58
          {peopleYouMayKnow.length ? (
59
            peopleYouMayKnow.map(({ id, ...rest }) => (
60
              <ProfileItem
61
                key={id}
62
                isTopData
63
                {...rest}
64
                fetchCallback={getPeopleYouMayKnow}
65
              />
66
            ))
67
          ) : (
68
            <EmptySection
69
              align="left"
70
              message={labels.datatable_szerorecords}
71
            />
72
          )}
73
        </ul>
74
      )}
6725 stevensc 75
    </main>
76
  )
77
}
78
 
79
export default PeopleYouMayKnowPage