Proyectos de Subversion LeadersLinked - SPA

Rev

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