Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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