Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3281 Rev 3282
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
 
-
 
5
import { useShareModal } from '@hooks'
6
import { useShareModal } from '@hooks'
6
import { addFeed } from '@store/feed/feed.actions'
7
import { feedTypes } from '@store/feed/feed.types'
-
 
8
import { addFeed, addFeedSuccess } from '@store/feed/feed.actions'
-
 
9
import { shareModalTypes } from '@store/share-modal/shareModal.types'
7
import { feedTypes } from '@store/feed/feed.types'
-
 
8
import { addNotification } from '@store/notification/notification.actions'
Línea 10... Línea 9...
10
import { addNotification } from '@store/notification/notification.actions'
9
import { shareModalTypes } from '@store/share-modal/shareModal.types'
11
 
10
 
12
import Form from '@components/common/form'
11
import Form from '@components/common/form'
13
import Modal from '@components/UI/modal/Modal'
12
import Modal from '@components/UI/modal/Modal'
Línea 44... Línea 43...
44
    handleSubmit,
43
    handleSubmit,
45
    reset,
44
    reset,
46
    watch
45
    watch
47
  } = useForm({
46
  } = useForm({
48
    defaultValues: {
47
    defaultValues: {
49
      posted_or_shared: modalType === shareModalTypes.SHARE ? 's' : 'p',
-
 
50
      share_width: 'p',
48
      share_width: 'p',
51
      description: ''
49
      description: ''
52
    }
50
    }
53
  })
51
  })
54
  const description = watch('description')
52
  const description = watch('description')
Línea 56... Línea 54...
56
 
54
 
Línea 57... Línea 55...
57
  const toggleConfirm = () => setShowConfirm(!showConfirm)
55
  const toggleConfirm = () => setShowConfirm(!showConfirm)
58
 
56
 
59
  const onSubmit = handleSubmit(async (feed) => {
-
 
60
    try {
57
  const onSubmit = handleSubmit(async (feed) => {
61
      const form = new FormData()
-
 
62
      Object.entries(feed).forEach(([key, value]) => form.append(key, value))
58
    try {
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
      feed.posted_or_shared = modalType === shareModalTypes.SHARE ? 's' : 'p'
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
        })
-
 
82
      )
65
          msg: 'Post publicado correctamente'
83
      dispatch(addFeedSuccess(newFeed, feedSharedId))
66
        })
84
 
67
      )
85
      reset()
68
      reset()
86
      closeModal()
69
      closeModal()