Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2888 | Rev 2910 | 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">
2890 stevensc 51
      <div className="sd-title d-flex align-items-center justify-content-between">
52
        <h3>Conecta con:</h3>
1 www 53
        {
54
          !error && (
2890 stevensc 55
            <a href="/connection/people-you-may-know" target="_blank">
56
              Ver más
57
            </a>
1 www 58
          )
59
        }
2890 stevensc 60
      </div>
61
      <div className={styles.suggestionList}>
62
        {peopleYouMayKnow.length ? (
63
          <React.Fragment>
64
            {error ? (
65
              <div className="suggestion-usd"> Ha ocurrido un error :( </div>
66
            ) : (
67
              peopleYouMayKnow.map(({ id, image, link_cancel, link_request, name, profile, relation }) => (
68
                <div className={styles.user} key={id}>
69
                  <div className="w-100 d-flex align-items-center" style={{ gap: '.5rem' }}>
70
                    <a href={profile} target="_blank">
71
                      <img src={image} alt={`${name} profile image`} />
72
                    </a>
73
                    <h4>{name}</h4>
74
                  </div>
75
                  <div className="w-100 d-flex align-items-center justify-content-center" style={{ gap: '.5rem' }}>
76
                    {
77
                      link_request
78
                      &&
79
                      <button
80
                        className="btn btn-primary"
81
                        onClick={() => handleConnect(link_request)}
82
                      >
83
                        Conectar
84
                      </button>
85
                    }
86
                    {
87
                      link_cancel
88
                      &&
89
                      <button
90
                        className="btn btn-secondary"
91
                        onClick={() => handleConnect(link_cancel)}
92
                      >
93
                        Cancelar
94
                      </button>
95
                    }
96
                  </div>
97
                </div>
98
              ))
99
            )}
100
 
101
          </React.Fragment>
102
        ) : (
103
          <div className="view-more">Sin sugerencias</div>
104
        )}
105
      </div>
2885 stevensc 106
    </div >
1 www 107
  );
108
};
109
 
110
export default PeopleYouMayKnow;