Rev 1 | Rev 1593 | 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 { useForm } from "react-hook-form";import {axios} from "../../../utils";import Spinner from "../../../shared/loading-spinner/Spinner";import CompanyTemplate from "./companyTemplate/CompanyTemplate";import { connect } from "react-redux";import { addNotification } from "../../../redux/notification/notification.actions";import SearchList from "../../../components/SearchList";const IWorkWith = (props) => {// redux destructuringconst { addNotification } = props;// statesconst [companies, setCompanies] = useState([]);const [loading, setLoading] = useState(true);// React hook formconst { register, getValues } = useForm();let axiosThrottle = null;useEffect(() => {fetchCompanies();return () => {clearTimeout(axiosThrottle);};}, []);const fetchCompanies = async (searchParam='') => {setLoading(true);await axios.get("/company/i-work-with?search="+searchParam).then((response) => {const resData = response.data;if (resData.success) {setCompanies(resData.data);}});setLoading(false);};const handleSearch = () => {// (getValues());clearTimeout(axiosThrottle);// setLoading(true);const searchValue = getValues("search");axiosThrottle = setTimeout(() => {fetchCompanies(searchValue);}, 500);};const handleLeaveCompany = (link) => {setLoading(true);axios.post(link).then((response) => {const resData = response.data;if (resData.success) {addNotification({style: "success",msg: resData.data,});fetchCompanies();} else {setLoading(false);addNotification({style: "danger",msg: resData.data ?? "ha ocurrido un error",});}});};return (<section className="companies-info"><div className="container"><SearchListtitle="Empresas donde trabajo"fetchCallback={fetchCompanies}/><div className="companies-list"><divclassName="row"id="profiles-container"style={{position: "relative",}}>{companies.length > 0 ? (companies.map((company, id) => (<CompanyTemplatecompany={company}key={id}onLeave={handleLeaveCompany}/>))) : (<div style={{ margin: "auto", textAlign: "center" }}>Ningún registro coincidio con su consulta</div>)}{loading && (<div className="spinner-container"><Spinner /></div>)}</div>{/* <!--product-feed-tab end--> */}</div></div></section>);};// const mapStateToProps = (state) => ({});const mapDispatchToProps = {addNotification: (notification) => addNotification(notification),};export default connect(null, mapDispatchToProps)(IWorkWith);