Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2328 | Rev 5164 | 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 styled from "styled-components";
1158 stevensc 5
import { axios } from "../../../utils";
1 www 6
import Company from "./company/Company";
7
import Spinner from "../../../shared/loading-spinner/Spinner";
8
import AddCompanyModal from "./add-company-modal/AddCompanyModal";
1581 steven 9
import SearchList from "../../../components/SearchList";
1583 steven 10
import Profile from "../../../components/Profile";
1 www 11
 
12
const StyledSpinnerContainer = styled.div`
13
  position: absolute;
14
  left: 0;
15
  top: 0;
16
  width: 100%;
17
  height: 100%;
18
  background: rgba(255, 255, 255, 0.4);
19
  display: flex;
20
  justify-content: center;
21
  align-items: center;
22
  z-index: 300;
23
`;
24
 
25
const MyCompanies = (props) => {
26
  // backendVars destructuring
27
  const { companySizes, industries } = props.backendVars;
28
 
29
  // states
30
  const [companies, setCompanies] = useState([]);
31
  const [loading, setLoading] = useState(true);
32
  const [showAddCompanyModal, setShowCompanyModal] = useState(false);
33
 
34
  // React hook form
35
  const { register, getValues } = useForm();
36
 
37
  let axiosThrottle = null;
38
 
39
  useEffect(() => {
40
    fetchCompanies();
41
    return () => {
42
      clearTimeout(axiosThrottle);
43
    };
44
  }, []);
45
 
1158 stevensc 46
  const fetchCompanies = async (searchParam = '') => {
1 www 47
    setLoading(true);
48
    await axios
49
      .get(
1158 stevensc 50
        "/company/my-companies?search=" + searchParam)
1 www 51
      .then((response) => {
52
        const resData = response.data;
53
        if (resData.success) {
54
          setCompanies(resData.data);
55
        }
56
      });
57
    setLoading(false);
58
  };
59
 
60
  const handleSearch = () => {
61
    //  (getValues());
62
    clearTimeout(axiosThrottle);
63
    // setLoading(true);
64
    const searchValue = getValues("search");
65
    axiosThrottle = setTimeout(() => {
66
      fetchCompanies(searchValue);
67
    }, 500);
68
  };
69
 
70
  const handleShowAddCompanyModal = () => {
71
    setShowCompanyModal(!showAddCompanyModal);
72
  };
73
 
74
  return (
75
    <React.Fragment>
76
      <section className="companies-info">
77
        <div className="container">
1581 steven 78
          <SearchList
79
            title="Mis Empresas"
80
            fetchCallback={fetchCompanies}
81
            addTitle="Agregar"
82
            addCallback={handleShowAddCompanyModal}
83
          />
1 www 84
 
2328 stevensc 85
          <div
86
            className="companies-list"
87
            id="profiles-container"
88
            style={{
89
              position: "relative",
90
            }}>
91
            {
92
              companies.length
93
                ?
94
                companies.map(({ image, link_my_company, link_view, name, status }, id) => (
95
                  <Profile
96
                    link_admin={link_my_company}
97
                    key={id}
98
                    name={name}
99
                    image={image}
100
                    status={status}
101
                    link_view={link_view}
2504 stevensc 102
                    btnAcceptTitle='Ver Empresa'
2328 stevensc 103
                  />
104
                ))
105
                :
106
                <div style={{ margin: "auto", textAlign: "center" }}>
107
                  Ningún registro coincidio con su consulta
108
                </div>
109
            }
110
            {loading && (
111
              <StyledSpinnerContainer>
112
                <Spinner />
113
              </StyledSpinnerContainer>
114
            )}
1 www 115
            {/* <!--product-feed-tab end--> */}
116
          </div>
117
        </div>
118
      </section>
119
 
120
      <AddCompanyModal
121
        show={showAddCompanyModal}
122
        onHide={handleShowAddCompanyModal}
123
        fetchCompanies={fetchCompanies}
124
        companySizes={companySizes}
125
        industries={industries}
126
      />
127
    </React.Fragment>
128
  );
129
};
130
 
131
export default MyCompanies;