Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3156 | Rev 3432 | 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'
3075 stevensc 8
import colors from '@styles/colors'
1847 stevensc 9
 
2902 stevensc 10
import Widget from '@components/UI/Widget'
11
import Cover from '@components/UI/cover/Cover'
12
import ConfirmModal from '@components/modals/ConfirmModal'
13
import ProfileModal from './ProfileModal'
3287 stevensc 14
import Avatar from '@components/common/avatar'
2909 stevensc 15
import Row from '@components/common/Row'
1847 stevensc 16
 
17
const ProfileCard = ({
2905 stevensc 18
  cover,
19
  facebook,
20
  following,
21
  formatted_address: formattedAddress,
2902 stevensc 22
  full_name: fullName,
23
  image,
2905 stevensc 24
  instagram,
25
  link_cancel: linkCancel,
26
  link_inmail: linkInmail,
27
  link_request: linkRequest,
2902 stevensc 28
  overview,
2905 stevensc 29
  request_connection: requestConnection,
30
  show_contact: showContact,
31
  sizes,
32
  total_connections: totalConnections,
1847 stevensc 33
  twitter,
2905 stevensc 34
  user_experiences: userExperiences = [],
2902 stevensc 35
  view_following: viewFollowing,
3032 stevensc 36
  view_total_connections: viewTotalConnections,
37
  edit
1847 stevensc 38
}) => {
39
  const [isAdded, setIsAdded] = useState(false)
40
  const [connectionUrl, setConnectionUrl] = useState('')
41
  const [modalToShow, setModalToShow] = useState(null)
42
  const [settedOverview, setSettedOverview] = useState('')
43
  const [isModalShow, setIsModalShow] = 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
  return (
2902 stevensc 103
    <Widget>
3032 stevensc 104
      <Cover cover={cover} edit={edit} />
3047 stevensc 105
 
2906 stevensc 106
      <Widget.Body>
2911 stevensc 107
        <Avatar
108
          src={image}
109
          alt={fullName}
3075 stevensc 110
          badgeStyles={{
111
            mt: { xs: '-50px', lg: '-75px' }
112
          }}
2911 stevensc 113
          styles={{
114
            width: { xs: '100px', lg: '150px' },
115
            height: { xs: '100px', lg: '150px' },
3075 stevensc 116
            border: `1px solid ${colors.border.primary}`
2911 stevensc 117
          }}
3032 stevensc 118
          edit={edit}
2911 stevensc 119
        />
2906 stevensc 120
 
2902 stevensc 121
        <Typography variant='h2'>{fullName}</Typography>
122
        <Typography>{parse(settedOverview)}</Typography>
123
 
2909 stevensc 124
        <Row>
2902 stevensc 125
          <Typography>{formattedAddress}</Typography>
2917 stevensc 126
          <Typography variant='overline'> - </Typography>
127
          <Typography variant='overline' onClick={() => setModalToShow('info')}>
2902 stevensc 128
            {labels.personal_info}
2909 stevensc 129
          </Typography>
130
        </Row>
2902 stevensc 131
 
2909 stevensc 132
        <Row>
2912 stevensc 133
          {viewTotalConnections ? (
2902 stevensc 134
            <Link to='/connection/my-connections'>
2917 stevensc 135
              <Typography variant='overline'>
2913 stevensc 136
                {`${totalConnections} conexiones`}
2911 stevensc 137
              </Typography>
2902 stevensc 138
            </Link>
2912 stevensc 139
          ) : null}
140
          {viewFollowing ? (
2902 stevensc 141
            <Link onClick={(e) => e.preventDefault()}>
2917 stevensc 142
              <Typography variant='overline'>
2913 stevensc 143
                {`${following} siguiendo`}
2911 stevensc 144
              </Typography>
2902 stevensc 145
            </Link>
2912 stevensc 146
          ) : null}
2909 stevensc 147
        </Row>
2902 stevensc 148
 
2909 stevensc 149
        <Row>
150
          {connectionUrl && isAdded && (
3156 stevensc 151
            <Button color='primary' onClick={() => displayModal()}>
2909 stevensc 152
              {labels.cancel}
153
            </Button>
154
          )}
155
          {connectionUrl && !isAdded && (
3156 stevensc 156
            <Button color='primary' onClick={connect}>
2909 stevensc 157
              {labels.connect}
158
            </Button>
159
          )}
160
          {showContact && (
3156 stevensc 161
            <Button to={linkInmail} LinkComponent={Link} color='secondary'>
2909 stevensc 162
              {labels.message}
163
            </Button>
164
          )}
165
        </Row>
2902 stevensc 166
      </Widget.Body>
2909 stevensc 167
      {/*  {isEdit && (
168
        <>
169
          <OverviewModal
170
            isOpen={modalToShow === 'overview'}
171
            overview={settedOverview}
172
            id={profileId}
173
            closeModal={() => closeModal()}
174
            onComplete={(newOverview) => setSettedOverview(newOverview)}
175
          />
176
        </>
177
      )} */}
1847 stevensc 178
 
2902 stevensc 179
      <ProfileModal
1847 stevensc 180
        show={modalToShow === 'info'}
181
        closeModal={() => closeModal()}
182
        fullName={fullName}
183
        facebook={facebook}
184
        twitter={twitter}
185
        instagram={instagram}
186
        following={following}
187
        formatted_address={formattedAddress}
188
        overview={overview}
189
        total_connections={totalConnections}
2902 stevensc 190
        // follower={follower}
1847 stevensc 191
      />
192
      <ConfirmModal
193
        show={isModalShow}
194
        onClose={() => setIsModalShow(false)}
195
        onAccept={() => connect()}
196
      />
2902 stevensc 197
    </Widget>
1847 stevensc 198
  )
199
}
200
 
201
export default ProfileCard