Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1158 | Rev 2335 | 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 { useForm } from "react-hook-form";
1158 stevensc 4
import { axios } from "../../../utils";
1 www 5
import Spinner from "../../../shared/loading-spinner/Spinner";
6
import { connect } from "react-redux";
7
import { addNotification } from "../../../redux/notification/notification.actions";
8
import CompanyTemplate from "./companyTemplate/CompanyTemplate";
9
 
10
const InvitationsReceived = (props) => {
11
  // redux destructuring
12
  const { addNotification } = props;
13
 
14
  // states
15
  const [companies, setCompanies] = useState([]);
16
  const [loading, setLoading] = useState(true);
17
 
18
  // React hook form
19
  const { register, getValues } = useForm();
20
 
21
  let axiosThrottle = null;
22
 
23
  useEffect(() => {
24
    fetchCompanies();
25
    return () => {
26
      clearTimeout(axiosThrottle);
27
    };
28
  }, []);
29
 
1158 stevensc 30
  const fetchCompanies = async (searchParam = '') => {
1 www 31
    setLoading(true);
32
    await axios
1158 stevensc 33
      .get("/company/invitations-received?search=" + searchParam)
1 www 34
      .then((response) => {
35
        const resData = response.data;
36
        if (resData.success) {
37
          setCompanies(resData.data);
38
        }
39
      });
40
    setLoading(false);
41
  };
42
 
43
  const handleSearch = () => {
44
    //  (getValues());
45
    clearTimeout(axiosThrottle);
46
    // setLoading(true);
47
    const searchValue = getValues("search");
48
    axiosThrottle = setTimeout(() => {
49
      fetchCompanies(searchValue);
50
    }, 500);
51
  };
52
 
53
  const handleRequestAction = (link) => {
54
    setLoading(true);
55
    axios.post(link).then((response) => {
56
      const resData = response.data;
57
      if (resData.success) {
58
        addNotification({
59
          style: "success",
60
          msg: resData.data,
61
        });
62
        fetchCompanies();
63
      } else {
64
        setLoading(false);
65
        addNotification({
66
          style: "danger",
67
          msg: resData.data ?? "ha ocurrido un error",
68
        });
69
      }
70
    });
71
  };
72
 
73
  return (
74
    <section className="companies-info">
75
      <div className="container">
76
        <div className="company-title">
77
          <div className="section_admin_title_buttons">
78
            <div>
79
              <h1 className="title">Solicitudes recibidas</h1>
80
            </div>
81
          </div>
82
        </div>
83
        <div className="company-title">
84
          <div className="section_admin_title_buttons">
85
            <form
86
              name="form-connection-search"
87
              id="form-connection-search"
88
              onSubmit={(event) => event.preventDefault()}
89
            >
90
              <div className="form-group">
91
                <input
92
                  type="text"
93
                  name="search"
94
                  id="search"
95
                  className="form-control"
96
                  placeholder="Buscar"
97
                  ref={register}
98
                  onChange={handleSearch}
99
                />
100
              </div>
101
            </form>
102
          </div>
103
        </div>
2334 stevensc 104
        <div
105
          className="companies-list"
106
          id="profiles-container"
107
          style={{
108
            position: "relative",
109
          }}
110
        >
111
          {
112
            companies.length
113
              ?
114
              companies.map((company, id) => (
115
                <CompanyTemplate
116
                  company={company}
117
                  key={id}
118
                  onRequestAction={handleRequestAction}
119
                />
120
              ))
121
              :
122
              <div style={{ margin: "auto", textAlign: "center" }}>
123
                Ningún registro coincidio con su consulta
1 www 124
              </div>
2334 stevensc 125
          }
126
          {
127
            loading
128
            &&
129
            <div className="spinner-container">
130
              <Spinner />
131
            </div>
132
          }
1 www 133
          {/* <!--product-feed-tab end--> */}
134
        </div>
135
      </div>
2334 stevensc 136
    </section >
1 www 137
  );
138
};
139
 
140
// const mapStateToProps = (state) => ({});
141
 
142
const mapDispatchToProps = {
143
  addNotification: (notification) => addNotification(notification),
144
};
145
 
146
export default connect(null, mapDispatchToProps)(InvitationsReceived);