Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3279 Rev 3280
Línea 1... Línea 1...
1
import React, { useState } from 'react'
1
import React, { useState } from 'react'
2
import { Controller, useForm } from 'react-hook-form'
2
import { Controller, useForm } from 'react-hook-form'
3
import { useDispatch, useSelector } from 'react-redux'
3
import { useDispatch, useSelector } from 'react-redux'
Línea 4... Línea -...
4
 
-
 
5
import { axios } from '@utils'
4
 
6
import { useShareModal } from '@hooks'
5
import { useShareModal } from '@hooks'
7
import { addFeed } from '@store/feed/feed.actions'
6
import { addFeed } from '@store/feed/feed.actions'
8
import { feedTypes } from '@store/feed/feed.types'
7
import { feedTypes } from '@store/feed/feed.types'
9
import { addNotification } from '@store/notification/notification.actions'
8
import { addNotification } from '@store/notification/notification.actions'
Línea 56... Línea 55...
56
 
55
 
Línea 57... Línea 56...
57
  const toggleConfirm = () => setShowConfirm(!showConfirm)
56
  const toggleConfirm = () => setShowConfirm(!showConfirm)
58
 
57
 
59
  const onSubmit = handleSubmit(async (feed) => {
-
 
60
    try {
-
 
61
      const form = new FormData()
-
 
62
      Object.entries(feed).forEach(([key, value]) => form.append(key, value))
58
  const onSubmit = handleSubmit(async (feed) => {
63
 
-
 
64
      const response = await axios.post(postUrl, form)
-
 
65
      const { data, success } = response.data
-
 
66
 
-
 
67
      if (!success) {
-
 
68
        const errorMessage =
-
 
69
          typeof data === 'string'
-
 
70
            ? data
-
 
71
            : 'Ha ocurrido un error al publicar, inténtalo de nuevo más tarde.'
-
 
72
        throw new Error(errorMessage)
-
 
73
      }
-
 
Línea 74... Línea 59...
74
 
59
    try {
75
      const newFeed = data
60
      await dispatch(addFeed(postUrl, feed, feedSharedId))
76
 
61
 
77
      dispatch(
62
      dispatch(
78
        addNotification({
63
        addNotification({
79
          style: 'success',
64
          style: 'success',
80
          msg: 'La publicación ha sido compartida'
-
 
81
        })
65
          msg: 'Post publicado correctamente'
82
      )
66
        })
83
      dispatch(addFeed(newFeed, feedSharedId))
67
      )
84
      reset()
-
 
85
      closeModal()
68
      reset()
86
    } catch (error) {
69
      closeModal()
87
      console.error(error)
70
    } catch (error) {
Línea 88... Línea 71...
88
      dispatch(addNotification({ style: 'danger', msg: error.message }))
71
      dispatch(addNotification({ style: 'danger', msg: error.message }))