Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6734 | | 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 { addNotification } from '../../redux/notification/notification.actions'
5
import { searchEntities } from '../../services/items'
6727 stevensc 6
 
6734 stevensc 7
import Spinner from '../../components/UI/Spinner'
8
import SearchBar from '../../components/UI/SearchBar'
9
import ProfileItem from '../../components/profile/ProfileItem'
6727 stevensc 10
import TitleSection from '../../components/UI/TitleSection'
6734 stevensc 11
import EmptySection from '../../components/UI/EmptySection'
12
import PaginationComponent from '../../components/UI/PaginationComponent'
6736 stevensc 13
import LoaderContainer from '../../components/UI/LoaderContainer'
6727 stevensc 14
 
15
const PeopleViewedMyProfilePage = () => {
6734 stevensc 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
 
6727 stevensc 22
  const labels = useSelector(({ intl }) => intl.labels)
6734 stevensc 23
  const dispatch = useDispatch()
6727 stevensc 24
 
6734 stevensc 25
  const getPeopleVieweMyProfile = async (search = '') => {
26
    setLoading(true)
27
    try {
28
      const { success, data } = await searchEntities(
29
        'profile/people-viewed-profile',
30
        search
31
      )
6727 stevensc 32
 
6734 stevensc 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
 
6727 stevensc 60
  return (
61
    <main className="companies-info container">
62
      <TitleSection title={labels.who_has_seen_my_profile} />
6734 stevensc 63
      <SearchBar onChange={handleSearch} />
64
      {loading ? (
6736 stevensc 65
        <LoaderContainer>
66
          <Spinner />
67
        </LoaderContainer>
6734 stevensc 68
      ) : (
69
        <ul className="companies-list">
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
      />
6727 stevensc 94
    </main>
95
  )
96
}
97
 
98
export default PeopleViewedMyProfilePage