Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Rev 1535 | 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 { connect } from "react-redux";
4
import { useForm } from "react-hook-form";
5
import styled from "styled-components";
6
import {axios} from "../../../utils";
7
import { addNotification } from "../../../redux/notification/notification.actions";
8
import Spinner from "../../../shared/loading-spinner/Spinner";
9
import AppliedJob from "./applied-job/AppliedJob";
1518 steven 10
import ProfileCard from "../../../profile/my-profiles/my-profiles/profile/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 AppliedJobs = (props) => {
26
  // states
27
  const [appliedJobs, setAppliedJobs] = useState([]);
28
  const [loading, setLoading] = useState(true);
29
 
30
  // redux destructuring
31
  const { addNotification } = props;
32
 
33
  // React hook form
34
  const { register, getValues } = useForm();
35
 
36
  let axiosThrottle = null;
37
 
38
  useEffect(() => {
39
    fetchAppliedJobs();
40
    return () => {
41
      clearTimeout(axiosThrottle);
42
    };
43
  }, []);
44
 
45
  const handleCancelApply = (cancelLink) => {
46
    setLoading(true);
47
    axios
48
      .post(cancelLink)
49
      .then((response) => {
50
        const resData = response.data;
51
         (resData);
52
        if (resData.success) {
53
          const msg = resData.data;
54
          addNotification({
55
            style: "success",
56
            msg: msg,
57
          });
58
          fetchAppliedJobs();
59
        } else {
60
          const errorMsg =
61
            typeof resData.data === "string"
62
              ? resData.data
63
              : "Ha ocurrido un error, Por favor intente más tarde";
64
          addNotification({
65
            style: "danger",
66
            msg: errorMsg,
67
          });
68
          setLoading(false);
69
        }
70
      })
71
      .catch((error) => {
72
         (error);
73
        setLoading(false);
74
      });
75
  };
76
 
77
  const fetchAppliedJobs = async (searchParam='') => {
78
    setLoading(true);
79
    await axios
80
      .get(
81
        "/job/applied-jobs?search="+searchParam)
82
      .then((response) => {
83
        const resData = response.data;
84
        if (resData.success) {
85
          setAppliedJobs(resData.data);
86
        }
87
      });
88
    setLoading(false);
89
  };
90
 
91
  const handleSearch = () => {
92
    //  (getValues());
93
    clearTimeout(axiosThrottle);
94
    // setLoading(true);
95
    const searchValue = getValues("search");
96
    axiosThrottle = setTimeout(() => {
97
      fetchAppliedJobs(searchValue);
98
    }, 500);
99
  };
100
 
101
  return (
102
    <section className="companies-info" style={{ position: "relative" }}>
103
      <div className="container">
104
        <div className="company-title">
105
          <div className="section_admin_title_buttons">
106
            <div style={{ float: "left" }}>
107
              <h1 className="title">Que he aplicado</h1>
108
            </div>
109
          </div>
110
        </div>
111
 
112
        <div className="company-title">
113
          <div className="section_admin_title_buttons">
114
            <div className="form-group">
115
              <input
116
                type="text"
117
                name="search"
118
                id="search"
119
                className="form-control"
120
                placeholder="Buscar"
121
                ref={register}
122
                onChange={handleSearch}
123
              />
124
            </div>
125
          </div>
126
        </div>
127
        <div
128
          className="companies-list"
129
          style={{
130
            padding: "0 15px",
131
          }}
132
        >
133
          <div className="row" id="profiles-container">
134
            {appliedJobs.length > 0 ? (
135
              appliedJobs.map(
136
                (
137
                  {
138
                    title,
139
                    employment_type,
140
                    last_date_of_application,
141
                    link_view,
142
                    link_remove,
143
                  },
144
                  index
145
                ) => (
1518 steven 146
                  <ProfileCard
147
                    key={index}
148
                    // image={image}
149
                    name={title}
150
                    status={employment_type}
1 www 151
                    link_view={link_view}
1518 steven 152
                    link_delete={link_remove}
153
                    fetchCallback={fetchAppliedJobs}
1 www 154
                  />
1518 steven 155
                  // <AppliedJob
156
                  //   title={title}
157
                  //   employment_type={employment_type}
158
                  //   last_date_of_application={last_date_of_application}
159
                  //   link_view={link_view}
160
                  //   link_remove={link_remove}
161
                  //   onCancelApply={handleCancelApply}
162
                  //   key={index}
163
                  // />
1 www 164
                )
165
              )
166
            ) : (
167
              <p>No hay resultados</p>
168
            )}
169
          </div>
170
          {/* <!--product-feed-tab end--> */}
171
        </div>
172
      </div>
173
      {loading && (
174
        <StyledSpinnerContainer>
175
          <Spinner />
176
        </StyledSpinnerContainer>
177
      )}
178
    </section>
179
  );
180
};
181
 
182
// const mapStateToProps = (state) => ({});
183
 
184
const mapDispatchToProps = {
185
  addNotification: (notification) => addNotification(notification),
186
};
187
 
188
export default connect(null, mapDispatchToProps)(AppliedJobs);