Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2808 | Rev 3063 | 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";
2348 stevensc 6
import { axios } from "../../../utils";
1 www 7
import { addNotification } from "../../../redux/notification/notification.actions";
8
import Spinner from "../../../shared/loading-spinner/Spinner";
9
import SavedJob from "./saved-job/SavedJob";
1547 steven 10
import SearchList from "../../../components/SearchList";
1548 steven 11
import Card from "../../../components/Profile";
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 SavedJobs = (props) => {
27
  // states
28
  const [savedJobs, setSavedJobs] = 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
    fetchSavedJobs();
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;
2348 stevensc 52
        (resData);
1 www 53
        if (resData.success) {
54
          fetchSavedJobs();
55
        } else {
56
          const errorMsg =
57
            typeof resData.data === "string"
58
              ? resData.data
59
              : "Ha ocurrido un error, Por favor intente más tarde";
60
          addNotification({
61
            style: "danger",
62
            msg: errorMsg,
63
          });
64
          setLoading(false);
65
        }
66
      })
67
      .catch((error) => {
2348 stevensc 68
        (error);
1 www 69
        setLoading(false);
70
      });
71
  };
72
 
2348 stevensc 73
  const fetchSavedJobs = async (searchParam = '') => {
1 www 74
    setLoading(true);
75
    await axios
76
      .get(
2348 stevensc 77
        "/job/saved-jobs?search=" + searchParam)
1 www 78
      .then((response) => {
79
        const resData = response.data;
80
        if (resData.success) {
2810 kerby 81
          console.log(resData.data)
1 www 82
          setSavedJobs(resData.data);
83
        }
84
      });
85
    setLoading(false);
86
  };
1549 steven 87
 
1 www 88
  return (
89
    <section className="companies-info" style={{ position: "relative" }}>
90
      <div className="container">
1547 steven 91
        <SearchList
2403 stevensc 92
          title="Empleos guardados"
1547 steven 93
          fetchCallback={fetchSavedJobs}
94
        />
1 www 95
        <div
96
          className="companies-list"
2348 stevensc 97
          id="profiles-container"
1 www 98
          style={{
99
            padding: "0 15px",
100
          }}
101
        >
2348 stevensc 102
          {savedJobs.length > 0 ? (
103
            savedJobs.map(
104
              (
105
                {
106
                  title,
107
                  employment_type,
108
                  last_date_of_application,
2808 kerby 109
                  image,
2348 stevensc 110
                  link_view,
111
                  link_remove,
112
                },
113
                index
114
              ) => (
115
                <Card
116
                  key={index}
2808 kerby 117
                  image={image}
2348 stevensc 118
                  name={title}
119
                  status={employment_type}
120
                  link_view={link_view}
121
                  link_delete={link_remove}
122
                  fetchCallback={fetchSavedJobs}
2522 stevensc 123
                  btnAcceptTitle='Ver Empleo'
2403 stevensc 124
                  btnCancelTitle='Eliminar'
2348 stevensc 125
                />
126
                // <SavedJob
127
                //   title={title}
128
                //   employment_type={employment_type}
129
                //   last_date_of_application={last_date_of_application}
130
                //   link_view={link_view}
131
                //   link_remove={link_remove}
132
                //   onCancelApply={handleCancelApply}
133
                //   key={index}
134
                // />
1 www 135
              )
2348 stevensc 136
            )
137
          ) : (
138
            <p>No hay resultados</p>
139
          )}
1 www 140
          {/* <!--product-feed-tab end--> */}
141
        </div>
142
      </div>
143
      {loading && (
144
        <StyledSpinnerContainer>
145
          <Spinner />
146
        </StyledSpinnerContainer>
147
      )}
148
    </section>
149
  );
150
};
151
 
152
// const mapStateToProps = (state) => ({});
153
 
154
const mapDispatchToProps = {
155
  addNotification: (notification) => addNotification(notification),
156
};
157
 
158
export default connect(null, mapDispatchToProps)(SavedJobs);