Rev 1548 | 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 SavedJob from "./saved-job/SavedJob";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 SavedJobs = (props) => {// statesconst [savedJobs, setSavedJobs] = useState([]);const [loading, setLoading] = useState(true);// redux destructuringconst { addNotification } = props;// React hook formconst { register, getValues } = useForm();let axiosThrottle = null;useEffect(() => {fetchSavedJobs();return () => {clearTimeout(axiosThrottle);};}, []);const handleCancelApply = (cancelLink) => {setLoading(true);axios.post(cancelLink).then((response) => {const resData = response.data;(resData);if (resData.success) {fetchSavedJobs();} 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 fetchSavedJobs = async (searchParam='') => {setLoading(true);await axios.get("/job/saved-jobs?search="+searchParam).then((response) => {const resData = response.data;if (resData.success) {setSavedJobs(resData.data);}});setLoading(false);};const handleSearch = () => {// (getValues());clearTimeout(axiosThrottle);// setLoading(true);const searchValue = getValues("search");axiosThrottle = setTimeout(() => {fetchSavedJobs(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 guardado</h1></div></div></div><div className="company-title"><div className="section_admin_title_buttons"><div className="form-group"><inputtype="text"name="search"id="search"className="form-control"placeholder="Buscar"ref={register}onChange={handleSearch}/></div></div></div><divclassName="companies-list"style={{padding: "0 15px",}}><div className="row" id="profiles-container">{savedJobs.length > 0 ? (savedJobs.map(({title,employment_type,last_date_of_application,link_view,link_remove,},index) => (<SavedJobtitle={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)(SavedJobs);