Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6727 | 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 PeopleBlockedPage = () => {
6734 stevensc 14
  const [peopleBlocked, setPeopleBlocked] = 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 getPeopleBlocked = async (search = '') => {
22
    setLoading(true)
23
    try {
24
      const { success, data } = await searchEntities(
25
        'connection/people-blocked',
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
      setPeopleBlocked(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
    getPeopleBlocked(search)
48
  }, [search])
49
 
6725 stevensc 50
  return (
51
    <main className="companies-info container">
6727 stevensc 52
      <TitleSection title={labels.people_blocked} />
6734 stevensc 53
      <SearchBar onChange={handleSearch} />
54
      {loading ? (
55
        <Spinner />
56
      ) : (
57
        <ul className="companies-list">
58
          {peopleBlocked.length ? (
59
            peopleBlocked.map(({ id, ...rest }) => (
60
              <ProfileItem
61
                key={id}
62
                {...rest}
63
                fetchCallback={getPeopleBlocked}
64
              />
65
            ))
66
          ) : (
67
            <EmptySection
68
              align="left"
69
              message={labels.datatable_szerorecords}
70
            />
71
          )}
72
        </ul>
73
      )}
6725 stevensc 74
    </main>
75
  )
76
}
77
 
78
export default PeopleBlockedPage