Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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