Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2614 | Rev 2917 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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