Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 7211 Rev 7212
Línea 1... Línea 1...
1
import React, { useEffect } from 'react'
1
import React, { useEffect, useRef, useState } from 'react'
2
import { axios } from '../../utils'
2
import { axios } from '../../utils'
3
import { useLocation } from 'react-router-dom'
3
import { useLocation } from 'react-router-dom'
4
import { addNotification } from '../../redux/notification/notification.actions'
4
import { addNotification } from '../../redux/notification/notification.actions'
5
import { useDispatch } from 'react-redux'
5
import { useDispatch, useSelector } from 'react-redux'
-
 
6
import { Col, Container, Row } from 'react-bootstrap'
-
 
7
import QuestionCard from '../../components/my-coach/QuestionCard'
-
 
8
import ConfirmModal from '../../components/modals/ConfirmModal'
Línea 6... Línea 9...
6
 
9
 
-
 
10
const MyCoachViewPage = () => {
-
 
11
  const [question, setQuestion] = useState({})
-
 
12
  const [modalShow, setModalShow] = useState(null)
-
 
13
  const addUrl = useRef('')
-
 
14
  const actionUrl = useRef('')
7
const MyCoachViewPage = () => {
15
  const labels = useSelector(({ intl }) => intl.labels)
8
  const dispatch = useDispatch()
16
  const dispatch = useDispatch()
Línea 9... Línea 17...
9
  const { pathname } = useLocation()
17
  const { pathname } = useLocation()
10
 
18
 
Línea 26... Línea 34...
26
 
34
 
27
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
35
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
28
          return
36
          return
Línea -... Línea 37...
-
 
37
        }
29
        }
38
 
30
 
39
        addUrl.current = data.link_answers_add
31
        console.log(data)
40
        setQuestion(data)
32
      })
41
      })
33
      .catch((error) => {
42
      .catch((error) => {
34
        dispatch(
43
        dispatch(
Línea 39... Línea 48...
39
        )
48
        )
40
        throw new Error(error)
49
        throw new Error(error)
41
      })
50
      })
42
  }
51
  }
Línea -... Línea 52...
-
 
52
 
-
 
53
  const confirmDelete = () => {
-
 
54
    axios
-
 
55
      .post(actionUrl.current)
-
 
56
      .then((response) => {
-
 
57
        const { data, success } = response.data
-
 
58
 
-
 
59
        if (!success) {
-
 
60
          const errorMessage =
-
 
61
            typeof data === 'string'
-
 
62
              ? data
-
 
63
              : 'Ha ocurrido un error, por favor intente más tarde.'
-
 
64
 
-
 
65
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
-
 
66
          return
-
 
67
        }
-
 
68
 
-
 
69
        dispatch(addNotification({ style: 'success', msg: data }))
-
 
70
        closeModal()
-
 
71
      })
-
 
72
      .catch((error) => {
-
 
73
        dispatch(
-
 
74
          addNotification({
-
 
75
            style: 'danger',
-
 
76
            msg: 'Ha ocurrido un error, por favor intente más tarde.',
-
 
77
          })
-
 
78
        )
-
 
79
        throw new Error(error)
-
 
80
      })
-
 
81
  }
-
 
82
 
-
 
83
  const deleteQuestion = (url) => {
-
 
84
    actionUrl.current = url
-
 
85
    setModalShow('delete')
-
 
86
  }
-
 
87
 
-
 
88
  const editQuestion = (url) => {
-
 
89
    actionUrl.current = url
-
 
90
    setModalShow('edit')
-
 
91
  }
-
 
92
 
-
 
93
  const closeModal = () => {
-
 
94
    actionUrl.current = ''
-
 
95
    setModalShow(null)
-
 
96
  }
43
 
97
 
44
  useEffect(() => {
98
  useEffect(() => {
45
    getQuestion()
99
    getQuestion()
Línea -... Línea 100...
-
 
100
  }, [])
-
 
101
 
-
 
102
  return (
46
  }, [])
103
    <>
-
 
104
      <Container as="section" className="companies-info">
-
 
105
        <div className="company-title">
-
 
106
          <h1 className="title mx-auto">{labels.my_coach}</h1>
-
 
107
        </div>
-
 
108
 
-
 
109
        <Row>
-
 
110
          <Col md="8" className="mx-auto">
-
 
111
            <QuestionCard
-
 
112
              key={question.uuid}
-
 
113
              onEdit={editQuestion}
-
 
114
              onDelete={deleteQuestion}
-
 
115
              {...question}
-
 
116
            />
-
 
117
          </Col>
-
 
118
        </Row>
-
 
119
      </Container>
-
 
120
      <ConfirmModal
-
 
121
        show={modalShow === 'delete'}
-
 
122
        onClose={closeModal}
-
 
123
        onAccept={confirmDelete}
-
 
124
      />
47
 
125
    </>
Línea 48... Línea 126...
48
  return <div>MyCoachViewPage</div>
126
  )