Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
5121 stevensc 1
/* eslint-disable camelcase */
2
import React, { useEffect, useState } from 'react'
3
import { axios } from '../../../utils'
4
import { connect } from 'react-redux'
5
import { addNotification } from '../../../redux/notification/notification.actions'
6
import Profile from '../../../components/Profile'
7
import SearchList from '../../../components/SearchList'
8
import Spinner from '../../../shared/loading-spinner/Spinner'
9
import PaginationComponent from '../../../shared/pagination/PaginationComponent'
10
import EmptySection from '../../../shared/empty-section/EmptySection'
11
import TitleSection from '../../../components/TitleSection'
1 www 12
 
4889 stevensc 13
const MyConnections = () => {
14
  const [myConnections, setMyConnections] = useState([])
15
  const [currentPage, setCurrentPage] = useState(1)
16
  const [search, setSearch] = useState('')
17
  const [pages, setPages] = useState(1)
18
  const [loading, setLoading] = useState(true)
1 www 19
 
4890 stevensc 20
  const fetchMyConnections = async ({ search = '', page = 1 }) => {
4891 stevensc 21
    setLoading(true)
1 www 22
    await axios
4970 stevensc 23
      .get(`/connection/my-connections?search=${search}&page=${page}`)
4889 stevensc 24
      .then(({ data: response }) => {
25
        if (response.success) {
26
          setMyConnections(response.data.current.items)
27
          setCurrentPage(response.data.current.page)
28
          setPages(response.data.total.pages)
1 www 29
        }
4891 stevensc 30
      })
31
    setLoading(false)
32
  }
1 www 33
 
4889 stevensc 34
  const handleChangePage = (newPage) => setCurrentPage(newPage)
35
 
4891 stevensc 36
  useEffect(() => {
37
    fetchMyConnections({
5121 stevensc 38
      search,
4891 stevensc 39
      page: currentPage
40
    })
41
  }, [currentPage, search])
42
 
1 www 43
  return (
5124 stevensc 44
    <section className="companies-info container">
45
      <TitleSection title={LABELS.FIRST_LEVEL_PERSONS} />
46
      <SearchList onChange={(value) => setSearch(value)} />
5126 stevensc 47
      <div className="companies-list">
5124 stevensc 48
        {myConnections.length
5126 stevensc 49
          ? myConnections.map(({ image, name, link_view, link_inmail, link_cancel, link_block }, id) =>
5124 stevensc 50
            <Profile
51
              isTopData
52
              key={id}
53
              image={image}
54
              name={name}
55
              link_inmail={link_inmail}
56
              link_view={link_view}
57
              link_cancel={link_cancel}
58
              link_block={link_block}
59
              fetchCallback={fetchMyConnections}
60
            />
61
          )
62
          : <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />
63
        }
64
        {loading && <Spinner />}
1 www 65
      </div>
5124 stevensc 66
      <PaginationComponent
67
        onChangePage={handleChangePage}
68
        pages={pages}
69
        currentActivePage={currentPage}
70
        isRow={true}
71
      />
1 www 72
    </section>
4889 stevensc 73
  )
74
}
1 www 75
 
76
const mapDispatchToProps = {
5121 stevensc 77
  addNotification: (notification) => addNotification(notification)
4889 stevensc 78
}
1 www 79
 
5121 stevensc 80
export default connect(null, mapDispatchToProps)(MyConnections)