Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Rev 1581 | 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";
9
 
10
const StyledSpinnerContainer = styled.div`
11
  position: absolute;
12
  left: 0;
13
  top: 0;
14
  width: 100%;
15
  height: 100%;
16
  background: rgba(255, 255, 255, 0.4);
17
  display: flex;
18
  justify-content: center;
19
  align-items: center;
20
  z-index: 300;
21
`;
22
 
23
const MyCompanies = (props) => {
24
  // backendVars destructuring
25
  const { companySizes, industries } = props.backendVars;
26
 
27
  // states
28
  const [companies, setCompanies] = useState([]);
29
  const [loading, setLoading] = useState(true);
30
  const [showAddCompanyModal, setShowCompanyModal] = useState(false);
31
 
32
  // React hook form
33
  const { register, getValues } = useForm();
34
 
35
  let axiosThrottle = null;
36
 
37
  useEffect(() => {
38
    fetchCompanies();
39
    return () => {
40
      clearTimeout(axiosThrottle);
41
    };
42
  }, []);
43
 
1158 stevensc 44
  const fetchCompanies = async (searchParam = '') => {
1 www 45
    setLoading(true);
46
    await axios
47
      .get(
1158 stevensc 48
        "/company/my-companies?search=" + searchParam)
1 www 49
      .then((response) => {
50
        const resData = response.data;
51
        if (resData.success) {
52
          setCompanies(resData.data);
53
        }
54
      });
55
    setLoading(false);
56
  };
57
 
58
  const handleSearch = () => {
59
    //  (getValues());
60
    clearTimeout(axiosThrottle);
61
    // setLoading(true);
62
    const searchValue = getValues("search");
63
    axiosThrottle = setTimeout(() => {
64
      fetchCompanies(searchValue);
65
    }, 500);
66
  };
67
 
68
  const handleShowAddCompanyModal = () => {
69
    setShowCompanyModal(!showAddCompanyModal);
70
  };
71
 
72
  return (
73
    <React.Fragment>
74
      <section className="companies-info">
75
        <div className="container">
76
          <div className="company-title">
77
            <div className="section_admin_title_buttons">
78
              <div style={{ float: "left" }}>
79
                <h1 className="title">Mis Empresas</h1>
80
              </div>
81
              {/* <?php if($allowAdd) : ?> */}
82
              <div style={{ float: "right" }}>
83
                <button
84
                  type="button"
85
                  className="btn btn-primary btn-add"
86
                  onClick={(e) => {
87
                    e.preventDefault();
88
                    handleShowAddCompanyModal();
89
                  }}
90
                >
91
                  Agregar
92
                </button>
93
              </div>
94
              {/* <?php endif; ?> */}
95
            </div>
96
          </div>
97
          <div className="company-title">
98
            <div className="section_admin_title_buttons">
99
              <form
100
                name="form-connection-search"
101
                id="form-connection-search"
102
                onSubmit={(event) => event.preventDefault()}
103
              >
104
                <div className="form-group">
105
                  <input
106
                    type="text"
107
                    name="search"
108
                    id="search"
109
                    className="form-control"
110
                    placeholder="Buscar"
111
                    ref={register}
112
                    onChange={handleSearch}
113
                  />
114
                </div>
115
              </form>
116
            </div>
117
          </div>
118
 
119
          <div className="companies-list">
120
            <div
121
              className="row"
122
              id="profiles-container"
123
              style={{
124
                position: "relative",
125
              }}
126
            >
1158 stevensc 127
              {
128
                companies.length
129
                  ?
130
                  companies.map(({ image, link_my_company, link_view, name, status }, id) => (
131
                    <Company
132
                      image={image}
133
                      link_my_company={link_my_company}
134
                      link_view={link_view}
135
                      name={name}
136
                      status={status}
137
                      key={id}
138
                    />
139
                  ))
140
                  :
141
                  <div style={{ margin: "auto", textAlign: "center" }}>
142
                    Ningún registro coincidio con su consulta
143
                  </div>
144
              }
1 www 145
              {loading && (
146
                <StyledSpinnerContainer>
147
                  <Spinner />
148
                </StyledSpinnerContainer>
149
              )}
150
            </div>
151
            {/* <!--product-feed-tab end--> */}
152
          </div>
153
        </div>
154
      </section>
155
 
156
      <AddCompanyModal
157
        show={showAddCompanyModal}
158
        onHide={handleShowAddCompanyModal}
159
        fetchCompanies={fetchCompanies}
160
        companySizes={companySizes}
161
        industries={industries}
162
      />
163
    </React.Fragment>
164
  );
165
};
166
 
167
export default MyCompanies;