Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1547 | Rev 1549 | 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 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;
52
         (resData);
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) => {
68
         (error);
69
        setLoading(false);
70
      });
71
  };
72
 
73
  const fetchSavedJobs = async (searchParam='') => {
74
    setLoading(true);
75
    await axios
76
      .get(
77
        "/job/saved-jobs?search="+searchParam)
78
      .then((response) => {
79
        const resData = response.data;
80
        if (resData.success) {
81
          setSavedJobs(resData.data);
82
        }
83
      });
84
    setLoading(false);
85
  };
1548 steven 86
 
1 www 87
  return (
88
    <section className="companies-info" style={{ position: "relative" }}>
89
      <div className="container">
1547 steven 90
        <SearchList
91
          title="Que he guardado"
92
          fetchCallback={fetchSavedJobs}
93
        />
1 www 94
        <div
95
          className="companies-list"
96
          style={{
97
            padding: "0 15px",
98
          }}
99
        >
100
          <div className="row" id="profiles-container">
101
            {savedJobs.length > 0 ? (
102
              savedJobs.map(
103
                (
104
                  {
105
                    title,
106
                    employment_type,
107
                    last_date_of_application,
108
                    link_view,
109
                    link_remove,
110
                  },
111
                  index
112
                ) => (
1548 steven 113
                  <ProfileCard
114
                    key={index}
115
                    // image={image}
116
                    name={title}
117
                    status={employment_type}
1 www 118
                    link_view={link_view}
1548 steven 119
                    link_delete={link_remove}
120
                    fetchCallback={fetchSavedJobs}
1 www 121
                  />
1548 steven 122
                  // <SavedJob
123
                  //   title={title}
124
                  //   employment_type={employment_type}
125
                  //   last_date_of_application={last_date_of_application}
126
                  //   link_view={link_view}
127
                  //   link_remove={link_remove}
128
                  //   onCancelApply={handleCancelApply}
129
                  //   key={index}
130
                  // />
1 www 131
                )
132
              )
133
            ) : (
134
              <p>No hay resultados</p>
135
            )}
136
          </div>
137
          {/* <!--product-feed-tab end--> */}
138
        </div>
139
      </div>
140
      {loading && (
141
        <StyledSpinnerContainer>
142
          <Spinner />
143
        </StyledSpinnerContainer>
144
      )}
145
    </section>
146
  );
147
};
148
 
149
// const mapStateToProps = (state) => ({});
150
 
151
const mapDispatchToProps = {
152
  addNotification: (notification) => addNotification(notification),
153
};
154
 
155
export default connect(null, mapDispatchToProps)(SavedJobs);