Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3640 efrain 1
import React from "react";
2
import { useEffect, useState } from "react";
3
import { connect } from "react-redux";
4
import { useForm } from "react-hook-form";
5
import styled from "styled-components";
6
import { axios, jsonToParams } from "../../utils";
7
import { addNotification } from "../../redux/notification/notification.actions";
8
import Spinner from "../../shared/loading-spinner/Spinner";
9
import Entity from "./entity/Entity";
10
import Profile from "../../components/Profile";
11
import SearchList from "../../components/SearchList";
12
import PaginationComponent from "../../shared/pagination/PaginationComponent";
13
 
14
const StyledSpinnerContainer = styled.div`
15
  position: absolute;
16
  left: 0;
17
  top: 0;
18
  width: 100%;
19
  height: 100%;
20
  background: rgba(255, 255, 255, 0.4);
21
  display: flex;
22
  justify-content: center;
23
  align-items: center;
24
  z-index: 300;
25
`;
26
 
27
const Impersonate = (props) => {
28
  // states
29
  const [users, setUsers] = useState([]);
30
  const [loading, setLoading] = useState(true);
31
  const [error, setError] = useState("");
32
  const [currentPage, setCurrentPage] = useState(1);
33
  const [pages, setPages] = useState(1);
34
  const { register, getValues } = useForm();
35
 
36
 
37
  useEffect(() => {
38
    fetchUsers();
39
  }, []);
40
 
41
 
42
 
43
 
44
 
45
	const handleSearch = () => {
46
        const searchValue = getValues("search");
47
 
48
		console.log('searchValue')
49
		console.log(searchValue)
50
        setTimeout(() => fetchUsers(1, searchValue ), [500])
51
    };
52
 
53
 
54
const fetchUsers = async (page = 1, keyword  = '') => {
55
    setLoading(true);
56
    setError(false);
57
    setCurrentPage(page)
58
    let urlParams = {
59
      page,
60
      keyword
61
    }
62
 
63
 
64
    await axios
65
      .get(`/impersonate?${jsonToParams(urlParams)}`)
66
      .then((response) => {
67
        const responseData = response.data;
68
        if (responseData.success) {
69
          setUsers(responseData.data.current.items);
70
          setPages(responseData.data.total.pages);
71
        } else {
72
          const newError = responseData.data;
73
          setError(newError);
74
        }
75
      });
76
    setLoading(false);
77
  };
78
 
79
  return (
80
    <section className="companies-info">
81
      <div className="container">
82
 
83
 
84
                <div className="company-title">
85
                    <div
86
                        className="section_admin_title_buttons" >
87
                        <h1
88
                            className="title">Usuarios disponibles a personalizar</h1>
89
                    </div>
90
                </div>
91
 
92
            <div className="company-title">
93
                <div className="search-box border-gray border-radius">
94
                    <div className="form-group">
95
                        <input
96
                            type="text"
97
                            name="search"
98
                            id="search"
99
                            className="form-control"
100
                            placeholder=""
101
							ref={register}
102
                            onKeyUp={handleSearch}
103
 
104
                        />
105
                    </div>
106
                </div>
107
            </div>
108
 
109
 
110
        <div
111
          className="companies-list"
112
          id="profiles-container"
113
          style={{ position: "relative", padding: "0 15px" }}
114
        >
115
          {users.length > 0 ? (
116
            users.map(
117
              (
118
                {
119
                  image,
120
                  name,
121
				  email,
122
				  network,
123
                  link_impersonate,
124
                },
125
                id
126
              ) => (
127
                <Profile
128
                  isTopData
129
                  key={id}
130
                  image={image}
131
                  name={name}
132
				  email={email}
133
				  network={network}
134
                  link_impersonate={link_impersonate}
135
                />
136
              )
137
            )
138
          ) : (
139
            <p>No hay resultados</p>
140
          )}
141
          {loading && (
142
            <StyledSpinnerContainer>
143
              <Spinner />
144
            </StyledSpinnerContainer>
145
          )}
146
        </div>
147
      </div>
148
   <PaginationComponent
149
                  pages={pages}
150
                  currentActivePage={currentPage}
151
                  onChangePage={fetchUsers}
152
                />
153
    </section>
154
  );
155
};
156
 
157
// const mapStateToProps = (state) => ({});
158
 
159
const mapDispatchToProps = {
160
  addNotification: (notification) => addNotification(notification),
161
};
162
 
163
export default connect(null, mapDispatchToProps)(Impersonate);