Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Rev 1569 | 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";
4
import { useForm } from "react-hook-form";
5
import styled from "styled-components";
6
import {axios} from "../../../utils";
7
import { addNotification } from "../../../redux/notification/notification.actions";
8
import Spinner from "../../../shared/loading-spinner/Spinner";
9
import Entity from "./entity/Entity";
1564 steven 10
import Profile from "../../../components/Profile";
1 www 11
 
12
const StyledSpinnerContainer = styled.div`
13
  position: absolute;
14
  left: 0;
15
  top: 0;
16
  width: 100%;
17
  height: 100%;
18
  background: rgba(255, 255, 255, 0.4);
19
  display: flex;
20
  justify-content: center;
21
  align-items: center;
22
  z-index: 300;
23
`;
24
 
25
const MyConnections = (props) => {
26
  // states
27
  const [myConnections, setMyConnections] = useState([]);
28
  const [loading, setLoading] = useState(true);
29
 
30
  // redux destructuring
31
  const { addNotification } = props;
32
 
33
  // React hook form
34
  const { register, getValues } = useForm();
35
 
36
  let axiosThrottle = null;
37
 
38
  useEffect(() => {
39
    fetchMyConnections();
40
    return () => {
41
      clearTimeout(axiosThrottle);
42
    };
43
  }, []);
44
 
45
  const handleBlock = (link) => {
46
    handleAction(link);
47
  };
48
 
49
  const handleCancel = (link) => {
50
    handleAction(link);
51
  };
52
 
53
  const handleAction = (link) => {
54
    setLoading(true);
55
    axios
56
      .post(link)
57
      .then((response) => {
58
        const resData = response.data;
59
         (resData);
60
        if (resData.success) {
61
          const msg = resData.data;
62
          addNotification({
63
            style: "success",
64
            msg: msg,
65
          });
66
          fetchMyConnections();
67
        } else {
68
          setLoading(false);
69
        }
70
      })
71
      .catch((error) => {
72
        setLoading(false);
73
      });
74
  };
75
 
76
  const fetchMyConnections = async (searchParam='') => {
77
    setLoading(true);
78
    await axios
79
      .get(
80
        "/connection/my-connections?search="+searchParam)
81
      .then((response) => {
82
        const resData = response.data;
83
        if (resData.success) {
84
          setMyConnections(resData.data);
85
        }
86
      });
87
    setLoading(false);
88
  };
89
 
90
  const handleSearch = () => {
91
    //  (getValues());
92
    clearTimeout(axiosThrottle);
93
    // setLoading(true);
94
    const searchValue = getValues("search");
95
    axiosThrottle = setTimeout(() => {
96
      fetchMyConnections(searchValue);
97
    }, 500);
98
  };
99
 
100
  return (
101
    <section className="companies-info">
102
      <div className="container">
103
        <div className="company-title">
104
          <div className="section_admin_title_buttons">
105
            <div style={{ float: "left" }}>
106
              <h1 className="title">Personas con relación directa, de 1er nivel</h1>
107
            </div>
108
          </div>
109
        </div>
110
 
111
        <div className="company-title">
112
          <div className="section_admin_title_buttons">
113
            <form
114
              name="form-connection-search"
115
              id="form-connection-search"
116
              onSubmit={(event) => event.preventDefault()}
117
            >
118
              <div className="form-group">
119
                <input
120
                  type="text"
121
                  name="search"
122
                  id="search"
123
                  className="form-control"
124
                  placeholder="Buscar"
125
                  ref={register}
126
                  onChange={handleSearch}
127
                />
128
              </div>
129
            </form>
130
          </div>
131
        </div>
132
 
133
        <div className="companies-list">
134
          <div
135
            className="row"
136
            id="profiles-container"
137
            style={{
138
              position: "relative",
139
              padding: "0 15px",
140
            }}
141
          >
142
            {myConnections.length > 0 ? (
143
              myConnections.map(
144
                (
145
                  {
146
                    image,
147
                    name,
148
                    link_view,
149
                    link_inmail,
150
                    link_cancel,
151
                    link_block,
152
                  },
153
                  id
154
                ) => (
1564 steven 155
                  <Profile
156
                    key={id}
1 www 157
                    image={image}
158
                    name={name}
1564 steven 159
                    link_inmail={link_inmail}
1 www 160
                    link_view={link_view}
161
                    link_cancel={link_cancel}
162
                    link_block={link_block}
1564 steven 163
                    fetchCallback={fetchMyConnections}
1 www 164
                  />
165
                )
166
              )
167
            ) : (
168
              <p>No hay resultados</p>
169
            )}
170
            {loading && (
171
              <StyledSpinnerContainer>
172
                <Spinner />
173
              </StyledSpinnerContainer>
174
            )}
175
          </div>
176
          {/* <!--product-feed-tab end--> */}
177
        </div>
178
      </div>
179
    </section>
180
  );
181
};
182
 
183
// const mapStateToProps = (state) => ({});
184
 
185
const mapDispatchToProps = {
186
  addNotification: (notification) => addNotification(notification),
187
};
188
 
189
export default connect(null, mapDispatchToProps)(MyConnections);