Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
7065 stevensc 1
import React, { useEffect, useState } from 'react'
7062 stevensc 2
import { useParams } from 'react-router-dom'
3
import { axios } from '../../utils'
7065 stevensc 4
import { Card, CardContent, CardMedia, Typography } from '@mui/material'
5
import styled from 'styled-components'
6
import { Container } from 'react-bootstrap'
7
import { useDispatch, useSelector } from 'react-redux'
8
import { addNotification } from '../../redux/notification/notification.actions'
7062 stevensc 9
 
7065 stevensc 10
const KnowledgeCard = styled(Card)`
11
  background-color: var(--bg-color);
12
  border-radius: var(--border-radius);
13
  overflow: hidden;
14
  height: fit-content;
15
`
16
 
7062 stevensc 17
const KnowledgeViewPage = () => {
7065 stevensc 18
  const [knowledge, setKnowledge] = useState({
19
    category: '',
20
    title: '',
21
    description: '',
22
    link: null,
23
    image: '',
24
    attachment: '',
25
    reaction: '',
26
    routeComments: '',
27
    routeCommentAdd: '',
28
    routeSaveReaction: '',
29
    routeDeleteReaction: '',
30
  })
31
  const labels = useSelector(({ intl }) => intl.labels)
32
  const dispatch = useDispatch()
7062 stevensc 33
  const { uuid } = useParams()
34
 
35
  useEffect(() => {
36
    axios
37
      .get(`/knowledge-area/view/${uuid}`, {
38
        headers: {
39
          'Content-Type': 'application/json',
40
        },
41
      })
7065 stevensc 42
      .then((response) => {
43
        const { data, success } = response.data
44
        if (!success) {
45
          const errorMessage =
46
            typeof data === 'string' ? data : labels.error_there_was_an_error
47
 
48
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
49
          return
50
        }
51
 
52
        setKnowledge(data)
53
      })
54
      .catch((err) => {
55
        dispatch(
56
          addNotification({
57
            style: 'danger',
58
            msg: labels.error_there_was_an_error,
59
          })
60
        )
61
        throw new Error(err)
62
      })
7062 stevensc 63
  }, [uuid])
64
 
7065 stevensc 65
  return (
66
    <Container as="section">
67
      <KnowledgeCard>
68
        <CardMedia
69
          component="img"
70
          height="194"
71
          image={knowledge.image}
72
          alt={`${knowledge.title} image`}
73
        />
74
        <CardContent>
75
          <Typography variant="h5">{knowledge.title}</Typography>
76
          <Typography variant="subtitle1" color="text.secondary">
77
            {knowledge.category}
78
          </Typography>
79
          <Typography variant="body2" color="text.secondary">
80
            {knowledge.description}
81
          </Typography>
82
        </CardContent>
83
      </KnowledgeCard>
84
    </Container>
85
  )
7062 stevensc 86
}
87
 
88
export default KnowledgeViewPage