Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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