Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1158 | Rev 1600 | 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";
5
import styled from "styled-components";
1158 stevensc 6
import { axios } from "../../../utils";
1 www 7
import { addNotification } from "../../../redux/notification/notification.actions";
8
import Spinner from "../../../shared/loading-spinner/Spinner";
9
import JoinedGroup from "./joined-group/JoinedGroup";
1599 steven 10
import SearchList from "../../../components/SearchList";
11
import Profile from "../../../components/Profile";
1 www 12
 
13
const JoinedGroups = (props) => {
14
  // states
15
  const [joinedGroups, setJoinedGroups] = useState([]);
16
  const [loading, setLoading] = useState(true);
17
 
18
  // redux destructuring
19
  const { addNotification } = props;
20
 
21
  // React hook form
22
  const { register, getValues } = useForm();
23
 
24
  let axiosThrottle = null;
25
 
26
  useEffect(() => {
27
    fetchJoinedGroups();
28
    return () => {
29
      clearTimeout(axiosThrottle);
30
    };
31
  }, []);
32
 
1158 stevensc 33
  const fetchJoinedGroups = async (searchParam = '') => {
1 www 34
    setLoading(true);
35
    await axios
36
      .get(
1158 stevensc 37
        "/group/joined-groups?search=" + searchParam,
1 www 38
      )
39
      .then((response) => {
40
        const resData = response.data;
1158 stevensc 41
        (resData);
1 www 42
        if (resData.success) {
43
          setJoinedGroups(resData.data);
44
        }
45
      });
46
    setLoading(false);
47
  };
48
 
49
  const handleLeaveGroup = (link) => {
50
    setLoading(true);
51
    axios.post(link).then((response) => {
52
      const resData = response.data;
53
      if (resData.success) {
54
        addNotification({
55
          style: "success",
56
          msg: resData.data,
57
        });
58
        fetchCompanies();
59
      } else {
60
        setLoading(false);
61
        addNotification({
62
          style: "danger",
63
          msg: resData.data ?? "ha ocurrido un error",
64
        });
65
      }
66
    });
67
  };
68
 
69
  const handleSearch = () => {
70
    //  (getValues());
71
    clearTimeout(axiosThrottle);
72
    // setLoading(true);
73
    const searchValue = getValues("search");
74
    axiosThrottle = setTimeout(() => {
75
      fetchJoinedGroups(searchValue);
76
    }, 500);
77
  };
78
 
79
  return (
80
    <section className="companies-info" style={{ position: "relative" }}>
81
      <div className="container">
1599 steven 82
        <SearchList
83
          title="Grupos unidos"
84
          fetchCallback={fetchJoinedGroups}
85
        />
1 www 86
        <div className="companies-list">
87
          <div className="row" id="profiles-container">
1158 stevensc 88
            {
89
              joinedGroups.length
90
                ?
91
                joinedGroups.map(
92
                  ({ image, name, privacy, link_view, link_leave }, index) => (
1599 steven 93
                    <Profile
1158 stevensc 94
                      image={image}
95
                      name={name}
1599 steven 96
                      status={privacy}
1158 stevensc 97
                      link_view={link_view}
98
                      link_leave={link_leave}
99
                      key={index}
100
                    />
101
                  ))
102
                :
103
                <div style={{ margin: "auto", textAlign: "center" }}>
104
                  Ningún registro coincidio con su consulta
105
                </div>
106
            }
1 www 107
          </div>
108
          {/* <!--product-feed-tab end--> */}
109
        </div>
110
      </div>
1158 stevensc 111
      {
112
        loading &&
1 www 113
        <div className="spinner-container">
114
          <Spinner />
115
        </div>
1158 stevensc 116
      }
1 www 117
    </section>
118
  );
119
};
120
 
121
// const mapStateToProps = (state) => ({});
122
 
123
const mapDispatchToProps = {
124
  addNotification: (notification) => addNotification(notification),
125
};
126
 
127
export default connect(null, mapDispatchToProps)(JoinedGroups);