Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Rev 2334 | 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>
104
        <div className="companies-list">
105
          <div
106
            className="row"
107
            id="profiles-container"
108
            style={{
109
              position: "relative",
110
            }}
111
          >
1158 stevensc 112
            {
113
              companies.length
114
                ?
115
                companies.map((company, id) => (
116
                  <CompanyTemplate
117
                    company={company}
118
                    key={id}
119
                    onRequestAction={handleRequestAction}
120
                  />
121
                ))
122
                :
123
                <div style={{ margin: "auto", textAlign: "center" }}>
124
                  Ningún registro coincidio con su consulta
125
                </div>
126
            }
127
            {
128
              loading
129
              &&
1 www 130
              <div className="spinner-container">
131
                <Spinner />
132
              </div>
1158 stevensc 133
            }
1 www 134
          </div>
135
          {/* <!--product-feed-tab end--> */}
136
        </div>
137
      </div>
138
    </section>
139
  );
140
};
141
 
142
// const mapStateToProps = (state) => ({});
143
 
144
const mapDispatchToProps = {
145
  addNotification: (notification) => addNotification(notification),
146
};
147
 
148
export default connect(null, mapDispatchToProps)(InvitationsReceived);