Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2304 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
import React from "react";
2
import { useEffect, useState } from "react";
3
import { connect } from "react-redux";
4
import { useForm } from "react-hook-form";
1102 stevensc 5
import { axios } from "../../../utils";
1 www 6
import { addNotification } from "../../../redux/notification/notification.actions";
7
import Spinner from "../../../shared/loading-spinner/Spinner";
8
import RequestTemplate from './invitationTemplate/InvitationTemplate'
1605 steven 9
import SearchList from "../../../components/SearchList";
10
import Profile from "../../../components/Profile";
1 www 11
 
12
const InvitationsReceived = (props) => {
13
  // states
14
  const [invitations, setInvitations] = useState([]);
15
  const [loading, setLoading] = useState(true);
16
 
17
  // redux destructuring
18
  const { addNotification } = props;
19
 
20
  // React hook form
21
  const { register, getValues } = useForm();
22
 
23
  let axiosThrottle = null;
24
 
25
  useEffect(() => {
26
    fetchInvitationsReceived();
27
    return () => {
28
      clearTimeout(axiosThrottle);
29
    };
30
  }, []);
31
 
1102 stevensc 32
  const fetchInvitationsReceived = async (searchParam = '') => {
1 www 33
    setLoading(true);
34
    await axios
35
      .get(
1102 stevensc 36
        "/group/invitations-received?search=" + searchParam)
1 www 37
      .then((response) => {
38
        const resData = response.data;
1102 stevensc 39
        (resData);
1 www 40
        if (resData.success) {
41
          setInvitations(resData.data);
42
        }
43
      });
44
    setLoading(false);
45
  };
46
 
47
  const handleResponse = (link) => {
48
    setLoading(true);
1102 stevensc 49
    axios.post(link)
50
      .then((response) => {
51
        const resData = response.data;
52
        if (resData.success) {
53
          addNotification({
54
            style: "success",
55
            msg: resData.data,
56
          });
57
          fetchInvitationsReceived();
58
        } else {
59
          setLoading(false);
60
          addNotification({
61
            style: "danger",
62
            msg: resData.data ?? "ha ocurrido un error",
63
          });
64
        }
65
      });
1 www 66
  };
67
 
68
  const handleSearch = () => {
69
    //  (getValues());
70
    clearTimeout(axiosThrottle);
71
    // setLoading(true);
72
    const searchValue = getValues("search");
73
    axiosThrottle = setTimeout(() => {
74
      fetchInvitationsReceived(searchValue);
75
    }, 500);
76
  };
77
 
78
  return (
79
    <section className="companies-info" style={{ position: "relative" }}>
80
      <div className="container">
1605 steven 81
        <SearchList
82
          title="Invitaciones Recibidas"
83
          fetchCallback={fetchInvitationsReceived}
84
        />
2304 stevensc 85
        <div className="companies-list" id="profiles-container">
86
          {
87
            invitations.length
88
              ?
89
              invitations.map((invitation, index) => (
90
                <Profile
91
                  {...invitation}
92
                  key={index}
93
                  fetchCallback={fetchInvitationsReceived}
2326 stevensc 94
                  btnAcceptTitle='Ver grupo'
2304 stevensc 95
                />
96
              ))
97
              :
98
              <div style={{ margin: "auto", textAlign: "center" }}>
99
                Ningún registro coincidio con su consulta
100
              </div>
101
          }
1 www 102
          {/* <!--product-feed-tab end--> */}
103
        </div>
104
      </div>
105
      {loading && (
106
        <div className="spinner-container">
107
          <Spinner />
108
        </div>
109
      )}
110
    </section>
111
  );
112
};
113
 
114
const mapDispatchToProps = {
115
  addNotification: (notification) => addNotification(notification),
116
};
117
 
118
export default connect(null, mapDispatchToProps)(InvitationsReceived);