Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| 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 { connect } from "react-redux";
4
import { useForm } from "react-hook-form";
5
import {axios} from "../../../../../utils";
6
import styled from "styled-components";
7
import Job from "./job/Job";
8
import Spinner from "../../../../../shared/loading-spinner/Spinner";
9
import AddJobModal from "./add-job-modal/AddJobModal";
10
 
11
const StyledSpinnerContainer = styled.div`
12
  position: absolute;
13
  left: 0;
14
  top: 0;
15
  width: 100%;
16
  height: 100%;
17
  background: rgba(255, 255, 255, 0.4);
18
  display: flex;
19
  justify-content: center;
20
  align-items: center;
21
  z-index: 300;
22
`;
23
 
24
const Jobs = (props) => {
25
  // backendVars destructuring
26
  const {
27
    companyId,
28
    companyName,
29
    employmentTypes,
30
    jobCategories,
31
  } = props.backendVars;
32
  // states
33
  const [jobs, setJobs] = useState([]);
34
  const [loading, setLoading] = useState(true);
35
  const [showAddJobModal, setShowAddJobModal] = useState(false);
36
 
37
  // redux destructuring
38
  const { addNotification } = props;
39
 
40
  // React hook form
41
  const { register, getValues } = useForm();
42
 
43
  let axiosThrottle = null;
44
 
45
  useEffect(() => {
46
    fetchJobs();
47
    return () => {
48
      clearTimeout(axiosThrottle);
49
    };
50
  }, []);
51
 
52
  const fetchJobs = async (searchParam='') => {
53
    setLoading(true);
54
    await axios
55
      .get(
56
        `/my-company/${companyId}/job?search=${searchParam}`)
57
      .then((response) => {
58
        const resData = response.data;
59
         (resData);
60
        if (resData.success) {
61
          setJobs(resData.data);
62
        }
63
      });
64
    setLoading(false);
65
  };
66
 
67
  const handleSearch = () => {
68
    //  (getValues());
69
    clearTimeout(axiosThrottle);
70
    // setLoading(true);
71
    const searchValue = getValues("search");
72
    axiosThrottle = setTimeout(() => {
73
      fetchJobs(searchValue);
74
    }, 500);
75
  };
76
 
77
  const handleDelete = (link) => {
78
    setLoading(true);
79
    axios
80
      .post(link)
81
      .then((response) => {
82
        const resData = response.data;
83
         (resData);
84
        if (resData.success) {
85
          const msg = resData.data;
86
          addNotification({
87
            style: "success",
88
            msg: msg,
89
          });
90
          fetchGroups();
91
        } else {
92
          setLoading(false);
93
        }
94
      })
95
      .catch((error) => {
96
        setLoading(false);
97
      });
98
  };
99
 
100
  const handleShowAddJobModal = () => {
101
    setShowAddJobModal(!showAddJobModal);
102
  };
103
 
104
  return (
105
    <React.Fragment>
106
      <section className="companies-info">
107
        <div className="container">
108
          <div className="company-title">
109
            <div className="section_admin_title_buttons">
110
              <div style={{ float: "left" }}>
111
                <h1 className="title">{`${companyName} - Mis Empleos`}</h1>
112
              </div>
113
              {/* <?php if($allowAdd) : ?> */}
114
              <div style={{ float: "right" }}>
115
                <button
116
                  type="button"
117
                  className="btn btn-primary btn-add"
118
                  onClick={handleShowAddJobModal}
119
                >
120
                  Agregar
121
                </button>
122
              </div>
123
              {/* <?php endif; ?> */}
124
            </div>
125
          </div>
126
 
127
          <div className="company-title">
128
            <div className="section_admin_title_buttons">
129
              <form
130
                name="form-connection-search"
131
                id="form-connection-search"
132
                onSubmit={(event) => event.preventDefault()}
133
              >
134
                <div className="form-group">
135
                  <input
136
                    type="text"
137
                    name="search"
138
                    id="search"
139
                    className="form-control"
140
                    placeholder="Buscar"
141
                    ref={register}
142
                    onChange={handleSearch}
143
                  />
144
                </div>
145
              </form>
146
            </div>
147
          </div>
148
 
149
          <div className="companies-list">
150
            <div
151
              className="row"
152
              id="profiles-container"
153
              style={{
154
                position: "relative",
155
              }}
156
            >
157
              {jobs.length ? (
158
                jobs.map(
159
                  ({
160
                    title,
161
                    status,
162
                    employment_type,
163
                    last_date_of_application,
164
                    link_users,
165
                    link_view,
166
                    link_admin,
167
                    link_delete,
168
                    id,
169
                  }) => (
170
                    <Job
171
                      title={title}
172
                      status={status}
173
                      employment_type={employment_type}
174
                      last_date_of_application={last_date_of_application}
175
                      link_users={link_users}
176
                      link_view={link_view}
177
                      link_admin={link_admin}
178
                      link_delete={link_delete}
179
                      onDelete={handleDelete}
180
                      key={id}
181
                    />
182
                  )
183
                )
184
              ) : (
185
                <div style={{ margin: "auto", textAlign: "center" }}>
186
                  Ningún registro coincidio con su consulta
187
                </div>
188
              )}
189
              {loading && (
190
                <StyledSpinnerContainer>
191
                  <Spinner />
192
                </StyledSpinnerContainer>
193
              )}
194
            </div>
195
            {/* <!--product-feed-tab end--> */}
196
          </div>
197
        </div>
198
      </section>
199
      <AddJobModal
200
        show={showAddJobModal}
201
        onHide={handleShowAddJobModal}
202
        companyId={companyId}
203
        fetchJobs={fetchJobs}
204
        addNotification={addNotification}
205
        employmentTypes={employmentTypes}
206
        jobCategories={jobCategories}
207
      />
208
    </React.Fragment>
209
  );
210
};
211
 
212
// const mapStateToProps = (state) => ({});
213
 
214
const mapDispatchToProps = {
215
  addNotification: (notification) => addNotification(notification),
216
};
217
 
218
export default connect(null, mapDispatchToProps)(Jobs);