Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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