Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Rev 1548 | 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";
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 SavedJobs = (props) => {
26
  // states
27
  const [savedJobs, setSavedJobs] = 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
    fetchSavedJobs();
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
          fetchSavedJobs();
54
        } else {
55
          const errorMsg =
56
            typeof resData.data === "string"
57
              ? resData.data
58
              : "Ha ocurrido un error, Por favor intente más tarde";
59
          addNotification({
60
            style: "danger",
61
            msg: errorMsg,
62
          });
63
          setLoading(false);
64
        }
65
      })
66
      .catch((error) => {
67
         (error);
68
        setLoading(false);
69
      });
70
  };
71
 
72
  const fetchSavedJobs = async (searchParam='') => {
73
    setLoading(true);
74
    await axios
75
      .get(
76
        "/job/saved-jobs?search="+searchParam)
77
      .then((response) => {
78
        const resData = response.data;
79
        if (resData.success) {
80
          setSavedJobs(resData.data);
81
        }
82
      });
83
    setLoading(false);
84
  };
85
 
86
  const handleSearch = () => {
87
    //  (getValues());
88
    clearTimeout(axiosThrottle);
89
    // setLoading(true);
90
    const searchValue = getValues("search");
91
    axiosThrottle = setTimeout(() => {
92
      fetchSavedJobs(searchValue);
93
    }, 500);
94
  };
95
 
96
  return (
97
    <section className="companies-info" style={{ position: "relative" }}>
98
      <div className="container">
1547 steven 99
        <SearchList
100
          title="Que he guardado"
101
          fetchCallback={fetchSavedJobs}
102
        />
1 www 103
        <div
104
          className="companies-list"
105
          style={{
106
            padding: "0 15px",
107
          }}
108
        >
109
          <div className="row" id="profiles-container">
110
            {savedJobs.length > 0 ? (
111
              savedJobs.map(
112
                (
113
                  {
114
                    title,
115
                    employment_type,
116
                    last_date_of_application,
117
                    link_view,
118
                    link_remove,
119
                  },
120
                  index
121
                ) => (
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
                  />
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);