Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2326 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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