Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 7062 Rev 7065
Línea 1... Línea 1...
1
import React, { useEffect } from 'react'
1
import React, { useEffect, useState } from 'react'
2
import { useParams } from 'react-router-dom'
2
import { useParams } from 'react-router-dom'
3
import { axios } from '../../utils'
3
import { axios } from '../../utils'
-
 
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'
-
 
9
 
-
 
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
`
Línea 4... Línea 16...
4
 
16
 
-
 
17
const KnowledgeViewPage = () => {
-
 
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)
5
const KnowledgeViewPage = () => {
32
  const dispatch = useDispatch()
Línea 6... Línea 33...
6
  const { uuid } = useParams()
33
  const { uuid } = useParams()
7
 
34
 
8
  useEffect(() => {
35
  useEffect(() => {
9
    axios
36
    axios
10
      .get(`/knowledge-area/view/${uuid}`, {
37
      .get(`/knowledge-area/view/${uuid}`, {
11
        headers: {
38
        headers: {
12
          'Content-Type': 'application/json',
39
          'Content-Type': 'application/json',
-
 
40
        },
13
        },
41
      })
-
 
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
        )
14
      })
61
        throw new Error(err)
Línea -... Línea 62...
-
 
62
      })
-
 
63
  }, [uuid])
-
 
64
 
-
 
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
        />
15
      .then((response) => console.log(response.data))
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>
16
  }, [uuid])
83
      </KnowledgeCard>
Línea 17... Línea 84...
17
 
84
    </Container>