Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Ir a la última revisión | | Ultima modificación | Ver Log |

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