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
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'
7
 
8
const ProfileInfo = ({
9
  id,
10
  image,
11
  following,
12
  facebook,
13
  twitter,
14
  instagram,
15
  showContact,
16
  fullName,
17
  linkInmail,
18
  connectUrl,
19
  cancelUrl,
20
}) => {
21
  const [isAdded, setIsAdded] = useState(!connectUrl)
22
  const [connectionUrl, setConnectionUrl] = useState(connectUrl || cancelUrl)
23
  const [showConfirmModal, setShowConfirmModal] = useState(false)
24
 
25
  const dispatch = useDispatch()
26
  const labels = useSelector((state) => state.labels)
27
 
28
  const getProfile = () => {
29
    axios.get(window.location.href).then(({ data }) => {
30
      if (data.link_request) {
31
        return setConnectionUrl(data.link_request)
32
      }
33
 
34
      return setConnectionUrl(data.link_cancel)
35
    })
36
  }
37
 
38
  const connect = () => {
39
    axios.post(connectionUrl).then(({ data: response }) => {
40
      const { data, success } = response
41
      if (!success) {
42
        dispatch(addNotification({ style: 'danger', msg: data }))
43
        return
44
      }
45
      dispatch(addNotification({ style: 'success', msg: data }))
46
      getProfile()
47
      setIsAdded(!isAdded)
48
    })
49
  }
50
 
51
  const toggleConfirmationModal = () => setShowConfirmModal(!showConfirmModal)
52
 
53
  return (
54
    <>
55
      <div className="profile-info">
56
        <img
57
          id="user-profile-img"
58
          src={`/storage/type/user-profile/code/${id}/${
59
            image ? `filename/${image}` : ''
60
          }`}
61
          alt="profile-image"
62
        />
63
        <h3>{fullName}</h3>
64
        <div className="row">
65
          <a href={facebook} target="_blank" rel="noreferrer">
66
            <Facebook />
67
          </a>
68
          <a href={twitter} target="_blank" rel="noreferrer">
69
            <Twitter />
70
          </a>
71
          <a href={instagram} target="_blank" rel="noreferrer">
72
            <Instagram />
73
          </a>
74
        </div>
75
        <span>
76
          <b>{following}</b>
77
          <br />
78
          Seguidores
79
        </span>
80
        <div className="row ">
81
          {showContact && (
82
            <>
83
              <button
84
                className={`btn btn-${isAdded ? 'secondary' : 'primary'}`}
85
                onClick={() =>
86
                  isAdded ? toggleConfirmationModal() : connect()
87
                }
88
              >
89
                {isAdded ? labels.CANCEL : labels.ADD}
90
              </button>
91
              <a href={linkInmail} className="btn btn-tertiary">
92
                {labels.MESSAGE}
93
              </a>
94
            </>
95
          )}
96
        </div>
97
      </div>
98
      <ConfirmModal
99
        show={showConfirmModal}
100
        onClose={toggleConfirmationModal}
101
        onAccept={connect}
102
        title={labels.TITLE_CONFIRM_CONECTION}
103
        acceptLabel={labels.ACCEPT}
104
      />
105
    </>
106
  )
107
}
108
 
109
export default ProfileInfo