Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6727 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 6727 Rev 6734
Línea 1... Línea 1...
1
import React from 'react'
1
import React, { useEffect, useState } from 'react'
2
import { useSelector } from 'react-redux'
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'
Línea -... Línea 6...
-
 
6
 
3
 
7
import Spinner from '../../components/UI/Spinner'
4
import withSearch from '../../HOC/withSearch'
8
import SearchBar from '../../components/UI/SearchBar'
-
 
9
import TitleSection from '../../components/UI/TitleSection'
5
import TitleSection from '../../components/UI/TitleSection'
10
import EmptySection from '../../components/UI/EmptySection'
Línea 6... Línea 11...
6
import ProfileItemList from '../../components/profile-item/ProfileItemList'
11
import ProfileItem from '../../components/profile/ProfileItem'
-
 
12
 
-
 
13
const PeopleBlockedPage = () => {
-
 
14
  const [peopleBlocked, setPeopleBlocked] = useState([])
-
 
15
  const [loading, setLoading] = useState(false)
7
 
16
  const [search, setSearch] = useState('')
-
 
17
 
Línea 8... Línea 18...
8
const PeopleBlockedPage = () => {
18
  const labels = useSelector(({ intl }) => intl.labels)
9
  const labels = useSelector(({ intl }) => intl.labels)
19
  const dispatch = useDispatch()
-
 
20
 
-
 
21
  const getPeopleBlocked = async (search = '') => {
10
 
22
    setLoading(true)
-
 
23
    try {
-
 
24
      const { success, data } = await searchEntities(
-
 
25
        'connection/people-blocked',
-
 
26
        search
-
 
27
      )
-
 
28
 
-
 
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)
11
  const WithSearchConnections = withSearch(
39
    } finally {
-
 
40
      setLoading(false)
-
 
41
    }
-
 
42
  }
-
 
43
 
-
 
44
  const handleSearch = debounce((value) => setSearch(value), 500)
-
 
45
 
Línea 12... Línea 46...
12
    ProfileItemList,
46
  useEffect(() => {
13
    'connection/people-blocked'
47
    getPeopleBlocked(search)
14
  )
48
  }, [search])
-
 
49
 
-
 
50
  return (
-
 
51
    <main className="companies-info container">
-
 
52
      <TitleSection title={labels.people_blocked} />
-
 
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}
15
 
63
                fetchCallback={getPeopleBlocked}
-
 
64
              />
-
 
65
            ))
-
 
66
          ) : (
-
 
67
            <EmptySection
-
 
68
              align="left"
-
 
69
              message={labels.datatable_szerorecords}
16
  return (
70
            />
17
    <main className="companies-info container">
71
          )}
18
      <TitleSection title={labels.people_blocked} />
72
        </ul>
Línea 19... Línea 73...
19
      <WithSearchConnections />
73
      )}