Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2864 | Rev 2934 | 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'
2864 stevensc 3
import { Search } from '@mui/icons-material'
4
 
5 stevensc 5
import { debounce } from '../../utils'
6
import { addNotification } from '../../redux/notification/notification.actions'
7
import { searchEntities } from '../../services/items'
8
 
9
import Spinner from '../../components/UI/Spinner'
2864 stevensc 10
import Input from '../../components/UI/inputs/Input'
5 stevensc 11
import ProfileItem from '../../components/profile/ProfileItem'
12
import TitleSection from '../../components/UI/TitleSection'
13
import EmptySection from '../../components/UI/EmptySection'
14
import PaginationComponent from '../../components/UI/PaginationComponent'
15
 
16
const PeopleViewedMyProfilePage = () => {
17
  const [peopleViewedMyProfile, setPeopleViewedMyProfile] = useState([])
18
  const [loading, setLoading] = useState(false)
19
  const [search, setSearch] = useState('')
20
  const [currentpage, setCurrentPage] = useState(1)
21
  const [totalPages, setTotalPages] = useState(1)
22
 
23
  const labels = useSelector(({ intl }) => intl.labels)
24
  const dispatch = useDispatch()
25
 
26
  const getPeopleVieweMyProfile = async (search = '') => {
27
    setLoading(true)
28
    try {
29
      const { success, data } = await searchEntities(
30
        'profile/people-viewed-profile',
31
        search
32
      )
33
 
34
      if (!success) {
35
        dispatch(addNotification({ style: 'danger', msg: data }))
36
        setLoading(false)
37
        return
38
      }
39
 
40
      setPeopleViewedMyProfile(data.current.items)
41
      setCurrentPage(data.current.page)
42
      setTotalPages(data.total.pages)
43
    } catch (error) {
2194 stevensc 44
      dispatch(addNotification({ style: 'danger', msg: error.message }))
5 stevensc 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 (
2194 stevensc 61
    <main className='companies-info container'>
5 stevensc 62
      <TitleSection title={labels.who_has_seen_my_profile} />
2875 stevensc 63
      <Input icon={<Search />} onChange={handleSearch} variant='search' />
5 stevensc 64
      {loading ? (
2864 stevensc 65
        <Spinner />
5 stevensc 66
      ) : (
2194 stevensc 67
        <ul className='companies-list'>
5 stevensc 68
          {peopleViewedMyProfile.length ? (
69
            peopleViewedMyProfile.map(
70
              ({ id, link_edit, link_delete, ...rest }) => (
71
                <ProfileItem
72
                  key={id}
73
                  {...rest}
74
                  fetchCallback={getPeopleVieweMyProfile}
75
                />
76
              )
77
            )
78
          ) : (
79
            <EmptySection
2194 stevensc 80
              align='left'
5 stevensc 81
              message={labels.datatable_szerorecords}
82
            />
83
          )}
84
        </ul>
85
      )}
86
      <PaginationComponent
87
        isRow
88
        pages={totalPages}
89
        currentActivePage={currentpage}
90
        onChangePage={handlePagination}
91
      />
92
    </main>
93
  )
94
}
95
 
96
export default PeopleViewedMyProfilePage