Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2384 | Rev 4890 | 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({
20
      params: {
21
        search: search,
22
        page: currentPage,
23
      }
24
    })
25
  }, [currentPage, search]);
1 www 26
 
4889 stevensc 27
  const fetchMyConnections = async ({ params = {} }) => {
1 www 28
    setLoading(true);
29
    await axios
4889 stevensc 30
      .get('/connection/my-connections', { params: params })
31
      .then(({ data: response }) => {
32
        if (response.success) {
33
          setMyConnections(response.data.current.items)
34
          setCurrentPage(response.data.current.page)
35
          setPages(response.data.total.pages)
1 www 36
        }
37
      });
38
    setLoading(false);
39
  };
40
 
4889 stevensc 41
  const handleChangePage = (newPage) => setCurrentPage(newPage)
42
 
1 www 43
  return (
44
    <section className="companies-info">
45
      <div className="container">
1569 steven 46
        <SearchList
47
          title="Personas con Relación directa, de 1er nivel"
4889 stevensc 48
          fetchCallback={(value) => setSearch(value)}
1569 steven 49
        />
4889 stevensc 50
        <div className="companies-list" style={{ position: "relative", padding: "0 15px" }}>
51
          {myConnections.length
52
            ? myConnections.map(({
53
              image,
54
              name,
55
              link_view,
56
              link_inmail,
57
              link_cancel,
58
              link_block,
59
            }, id) =>
60
              <Profile
61
                isTopData
62
                key={id}
63
                image={image}
64
                name={name}
65
                link_inmail={link_inmail}
66
                link_view={link_view}
67
                link_cancel={link_cancel}
68
                link_block={link_block}
69
                fetchCallback={fetchMyConnections}
70
              />
2384 stevensc 71
            )
4889 stevensc 72
            : <p>No hay resultados</p>
73
          }
74
          {loading && <Spinner />}
1 www 75
        </div>
4889 stevensc 76
        <PaginationComponent
77
          onChangePage={handleChangePage}
78
          pages={pages}
79
          currentActivePage={currentPage}
80
          isRow={true}
81
        />
1 www 82
      </div>
83
    </section>
4889 stevensc 84
  )
85
}
1 www 86
 
87
const mapDispatchToProps = {
88
  addNotification: (notification) => addNotification(notification),
4889 stevensc 89
}
1 www 90
 
4889 stevensc 91
export default connect(null, mapDispatchToProps)(MyConnections);