Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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