Rev 2336 | Rev 4239 | 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 { connect } from "react-redux";
import { addNotification } from "../../../redux/notification/notification.actions";
import Profile from "../../../components/Profile";
import SearchList from "../../../components/SearchList";
const InvitationsReceived = (props) => {
// redux destructuring
const { addNotification } = props;
// states
const [companies, setCompanies] = useState([]);
const [loading, setLoading] = useState(true);
// React hook form
const { register, getValues } = useForm();
let axiosThrottle = null;
useEffect(() => {
fetchCompanies();
return () => {
clearTimeout(axiosThrottle);
};
}, []);
const fetchCompanies = async (searchParam = '') => {
setLoading(true);
await axios
.get("/company/invitations-received?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 handleRequestAction = (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">
<SearchList
title="Solicitudes recibidas"
fetchCallback={fetchCompanies}
/>
<div
className="companies-list"
id="profiles-container"
style={{
position: "relative",
}}
>
{
companies.length
?
companies.map(({ image, name, link_view, link_reject, link_accept }, id) => (
<Profile
key={id}
image={image}
name={name}
link_view={link_view}
link_reject={link_reject}
link_accept={link_accept}
fetchCallback={fetchCompanies}
btnAcceptTitle='Ver Empresa'
/>
))
:
<div style={{ margin: "auto", textAlign: "center" }}>
Ningún registro coincidio con su consulta
</div>
}
{
loading
&&
<div className="spinner-container">
<Spinner />
</div>
}
{/* <!--product-feed-tab end--> */}
</div>
</div>
</section >
);
};
// const mapStateToProps = (state) => ({});
const mapDispatchToProps = {
addNotification: (notification) => addNotification(notification),
};
export default connect(null, mapDispatchToProps)(InvitationsReceived);