Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2917 | Rev 3047 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1847 stevensc 1
import React, { useState, useEffect } from 'react'
2
import { Link, useLocation } from 'react-router-dom'
3
import { useDispatch, useSelector } from 'react-redux'
2912 stevensc 4
import { Button, Typography } from '@mui/material'
1847 stevensc 5
 
2902 stevensc 6
import { axios, parse } from '@utils'
7
import { addNotification } from '@store/notification/notification.actions'
1847 stevensc 8
 
2902 stevensc 9
import Widget from '@components/UI/Widget'
10
import Cover from '@components/UI/cover/Cover'
11
import ConfirmModal from '@components/modals/ConfirmModal'
12
import ProfileModal from './ProfileModal'
2909 stevensc 13
import Avatar from '@components/common/Avatar'
14
import Row from '@components/common/Row'
1847 stevensc 15
 
16
const ProfileCard = ({
2905 stevensc 17
  cover,
18
  facebook,
19
  following,
20
  formatted_address: formattedAddress,
2902 stevensc 21
  full_name: fullName,
22
  image,
2905 stevensc 23
  instagram,
24
  link_cancel: linkCancel,
25
  link_inmail: linkInmail,
26
  link_request: linkRequest,
2902 stevensc 27
  overview,
2905 stevensc 28
  request_connection: requestConnection,
29
  show_contact: showContact,
30
  sizes,
31
  total_connections: totalConnections,
1847 stevensc 32
  twitter,
2905 stevensc 33
  user_experiences: userExperiences = [],
2902 stevensc 34
  view_following: viewFollowing,
3032 stevensc 35
  view_total_connections: viewTotalConnections,
36
  edit
1847 stevensc 37
}) => {
38
  const [isAdded, setIsAdded] = useState(false)
39
  const [connectionUrl, setConnectionUrl] = useState('')
40
  const [modalToShow, setModalToShow] = useState(null)
41
  const [settedOverview, setSettedOverview] = useState('')
42
  const [isModalShow, setIsModalShow] = useState(false)
43
  const [isEdit, setIsEdit] = useState(false)
44
  const labels = useSelector(({ intl }) => intl.labels)
45
  const { pathname } = useLocation()
46
  const dispatch = useDispatch()
47
 
48
  const displayModal = () => {
49
    setIsModalShow(!isModalShow)
50
  }
51
 
52
  const getProfileData = async () => {
53
    try {
54
      const { data: response } = await axios.get(pathname)
55
      const { link_request, link_cancel } = response
56
 
57
      if (link_request) {
58
        setConnectionUrl(link_request)
59
        return
60
      }
61
 
62
      setConnectionUrl(link_cancel)
63
    } catch (err) {
64
      dispatch(addNotification({ style: 'danger', msg: err.message }))
65
    }
66
  }
67
 
68
  const connect = async () => {
69
    try {
70
      const { data: response } = await axios.post(connectionUrl)
71
      const { data, success } = response
72
 
73
      if (!success) {
74
        return dispatch(addNotification({ style: 'danger', msg: data }))
75
      }
76
 
77
      if (success && isModalShow) {
78
        displayModal()
79
      }
80
 
81
      await getProfileData()
82
      dispatch(addNotification({ style: 'success', msg: data }))
83
      setIsAdded(!isAdded)
84
    } catch (error) {
85
      dispatch(addNotification({ style: 'danger', msg: `Error: ${error}` }))
86
    }
87
  }
88
 
89
  const closeModal = () => {
90
    setModalToShow(null)
91
  }
92
 
93
  useEffect(() => {
2902 stevensc 94
    setIsAdded(!requestConnection)
1847 stevensc 95
    setSettedOverview(overview)
2909 stevensc 96
  }, [requestConnection, overview])
1847 stevensc 97
 
98
  useEffect(() => {
2902 stevensc 99
    linkRequest ? setConnectionUrl(linkRequest) : setConnectionUrl(linkCancel)
100
  }, [linkRequest, linkCancel])
1847 stevensc 101
 
102
  useEffect(() => {
103
    setIsEdit(pathname.includes('edit'))
104
  }, [pathname])
105
 
106
  return (
2902 stevensc 107
    <Widget>
3032 stevensc 108
      <Cover cover={cover} edit={edit} />
2906 stevensc 109
      <Widget.Body>
2911 stevensc 110
        <Avatar
111
          src={image}
112
          alt={fullName}
113
          styles={{
114
            width: { xs: '100px', lg: '150px' },
115
            height: { xs: '100px', lg: '150px' },
116
            mt: { xs: '-50px', lg: '-75px' },
117
            border: '4px solid #fff',
118
            backgroundColor: '#c9ced4',
119
            cursor: isEdit ? 'pointer' : 'default'
120
          }}
3032 stevensc 121
          edit={edit}
2911 stevensc 122
        />
2906 stevensc 123
 
2902 stevensc 124
        <Typography variant='h2'>{fullName}</Typography>
125
        <Typography>{parse(settedOverview)}</Typography>
126
 
2909 stevensc 127
        <Row>
2902 stevensc 128
          <Typography>{formattedAddress}</Typography>
2917 stevensc 129
          <Typography variant='overline'> - </Typography>
130
          <Typography variant='overline' onClick={() => setModalToShow('info')}>
2902 stevensc 131
            {labels.personal_info}
2909 stevensc 132
          </Typography>
133
        </Row>
2902 stevensc 134
 
2909 stevensc 135
        <Row>
2912 stevensc 136
          {viewTotalConnections ? (
2902 stevensc 137
            <Link to='/connection/my-connections'>
2917 stevensc 138
              <Typography variant='overline'>
2913 stevensc 139
                {`${totalConnections} conexiones`}
2911 stevensc 140
              </Typography>
2902 stevensc 141
            </Link>
2912 stevensc 142
          ) : null}
143
          {viewFollowing ? (
2902 stevensc 144
            <Link onClick={(e) => e.preventDefault()}>
2917 stevensc 145
              <Typography variant='overline'>
2913 stevensc 146
                {`${following} siguiendo`}
2911 stevensc 147
              </Typography>
2902 stevensc 148
            </Link>
2912 stevensc 149
          ) : null}
2909 stevensc 150
        </Row>
2902 stevensc 151
 
2909 stevensc 152
        <Row>
153
          {connectionUrl && isAdded && (
154
            <Button variant='primary' onClick={() => displayModal()}>
155
              {labels.cancel}
156
            </Button>
157
          )}
158
          {connectionUrl && !isAdded && (
159
            <Button variant='primary' onClick={connect}>
160
              {labels.connect}
161
            </Button>
162
          )}
163
          {showContact && (
164
            <Button to={linkInmail} LinkComponent={Link} variant='secondary'>
165
              {labels.message}
166
            </Button>
167
          )}
168
        </Row>
2902 stevensc 169
      </Widget.Body>
2909 stevensc 170
      {/*  {isEdit && (
171
        <>
172
          <OverviewModal
173
            isOpen={modalToShow === 'overview'}
174
            overview={settedOverview}
175
            id={profileId}
176
            closeModal={() => closeModal()}
177
            onComplete={(newOverview) => setSettedOverview(newOverview)}
178
          />
179
        </>
180
      )} */}
1847 stevensc 181
 
2902 stevensc 182
      <ProfileModal
1847 stevensc 183
        show={modalToShow === 'info'}
184
        closeModal={() => closeModal()}
185
        fullName={fullName}
186
        facebook={facebook}
187
        twitter={twitter}
188
        instagram={instagram}
189
        following={following}
190
        formatted_address={formattedAddress}
191
        overview={overview}
192
        total_connections={totalConnections}
2902 stevensc 193
        // follower={follower}
1847 stevensc 194
      />
195
      <ConfirmModal
196
        show={isModalShow}
197
        onClose={() => setIsModalShow(false)}
198
        onAccept={() => connect()}
199
      />
2902 stevensc 200
    </Widget>
1847 stevensc 201
  )
202
}
203
 
204
export default ProfileCard