Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3063 | Rev 5158 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3063 Rev 5156
Línea -... Línea 1...
-
 
1
/* eslint-disable camelcase */
1
import React from "react";
2
/* eslint-disable react/prop-types */
2
import { useEffect, useState } from "react";
3
import React, { useEffect, useState } from 'react'
3
import { connect } from "react-redux";
4
import { connect } from 'react-redux'
4
import styled from "styled-components";
-
 
5
import { axios } from "../../../utils";
5
import { debounce } from '../../../utils'
6
import { addNotification } from "../../../redux/notification/notification.actions";
6
import { addNotification } from '../../../redux/notification/notification.actions'
-
 
7
import { searchEntities } from '../../../services/search'
7
import Spinner from "../../../shared/loading-spinner/Spinner";
8
import Spinner from '../../../shared/loading-spinner/Spinner'
8
import SearchList from "../../../components/SearchList";
9
import SearchList from '../../../components/SearchList'
9
import Card from "../../../components/Profile";
10
import Card from '../../../components/Profile'
10
 
-
 
11
const StyledSpinnerContainer = styled.div`
11
import EmptySection from '../../../shared/empty-section/EmptySection'
12
  position: absolute;
-
 
13
  left: 0;
-
 
14
  top: 0;
-
 
15
  width: 100%;
-
 
16
  height: 100%;
-
 
17
  background: rgba(255, 255, 255, 0.4);
12
import TitleSection from '../../../components/TitleSection'
18
  display: flex;
-
 
19
  justify-content: center;
-
 
20
  align-items: center;
-
 
21
  z-index: 300;
-
 
22
`;
-
 
23
 
13
 
24
const SavedJobs = () => {
14
const SavedJobs = ({ addNotification }) => {
25
  // states
-
 
26
  const [savedJobs, setSavedJobs] = useState([]);
15
  const [savedJobs, setSavedJobs] = useState([])
27
  const [loading, setLoading] = useState(true);
16
  const [loading, setLoading] = useState(true)
28
 
-
 
29
  let axiosThrottle = null;
-
 
Línea 30... Línea 17...
30
 
17
 
31
  useEffect(() => {
18
  useEffect(() => {
32
    fetchSavedJobs();
-
 
33
    return () => {
-
 
34
      clearTimeout(axiosThrottle);
-
 
35
    };
19
    getSavedJobs()
36
  }, []);
20
  }, [])
37
 
21
 
38
  const handleCancelApply = (cancelLink) => {
22
  const getSavedJobs = async (searchValue = '') => {
39
    setLoading(true);
-
 
40
    axios
-
 
41
      .post(cancelLink)
-
 
42
      .then((response) => {
23
    setLoading(true)
43
        const resData = response.data;
-
 
-
 
24
    const response = await searchEntities('job/saved-jobs', searchValue)
44
        (resData);
25
 
45
        if (resData.success) {
-
 
46
          fetchSavedJobs();
-
 
47
        } else {
-
 
48
          const errorMsg =
-
 
49
            typeof resData.data === "string"
-
 
50
              ? resData.data
26
    if (!response.success) {
51
              : "Ha ocurrido un error, Por favor intente más tarde";
-
 
52
          addNotification({
-
 
53
            style: "danger",
-
 
54
            msg: errorMsg,
-
 
55
          });
27
      addNotification({ style: 'danger', msg: response.data })
56
          setLoading(false);
28
      setLoading(false)
57
        }
29
      return
-
 
30
    }
58
      })
31
 
59
      .catch((error) => {
-
 
60
        (error);
32
    setSavedJobs(response.data)
61
        setLoading(false);
-
 
62
      });
33
    setLoading(false)
63
  };
34
  }
64
 
35
 
65
  const fetchSavedJobs = async (searchParam = '') => {
-
 
66
    setLoading(true);
-
 
67
    await axios.get("/job/saved-jobs?search=" + searchParam)
-
 
68
      .then((response) => {
-
 
69
        const resData = response.data;
-
 
70
        if (resData.success) {
-
 
71
          console.log(resData.data)
-
 
72
          setSavedJobs(resData.data);
-
 
73
        }
-
 
74
      });
-
 
75
    setLoading(false);
-
 
Línea 76... Línea 36...
76
  };
36
  const handleSearch = debounce((value) => getSavedJobs(value), 500)
77
 
37
 
78
  return (
38
  return (
79
    <section className="companies-info" style={{ position: "relative" }}>
39
    <section className="companies-info">
80
      <div className="container">
40
      <TitleSection title={`${LABELs.JOBS} ${LABELS.JOBS_SAVED.toLowerCase()}`} />
81
        <SearchList
41
      <SearchList onChange={handleSearch} />
82
          title="Empleos guardados"
-
 
83
          fetchCallback={fetchSavedJobs}
42
      <div className="companies-list">
84
        />
43
        {loading && <Spinner />}
85
        <div className="companies-list" style={{ padding: "0 15px", }}>
-
 
86
          {savedJobs.length > 0
-
 
87
            ?
-
 
88
            savedJobs.map(
44
        {(!loading && Boolean(!savedJobs.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
89
              ({
-
 
90
                employment_type,
-
 
91
                id,
-
 
92
                image,
-
 
93
                link_remove,
-
 
94
                link_view,
-
 
95
                title,
45
        {(!loading && Boolean(savedJobs.length)) &&
96
              }) =>
46
          savedJobs.map(({ employment_type, id, image, link_remove, link_view, title }) =>
97
                <Card
47
            <Card
98
                  key={id}
48
              key={id}
99
                  image={image}
49
              image={image}
100
                  name={title}
50
              name={title}
101
                  status={employment_type}
51
              status={employment_type}
102
                  link_view={link_view}
52
              link_view={link_view}
103
                  link_delete={link_remove}
53
              link_delete={link_remove}
104
                  fetchCallback={fetchSavedJobs}
54
              fetchCallback={getSavedJobs}
105
                  btnAcceptTitle='Ver Empleo'
-
 
106
                  btnCancelTitle='Eliminar'
55
              btnAcceptTitle={LABELS.VIEW_JOB}
107
                />
-
 
108
            )
56
              btnCancelTitle={LABELS.DELETE}
109
            : <p>No hay resultados</p>
-
 
110
          }
57
            />
111
        </div>
-
 
112
      </div>
-
 
113
      {loading && (
-
 
114
        <StyledSpinnerContainer>
-
 
115
          <Spinner />
-
 
116
        </StyledSpinnerContainer>
58
          )}
117
      )}
59
      </div>
118
    </section>
60
    </section>
119
  );
-
 
120
};
-
 
Línea 121... Línea 61...
121
 
61
  )
122
// const mapStateToProps = (state) => ({});
62
}
123
 
63
 
Línea 124... Línea 64...
124
const mapDispatchToProps = {
64
const mapDispatchToProps = {