Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
5 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { useDispatch, useSelector } from 'react-redux'
3
import { debounce } from '../../utils'
4
import { addNotification } from '../../redux/notification/notification.actions'
5
import { searchEntities } from '../../services/items'
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 PaginationComponent from '../../components/UI/PaginationComponent'
13
import LoaderContainer from '../../components/UI/LoaderContainer'
14
 
15
const PeopleViewedMyProfilePage = () => {
16
  const [peopleViewedMyProfile, setPeopleViewedMyProfile] = useState([])
17
  const [loading, setLoading] = useState(false)
18
  const [search, setSearch] = useState('')
19
  const [currentpage, setCurrentPage] = useState(1)
20
  const [totalPages, setTotalPages] = useState(1)
21
 
22
  const labels = useSelector(({ intl }) => intl.labels)
23
  const dispatch = useDispatch()
24
 
25
  const getPeopleVieweMyProfile = async (search = '') => {
26
    setLoading(true)
27
    try {
28
      const { success, data } = await searchEntities(
29
        'profile/people-viewed-profile',
30
        search
31
      )
32
 
33
      if (!success) {
34
        dispatch(addNotification({ style: 'danger', msg: data }))
35
        setLoading(false)
36
        return
37
      }
38
 
39
      setPeopleViewedMyProfile(data.current.items)
40
      setCurrentPage(data.current.page)
41
      setTotalPages(data.total.pages)
42
    } catch (error) {
43
      console.log(error)
44
      throw new Error(error)
45
    } finally {
46
      setLoading(false)
47
    }
48
  }
49
 
50
  const handleSearch = debounce((value) => setSearch(value), 500)
51
 
52
  const handlePagination = (currentPage) => {
53
    setCurrentPage(currentPage)
54
  }
55
 
56
  useEffect(() => {
57
    getPeopleVieweMyProfile(search)
58
  }, [search])
59
 
60
  return (
61
    <main className="companies-info container">
62
      <TitleSection title={labels.who_has_seen_my_profile} />
63
      <SearchBar onChange={handleSearch} />
64
      {loading ? (
65
        <LoaderContainer>
66
          <Spinner />
67
        </LoaderContainer>
68
      ) : (
583 andreina 69
          <ul className="companies-list">
5 stevensc 70
          {peopleViewedMyProfile.length ? (
71
            peopleViewedMyProfile.map(
72
              ({ id, link_edit, link_delete, ...rest }) => (
73
                <ProfileItem
74
                  key={id}
75
                  {...rest}
76
                  fetchCallback={getPeopleVieweMyProfile}
77
                />
78
              )
79
            )
80
          ) : (
81
            <EmptySection
82
              align="left"
83
              message={labels.datatable_szerorecords}
84
            />
85
          )}
86
        </ul>
87
      )}
88
      <PaginationComponent
89
        isRow
90
        pages={totalPages}
91
        currentActivePage={currentpage}
92
        onChangePage={handlePagination}
93
      />
94
    </main>
95
  )
96
}
97
 
98
export default PeopleViewedMyProfilePage