Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2887 | Rev 2890 | 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, { useEffect, useState } from "react";
2885 stevensc 2
import { useDispatch } from "react-redux";
3
import { addNotification } from "../../../redux/notification/notification.actions";
2232 stevensc 4
import { axios } from "../../../utils";
1 www 5
 
6
import styles from "./peopleYouMayKnow.module.scss";
7
 
8
const PeopleYouMayKnow = () => {
9
  // states
10
  const [peopleYouMayKnow, setPeopleYouMayKnow] = useState([]);
11
  const [error, setError] = useState("");
2885 stevensc 12
  const dispatch = useDispatch()
1 www 13
 
2885 stevensc 14
  const handleConnect = (url) => {
15
    axios.post(url)
16
      .then(({ data }) => {
17
        if (!data.success) {
18
          return dispatch(addNotification({
19
            style: 'danger',
20
            msg: typeof data.data === 'string'
21
              ? data.data
22
              : 'Ha ocurrido un error'
23
          }))
24
        }
25
 
2888 stevensc 26
        dispatch(addNotification({
2885 stevensc 27
          style: 'success',
28
          msg: data.data
29
        }))
2888 stevensc 30
        return getSuggestion()
2885 stevensc 31
      })
32
  }
33
 
2888 stevensc 34
  const getSuggestion = (url) => {
35
    axios.get(`/helpers/people-you-may-know`).then((response) => {
36
      const resData = response.data;
37
      if (resData.success) {
38
        setPeopleYouMayKnow(resData.data);
39
      } else {
40
        // alert error
41
      }
42
    });
43
  }
44
 
45
  useEffect(() => {
46
    getSuggestion()
47
  }, []);
48
 
1 www 49
  return (
2883 stevensc 50
    <div className={styles.peopleYouMayKnow} id="suggestions-list-people-you-may-know">
1 www 51
      <div className="sd-title">
52
        <h3>Personas que puede conocer</h3>
53
      </div>
54
      <>
55
        <div className={styles.suggestionList}>
56
          {peopleYouMayKnow.length ? (
57
            <React.Fragment>
58
              {error ? (
59
                <div className="suggestion-usd"> Ha ocurrido un error :( </div>
60
              ) : (
2883 stevensc 61
                peopleYouMayKnow.map(({ id, image, link_cancel, link_request, name, profile, relation }) => (
1 www 62
                  <div className={styles.user} key={id}>
2888 stevensc 63
                    <div className="w-100 d-flex align-items-center" style={{ gap: '.5rem' }}>
1 www 64
                      <a href={profile} target="_blank">
2885 stevensc 65
                        <img src={image} alt={`${name} profile image`} />
1 www 66
                      </a>
2885 stevensc 67
                      <h4>{name}</h4>
1 www 68
                    </div>
2888 stevensc 69
                    <div className="w-100 d-flex align-items-center justify-content-center" style={{ gap: '.5rem' }}>
2885 stevensc 70
                      {
71
                        link_request
72
                        &&
73
                        <button
74
                          className="btn btn-primary"
75
                          onClick={() => handleConnect(link_request)}
76
                        >
77
                          Conectar
78
                        </button>
79
                      }
80
                      {
81
                        link_cancel
82
                        &&
83
                        <button
84
                          className="btn btn-secondary"
85
                          onClick={() => handleConnect(link_cancel)}
86
                        >
87
                          Cancelar
88
                        </button>
89
                      }
90
                    </div>
1 www 91
                  </div>
92
                ))
93
              )}
2232 stevensc 94
 
1 www 95
            </React.Fragment>
96
          ) : (
97
            <div className="view-more">Sin sugerencias</div>
98
          )}
99
        </div>
100
        {
101
          !error && (
102
            <div className={styles.viewMore}>
2232 stevensc 103
              <a href="/connection/people-you-may-know" target="_blank">
104
                <button
105
                  className="btn btn-primary"
106
                  type="button"
107
                  style={{ padding: '2px 10px' }}
108
                >
109
                  Ver más
110
                </button>
111
              </a>
1 www 112
            </div>
113
          )
114
        }
115
      </>
2885 stevensc 116
    </div >
1 www 117
  );
118
};
119
 
120
export default PeopleYouMayKnow;