Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3694 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React, { useState } from 'react';
2
import { Link } from 'react-router-dom';
3
import { useDispatch, useSelector } from 'react-redux';
4
import Facebook from '@mui/icons-material/Facebook';
5
import Instagram from '@mui/icons-material/Instagram';
6
import Twitter from '@mui/icons-material/Twitter';
7
 
8
import { axios } from '../utils';
9
import { addNotification } from '../redux/notification/notification.actions';
10
 
11
import ConfirmModal from '../../shared/confirm-modal/ConfirmModal';
12
import SocialNetworks from '../../shared/social-networks/SocialNetwors';
13
 
14
const ProfileInfo = ({
15
  id,
16
  image,
17
  following,
18
  follower,
19
  facebook,
20
  twitter,
21
  instagram,
22
  showContact,
23
  fullName,
24
  linkInmail,
25
  connectUrl,
26
  cancelUrl,
27
  isEdit
28
}) => {
29
  const [isAdded, setIsAdded] = useState(!connectUrl);
30
  const [connectionUrl, setConnectionUrl] = useState(connectUrl || cancelUrl);
31
  const [showConfirmModal, setShowConfirmModal] = useState(false);
32
  const labels = useSelector(({ intl }) => intl.labels);
33
  const dispatch = useDispatch();
34
 
35
  const getProfile = () => {
36
    axios.get(window.location.href).then(({ data }) => {
37
      if (data.link_request) {
38
        return setConnectionUrl(data.link_request);
39
      }
40
 
41
      return setConnectionUrl(data.link_cancel);
42
    });
43
  };
44
 
45
  const connect = () => {
46
    axios.post(connectionUrl).then((response) => {
47
      const { data, success } = response.data;
48
      if (!success) {
49
        dispatch(addNotification({ style: 'danger', msg: data }));
50
        return;
51
      }
52
      dispatch(addNotification({ style: 'success', msg: data }));
53
      getProfile();
54
      setIsAdded(!isAdded);
55
    });
56
  };
57
 
58
  const toggleConfirmationModal = () => {
59
    setShowConfirmModal(!showConfirmModal);
60
  };
61
 
62
  return (
63
    <>
64
      <div className='profile-info'>
65
        <img id='user-profile-img' src={image} alt='profile-image' />
66
        <h3>{fullName}</h3>
67
        <div className='row'>
68
          {facebook && (
69
            <a href={facebook} target='_blank' rel='noreferrer'>
70
              <Facebook />
71
            </a>
72
          )}
73
          {twitter && (
74
            <a href={twitter} target='_blank' rel='noreferrer'>
75
              <Twitter />
76
            </a>
77
          )}
78
          {instagram && (
79
            <a href={instagram} target='_blank' rel='noreferrer'>
80
              <Instagram />
81
            </a>
82
          )}
83
        </div>
84
        <div className='row'>
85
          {following && (
86
            <span>
87
              <b>{following}</b>
88
              <br />
89
              Siguiendo
90
            </span>
91
          )}
92
          {follower && (
93
            <span>
94
              <b>{follower}</b>
95
              <br />
96
              Seguidores
97
            </span>
98
          )}
99
        </div>
100
        <div className='row '>
101
          {showContact && (
102
            <>
103
              <button
104
                className={`btn btn-${isAdded ? 'secondary' : 'primary'}`}
105
                onClick={() => (isAdded ? toggleConfirmationModal() : connect())}
106
              >
107
                {isAdded ? labels.cancel : labels.add}
108
              </button>
109
              <Link to={linkInmail} className='btn btn-tertiary'>
110
                {labels.message}
111
              </Link>
112
            </>
113
          )}
114
        </div>
115
        {isEdit && (
116
          <SocialNetworks
117
            type='profile'
118
            profileId={id}
119
            facebook={facebook}
120
            instagram={instagram}
121
            twitter={twitter}
122
          />
123
        )}
124
      </div>
125
      <ConfirmModal
126
        show={showConfirmModal}
127
        onClose={toggleConfirmationModal}
128
        onAccept={connect}
129
        title={labels.title_confirm_connection}
130
        acceptLabel={labels.accept}
131
      />
132
    </>
133
  );
134
};
135
 
136
export default ProfileInfo;