Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 7220 Rev 7221
Línea 20... Línea 20...
20
 
20
 
21
const MyCoachViewPage = () => {
21
const MyCoachViewPage = () => {
22
  const [question, setQuestion] = useState({})
22
  const [question, setQuestion] = useState({})
23
  const [answers, setAnswers] = useState([])
23
  const [answers, setAnswers] = useState([])
-
 
24
  const [modalShow, setModalShow] = useState(null)
24
  const [modalShow, setModalShow] = useState(null)
25
  const [currentAnswer, setCurrentAnswer] = useState('')
25
  const addUrl = useRef('')
26
  const addUrl = useRef('')
26
  const actionUrl = useRef('')
27
  const actionUrl = useRef('')
27
  const labels = useSelector(({ intl }) => intl.labels)
28
  const labels = useSelector(({ intl }) => intl.labels)
28
  const dispatch = useDispatch()
29
  const dispatch = useDispatch()
Línea 92... Línea 93...
92
        )
93
        )
93
        throw new Error(error)
94
        throw new Error(error)
94
      })
95
      })
95
  }
96
  }
Línea -... Línea 97...
-
 
97
 
-
 
98
  const confirmDeleteAnswer = () => {
-
 
99
    axios
-
 
100
      .post(actionUrl.current)
-
 
101
      .then((response) => {
-
 
102
        const { data, success } = response.data
-
 
103
 
-
 
104
        if (!success) {
-
 
105
          const errorMessage =
-
 
106
            typeof data === 'string'
-
 
107
              ? data
-
 
108
              : 'Ha ocurrido un error, por favor intente más tarde.'
-
 
109
 
-
 
110
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
-
 
111
          return
-
 
112
        }
-
 
113
 
-
 
114
        setQuestion((prevQuestion) => ({
-
 
115
          ...prevQuestion,
-
 
116
          comments: data.total_comments,
-
 
117
          answers: data.total_answers,
-
 
118
          reactions: data.total_reactions,
-
 
119
        }))
-
 
120
        closeModal()
-
 
121
      })
-
 
122
      .catch((error) => {
-
 
123
        dispatch(
-
 
124
          addNotification({
-
 
125
            style: 'danger',
-
 
126
            msg: 'Ha ocurrido un error, por favor intente más tarde.',
-
 
127
          })
-
 
128
        )
-
 
129
        throw new Error(error)
-
 
130
      })
-
 
131
  }
96
 
132
 
97
  const deleteQuestion = (url) => {
133
  const deleteQuestion = (url) => {
98
    actionUrl.current = url
134
    actionUrl.current = url
99
    setModalShow('delete')
135
    setModalShow('delete')
Línea 105... Línea 141...
105
  }
141
  }
Línea 106... Línea 142...
106
 
142
 
107
  const closeModal = () => {
143
  const closeModal = () => {
108
    actionUrl.current = ''
144
    actionUrl.current = ''
-
 
145
    setModalShow(null)
109
    setModalShow(null)
146
    setCurrentAnswer('')
Línea 110... Línea 147...
110
  }
147
  }
111
 
148
 
112
  const addAnswer = () => {
149
  const addAnswer = () => {
Línea -... Línea 150...
-
 
150
    setModalShow('addAnswer')
-
 
151
  }
-
 
152
 
-
 
153
  const editAnswer = (url, text) => {
-
 
154
    setModalShow('editAnswer')
-
 
155
    actionUrl.current = url
-
 
156
    setCurrentAnswer(text)
-
 
157
  }
-
 
158
 
-
 
159
  const deleteAnswer = (url) => {
-
 
160
    setModalShow('deleteAnswer')
113
    setModalShow('addAnswer')
161
    actionUrl.current = url
114
  }
162
  }
115
 
163
 
116
  const onAddAnswer = ({ answers, item }) => {
164
  const onAddAnswer = ({ answers, item }) => {
Línea -... Línea 165...
-
 
165
    setQuestion((prevQuestion) => ({ ...prevQuestion, answers }))
-
 
166
    setAnswers((prevAnswers) => [item, ...prevAnswers])
-
 
167
  }
-
 
168
 
-
 
169
  const onEditAnswer = ({ description }) => {
-
 
170
    const newAnswers = answers.map((answer) => {
-
 
171
      if (answer.link_edit === actionUrl.current) {
-
 
172
        return { ...answer, text: description }
-
 
173
      }
-
 
174
 
-
 
175
      return answer
-
 
176
    })
117
    setQuestion((prevQuestion) => ({ ...prevQuestion, answers }))
177
 
118
    setAnswers((prevAnswers) => [item, ...prevAnswers])
178
    setAnswers(newAnswers)
119
  }
179
  }
Línea 120... Línea 180...
120
 
180
 
Línea 167... Línea 227...
167
              onDelete={deleteQuestion}
227
              onDelete={deleteQuestion}
168
              onReply={addAnswer}
228
              onReply={addAnswer}
169
              {...question}
229
              {...question}
170
            />
230
            />
171
            {answers.map((answer) => (
231
            {answers.map((answer) => (
-
 
232
              <AnswerCard
172
              <AnswerCard key={answer.unique} {...answer} />
233
                key={answer.unique}
-
 
234
                {...answer}
-
 
235
                onEdit={editAnswer}
-
 
236
                onDelete={deleteAnswer}
-
 
237
              />
173
            ))}
238
            ))}
174
          </StyledSection>
239
          </StyledSection>
175
        </Row>
240
        </Row>
176
      </Container>
241
      </Container>
177
      <AnswerModal
242
      <AnswerModal
178
        url={addUrl.current}
243
        url={addUrl.current}
-
 
244
        show={['addAnswer', 'editAnswer'].includes(modalShow)}
-
 
245
        currentAnswer={currentAnswer}
-
 
246
        onClose={closeModal}
-
 
247
        onComplete={currentAnswer ? onEditAnswer : onAddAnswer}
-
 
248
      />
-
 
249
      <ConfirmModal
179
        show={modalShow === 'addAnswer'}
250
        show={modalShow === 'deleteAnswer'}
180
        onClose={closeModal}
251
        onClose={closeModal}
181
        onComplete={onAddAnswer}
252
        onAccept={confirmDeleteAnswer}
182
      />
253
      />
183
      <ConfirmModal
254
      <ConfirmModal
184
        show={modalShow === 'delete'}
255
        show={modalShow === 'delete'}
185
        onClose={closeModal}
256
        onClose={closeModal}
186
        onAccept={confirmDelete}
257
        onAccept={confirmDelete}