Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4970 | Rev 5124 | 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 (
44
    <section className="companies-info">
45
      <div className="container">
5121 stevensc 46
        <TitleSection title={LABELS.FIRST_LEVEL_PERSONS} />
47
        <SearchList onChange={(value) => setSearch(value)}/>
48
        <div className="companies-list" style={{ position: 'relative', padding: '0 15px' }}>
4889 stevensc 49
          {myConnections.length
50
            ? myConnections.map(({
51
              image,
52
              name,
53
              link_view,
54
              link_inmail,
55
              link_cancel,
5121 stevensc 56
              link_block
4889 stevensc 57
            }, id) =>
58
              <Profile
59
                isTopData
60
                key={id}
61
                image={image}
62
                name={name}
63
                link_inmail={link_inmail}
64
                link_view={link_view}
65
                link_cancel={link_cancel}
66
                link_block={link_block}
67
                fetchCallback={fetchMyConnections}
68
              />
2384 stevensc 69
            )
5121 stevensc 70
            : <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS}/>
4889 stevensc 71
          }
72
          {loading && <Spinner />}
1 www 73
        </div>
4889 stevensc 74
        <PaginationComponent
75
          onChangePage={handleChangePage}
76
          pages={pages}
77
          currentActivePage={currentPage}
78
          isRow={true}
79
        />
1 www 80
      </div>
81
    </section>
4889 stevensc 82
  )
83
}
1 www 84
 
85
const mapDispatchToProps = {
5121 stevensc 86
  addNotification: (notification) => addNotification(notification)
4889 stevensc 87
}
1 www 88
 
5121 stevensc 89
export default connect(null, mapDispatchToProps)(MyConnections)