Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
676 stevensc 1
import React, { useRef, useEffect } from 'react'
5 stevensc 2
import { axios } from '../../../utils'
674 stevensc 3
import { Avatar } from '@mui/material'
677 stevensc 4
import { useHistory } from 'react-router-dom'
5
import { useDispatch } from 'react-redux'
6
import { addNotification } from '../../../redux/notification/notification.actions'
5 stevensc 7
import MapOutlinedIcon from '@mui/icons-material/MapOutlined'
8
import ShareOutlinedIcon from '@mui/icons-material/ShareOutlined'
674 stevensc 9
import VisibilityOutlinedIcon from '@mui/icons-material/VisibilityOutlined'
10
import styled from 'styled-components'
11
 
12
import Paraphrase from '../../UI/Paraphrase'
1507 stevensc 13
import WidgetWrapper from '../WidgetLayout'
676 stevensc 14
import Options from '../../UI/Option'
5 stevensc 15
 
1507 stevensc 16
const StyledProfileContainer = styled(WidgetWrapper)`
676 stevensc 17
  padding: 10px;
18
  text-align: center;
19
`
20
 
674 stevensc 21
const StyledProfileStatus = styled.div`
22
  display: flex;
23
  align-items: center;
24
  justify-content: space-around;
25
`
26
 
5 stevensc 27
export default function ProfileInfo({
28
  image,
29
  name,
30
  description,
31
  visits,
32
  country,
33
  connections,
34
  linkAdmin,
671 stevensc 35
  linkImpersonate
5 stevensc 36
}) {
676 stevensc 37
  const options = useRef([
38
    {
39
      label: 'Configuración de la cuenta',
40
      action: () => history.push('/account-settings')
41
    },
42
    {
43
      label: 'Política de privacidad',
44
      action: () => history.push('/privacy-policy')
45
    },
46
    { label: 'Política de cookies', action: () => history.push('/cookies') },
47
    { label: 'Cerrar sesión', action: () => history.push('/signout') }
48
  ])
49
  const history = useHistory()
677 stevensc 50
  const dispatch = useDispatch()
676 stevensc 51
 
677 stevensc 52
  const getAdminUrl = () => {
53
    axios
54
      .get('/backend/signin-admin')
55
      .then(({ data: responseData }) => {
56
        const { data, success } = responseData
57
 
58
        if (!success) {
59
          throw new Error(data)
60
        }
61
 
62
        window.open(data)
63
      })
64
      .catch((err) => {
65
        dispatch(addNotification({ style: 'danger', msg: err.message }))
66
      })
5 stevensc 67
  }
68
 
676 stevensc 69
  useEffect(() => {
70
    if (linkAdmin)
71
      options.current.unshift({ label: 'Administración', action: getAdminUrl })
72
 
73
    if (linkImpersonate)
74
      options.current.unshift({
75
        label: 'Personificar otro usuario',
76
        action: () => history.push('/impersonate')
77
      })
78
  }, [])
79
 
5 stevensc 80
  return (
676 stevensc 81
    <StyledProfileContainer>
672 stevensc 82
      <Avatar
83
        src={image}
84
        alt={`${name} profile-image`}
85
        sx={{ margin: '0 auto', width: 100, height: 100 }}
86
      />
5 stevensc 87
      <h2>{name}</h2>
674 stevensc 88
      <Paraphrase>{description}</Paraphrase>
89
 
90
      <StyledProfileStatus>
91
        <span>
5 stevensc 92
          <VisibilityOutlinedIcon />
674 stevensc 93
          {visits}
94
        </span>
95
        <span>
5 stevensc 96
          <MapOutlinedIcon />
674 stevensc 97
          {country}
98
        </span>
99
        <span>
5 stevensc 100
          <ShareOutlinedIcon />
674 stevensc 101
          {connections}
102
        </span>
103
      </StyledProfileStatus>
104
 
677 stevensc 105
      <Options options={options.current} top='10px' right='10px' />
676 stevensc 106
    </StyledProfileContainer>
5 stevensc 107
  )
108
}