Rev 1518 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from "react";
import { useEffect, useState } from "react";
import { connect } from "react-redux";
import { useForm } from "react-hook-form";
import styled from "styled-components";
import {axios} from "../../../utils";
import { addNotification } from "../../../redux/notification/notification.actions";
import Spinner from "../../../shared/loading-spinner/Spinner";
import AppliedJob from "./applied-job/AppliedJob";
const StyledSpinnerContainer = styled.div`
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.4);
display: flex;
justify-content: center;
align-items: center;
z-index: 300;
`;
const AppliedJobs = (props) => {
// states
const [appliedJobs, setAppliedJobs] = useState([]);
const [loading, setLoading] = useState(true);
// redux destructuring
const { addNotification } = props;
// React hook form
const { register, getValues } = useForm();
let axiosThrottle = null;
useEffect(() => {
fetchAppliedJobs();
return () => {
clearTimeout(axiosThrottle);
};
}, []);
const handleCancelApply = (cancelLink) => {
setLoading(true);
axios
.post(cancelLink)
.then((response) => {
const resData = response.data;
(resData);
if (resData.success) {
const msg = resData.data;
addNotification({
style: "success",
msg: msg,
});
fetchAppliedJobs();
} else {
const errorMsg =
typeof resData.data === "string"
? resData.data
: "Ha ocurrido un error, Por favor intente más tarde";
addNotification({
style: "danger",
msg: errorMsg,
});
setLoading(false);
}
})
.catch((error) => {
(error);
setLoading(false);
});
};
const fetchAppliedJobs = async (searchParam='') => {
setLoading(true);
await axios
.get(
"/job/applied-jobs?search="+searchParam)
.then((response) => {
const resData = response.data;
if (resData.success) {
setAppliedJobs(resData.data);
}
});
setLoading(false);
};
const handleSearch = () => {
// (getValues());
clearTimeout(axiosThrottle);
// setLoading(true);
const searchValue = getValues("search");
axiosThrottle = setTimeout(() => {
fetchAppliedJobs(searchValue);
}, 500);
};
return (
<section className="companies-info" style={{ position: "relative" }}>
<div className="container">
<div className="company-title">
<div className="section_admin_title_buttons">
<div style={{ float: "left" }}>
<h1 className="title">Que he aplicado</h1>
</div>
</div>
</div>
<div className="company-title">
<div className="section_admin_title_buttons">
<div className="form-group">
<input
type="text"
name="search"
id="search"
className="form-control"
placeholder="Buscar"
ref={register}
onChange={handleSearch}
/>
</div>
</div>
</div>
<div
className="companies-list"
style={{
padding: "0 15px",
}}
>
<div className="row" id="profiles-container">
{appliedJobs.length > 0 ? (
appliedJobs.map(
(
{
title,
employment_type,
last_date_of_application,
link_view,
link_remove,
},
index
) => (
<AppliedJob
title={title}
employment_type={employment_type}
last_date_of_application={last_date_of_application}
link_view={link_view}
link_remove={link_remove}
onCancelApply={handleCancelApply}
key={index}
/>
)
)
) : (
<p>No hay resultados</p>
)}
</div>
{/* <!--product-feed-tab end--> */}
</div>
</div>
{loading && (
<StyledSpinnerContainer>
<Spinner />
</StyledSpinnerContainer>
)}
</section>
);
};
// const mapStateToProps = (state) => ({});
const mapDispatchToProps = {
addNotification: (notification) => addNotification(notification),
};
export default connect(null, mapDispatchToProps)(AppliedJobs);