Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
5473 stevensc 1
import React, { useState } from 'react'
2
import { axios } from '../../utils'
3
import { addNotification } from '../../redux/notification/notification.actions'
4
import { useDispatch, useSelector } from 'react-redux'
5
import { Facebook, Instagram, Twitter } from '@mui/icons-material'
6
import ConfirmModal from '../../shared/confirm-modal/ConfirmModal'
5566 stevensc 7
import SocialNetworks from '../../shared/social-networks/SocialNetwors'
5473 stevensc 8
 
9
const ProfileInfo = ({
10
  id,
11
  image,
12
  following,
5566 stevensc 13
  follower,
5473 stevensc 14
  facebook,
15
  twitter,
16
  instagram,
17
  showContact,
18
  fullName,
19
  linkInmail,
20
  connectUrl,
21
  cancelUrl,
5566 stevensc 22
  isEdit,
5473 stevensc 23
}) => {
24
  const [isAdded, setIsAdded] = useState(!connectUrl)
25
  const [connectionUrl, setConnectionUrl] = useState(connectUrl || cancelUrl)
26
  const [showConfirmModal, setShowConfirmModal] = useState(false)
27
 
28
  const dispatch = useDispatch()
29
  const labels = useSelector((state) => state.labels)
30
 
31
  const getProfile = () => {
32
    axios.get(window.location.href).then(({ data }) => {
33
      if (data.link_request) {
34
        return setConnectionUrl(data.link_request)
35
      }
36
 
37
      return setConnectionUrl(data.link_cancel)
38
    })
39
  }
40
 
41
  const connect = () => {
42
    axios.post(connectionUrl).then(({ data: response }) => {
43
      const { data, success } = response
44
      if (!success) {
45
        dispatch(addNotification({ style: 'danger', msg: data }))
46
        return
47
      }
48
      dispatch(addNotification({ style: 'success', msg: data }))
49
      getProfile()
50
      setIsAdded(!isAdded)
51
    })
52
  }
53
 
54
  const toggleConfirmationModal = () => setShowConfirmModal(!showConfirmModal)
55
 
56
  return (
57
    <>
58
      <div className="profile-info">
59
        <img
60
          id="user-profile-img"
61
          src={`/storage/type/user-profile/code/${id}/${
62
            image ? `filename/${image}` : ''
63
          }`}
64
          alt="profile-image"
65
        />
66
        <h3>{fullName}</h3>
67
        <div className="row">
5566 stevensc 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
          )}
5473 stevensc 83
        </div>
5566 stevensc 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>
5473 stevensc 100
        <div className="row ">
101
          {showContact && (
102
            <>
103
              <button
104
                className={`btn btn-${isAdded ? 'secondary' : 'primary'}`}
105
                onClick={() =>
106
                  isAdded ? toggleConfirmationModal() : connect()
107
                }
108
              >
109
                {isAdded ? labels.CANCEL : labels.ADD}
110
              </button>
111
              <a href={linkInmail} className="btn btn-tertiary">
112
                {labels.MESSAGE}
113
              </a>
114
            </>
115
          )}
116
        </div>
5566 stevensc 117
        {isEdit && (
118
          <SocialNetworks
119
            type="profile"
120
            profileId={id}
121
            facebook={facebook}
122
            instagram={instagram}
123
            twitter={twitter}
124
          />
125
        )}
5473 stevensc 126
      </div>
127
      <ConfirmModal
128
        show={showConfirmModal}
129
        onClose={toggleConfirmationModal}
130
        onAccept={connect}
131
        title={labels.TITLE_CONFIRM_CONECTION}
132
        acceptLabel={labels.ACCEPT}
133
      />
134
    </>
135
  )
136
}
137
 
138
export default ProfileInfo