Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 583 | Rev 2864 | 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) {
2194 stevensc 43
      dispatch(addNotification({ style: 'danger', msg: error.message }))
5 stevensc 44
    } finally {
45
      setLoading(false)
46
    }
47
  }
48
 
49
  const handleSearch = debounce((value) => setSearch(value), 500)
50
 
51
  const handlePagination = (currentPage) => {
52
    setCurrentPage(currentPage)
53
  }
54
 
55
  useEffect(() => {
56
    getPeopleVieweMyProfile(search)
57
  }, [search])
58
 
59
  return (
2194 stevensc 60
    <main className='companies-info container'>
5 stevensc 61
      <TitleSection title={labels.who_has_seen_my_profile} />
62
      <SearchBar onChange={handleSearch} />
63
      {loading ? (
64
        <LoaderContainer>
65
          <Spinner />
66
        </LoaderContainer>
67
      ) : (
2194 stevensc 68
        <ul className='companies-list'>
5 stevensc 69
          {peopleViewedMyProfile.length ? (
70
            peopleViewedMyProfile.map(
71
              ({ id, link_edit, link_delete, ...rest }) => (
72
                <ProfileItem
73
                  key={id}
74
                  {...rest}
75
                  fetchCallback={getPeopleVieweMyProfile}
76
                />
77
              )
78
            )
79
          ) : (
80
            <EmptySection
2194 stevensc 81
              align='left'
5 stevensc 82
              message={labels.datatable_szerorecords}
83
            />
84
          )}
85
        </ul>
86
      )}
87
      <PaginationComponent
88
        isRow
89
        pages={totalPages}
90
        currentActivePage={currentpage}
91
        onChangePage={handlePagination}
92
      />
93
    </main>
94
  )
95
}
96
 
97
export default PeopleViewedMyProfilePage