Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2810 | Rev 5156 | 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 styled from "styled-components";
2348 stevensc 5
import { axios } from "../../../utils";
1 www 6
import { addNotification } from "../../../redux/notification/notification.actions";
7
import Spinner from "../../../shared/loading-spinner/Spinner";
1547 steven 8
import SearchList from "../../../components/SearchList";
1548 steven 9
import Card from "../../../components/Profile";
1 www 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
 
3063 stevensc 24
const SavedJobs = () => {
1 www 25
  // states
26
  const [savedJobs, setSavedJobs] = useState([]);
27
  const [loading, setLoading] = useState(true);
28
 
29
  let axiosThrottle = null;
30
 
31
  useEffect(() => {
32
    fetchSavedJobs();
33
    return () => {
34
      clearTimeout(axiosThrottle);
35
    };
36
  }, []);
37
 
38
  const handleCancelApply = (cancelLink) => {
39
    setLoading(true);
40
    axios
41
      .post(cancelLink)
42
      .then((response) => {
43
        const resData = response.data;
2348 stevensc 44
        (resData);
1 www 45
        if (resData.success) {
46
          fetchSavedJobs();
47
        } else {
48
          const errorMsg =
49
            typeof resData.data === "string"
50
              ? resData.data
51
              : "Ha ocurrido un error, Por favor intente más tarde";
52
          addNotification({
53
            style: "danger",
54
            msg: errorMsg,
55
          });
56
          setLoading(false);
57
        }
58
      })
59
      .catch((error) => {
2348 stevensc 60
        (error);
1 www 61
        setLoading(false);
62
      });
63
  };
64
 
2348 stevensc 65
  const fetchSavedJobs = async (searchParam = '') => {
1 www 66
    setLoading(true);
3063 stevensc 67
    await axios.get("/job/saved-jobs?search=" + searchParam)
1 www 68
      .then((response) => {
69
        const resData = response.data;
70
        if (resData.success) {
2810 kerby 71
          console.log(resData.data)
1 www 72
          setSavedJobs(resData.data);
73
        }
74
      });
75
    setLoading(false);
76
  };
1549 steven 77
 
1 www 78
  return (
79
    <section className="companies-info" style={{ position: "relative" }}>
80
      <div className="container">
1547 steven 81
        <SearchList
2403 stevensc 82
          title="Empleos guardados"
1547 steven 83
          fetchCallback={fetchSavedJobs}
84
        />
3063 stevensc 85
        <div className="companies-list" style={{ padding: "0 15px", }}>
86
          {savedJobs.length > 0
87
            ?
2348 stevensc 88
            savedJobs.map(
3063 stevensc 89
              ({
90
                employment_type,
91
                id,
92
                image,
93
                link_remove,
94
                link_view,
95
                title,
96
              }) =>
2348 stevensc 97
                <Card
3063 stevensc 98
                  key={id}
2808 kerby 99
                  image={image}
2348 stevensc 100
                  name={title}
101
                  status={employment_type}
102
                  link_view={link_view}
103
                  link_delete={link_remove}
104
                  fetchCallback={fetchSavedJobs}
2522 stevensc 105
                  btnAcceptTitle='Ver Empleo'
2403 stevensc 106
                  btnCancelTitle='Eliminar'
2348 stevensc 107
                />
108
            )
3063 stevensc 109
            : <p>No hay resultados</p>
110
          }
1 www 111
        </div>
112
      </div>
113
      {loading && (
114
        <StyledSpinnerContainer>
115
          <Spinner />
116
        </StyledSpinnerContainer>
117
      )}
118
    </section>
119
  );
120
};
121
 
122
// const mapStateToProps = (state) => ({});
123
 
124
const mapDispatchToProps = {
125
  addNotification: (notification) => addNotification(notification),
126
};
127
 
128
export default connect(null, mapDispatchToProps)(SavedJobs);