Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4239 | Rev 4241 | 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"
4240 stevensc 84
          style={{ position: "relative", }}
2334 stevensc 85
        >
86
          {
87
            companies.length
88
              ?
2335 stevensc 89
              companies.map(({ image, name, link_view, link_reject, link_accept }, id) => (
90
                <Profile
2334 stevensc 91
                  key={id}
2335 stevensc 92
                  image={image}
93
                  name={name}
94
                  link_view={link_view}
95
                  link_reject={link_reject}
96
                  link_accept={link_accept}
97
                  fetchCallback={fetchCompanies}
2509 stevensc 98
                  btnAcceptTitle='Ver Empresa'
2334 stevensc 99
                />
100
              ))
101
              :
102
              <div style={{ margin: "auto", textAlign: "center" }}>
4240 stevensc 103
                {LABELS.not_found}
1 www 104
              </div>
2334 stevensc 105
          }
106
          {
107
            loading
108
            &&
109
            <div className="spinner-container">
110
              <Spinner />
111
            </div>
112
          }
1 www 113
          {/* <!--product-feed-tab end--> */}
114
        </div>
115
      </div>
2334 stevensc 116
    </section >
1 www 117
  );
118
};
119
 
120
// const mapStateToProps = (state) => ({});
121
 
122
const mapDispatchToProps = {
123
  addNotification: (notification) => addNotification(notification),
124
};
125
 
126
export default connect(null, mapDispatchToProps)(InvitationsReceived);