Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3181 Rev 3183
Línea 1... Línea 1...
1
import React 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...
4
 
4
 
5
import { axios } from '@utils'
5
import { axios } from '@utils'
Línea 21... Línea 21...
21
  [shareModalTypes.FILE]: 'solo documentos PDF',
21
  [shareModalTypes.FILE]: 'solo documentos PDF',
22
  [shareModalTypes.VIDEO]: 'Video de extensión mp4, mpeg, webm, mov'
22
  [shareModalTypes.VIDEO]: 'Video de extensión mp4, mpeg, webm, mov'
23
}
23
}
Línea 24... Línea 24...
24
 
24
 
-
 
25
const ShareModal = () => {
25
const ShareModal = () => {
26
  const [showConfirm, setShowConfirm] = useState(false)
26
  const labels = useSelector(({ intl }) => intl.labels)
27
  const labels = useSelector(({ intl }) => intl.labels)
Línea 27... Línea -...
27
  const dispatch = useDispatch()
-
 
28
 
-
 
29
  const {
-
 
30
    show,
-
 
31
    showConfirm,
-
 
32
    postUrl,
-
 
33
    modalType,
28
  const dispatch = useDispatch()
34
    feedType,
-
 
35
    feedSharedId,
-
 
36
    onConfirm,
-
 
37
    onReject,
29
 
Línea 38... Línea 30...
38
    close
30
  const { show, modalType, feedType, feedSharedId, postUrl, closeModal } =
39
  } = useShareModal()
31
    useShareModal()
40
 
32
 
41
  const {
33
  const {
42
    control,
34
    control,
-
 
35
    formState: { errors, isSubmitting },
43
    formState: { errors, isSubmitting },
36
    handleSubmit,
44
    handleSubmit,
37
    reset,
45
    reset
38
    watch
46
  } = useForm({
39
  } = useForm({
47
    defaultValues: {
40
    defaultValues: {
48
      posted_or_shared: modalType === shareModalTypes.SHARE ? 's' : 'p',
41
      posted_or_shared: modalType === shareModalTypes.SHARE ? 's' : 'p',
49
      share_width: 'p',
42
      share_width: 'p',
-
 
43
      description: ''
-
 
44
    }
-
 
45
  })
-
 
46
  const description = watch('description')
Línea 50... Línea 47...
50
      description: ''
47
  const file = watch('file')
51
    }
48
 
52
  })
49
  const toggleConfirm = () => setShowConfirm(!showConfirm)
53
 
50
 
Línea 75... Línea 72...
75
          msg: 'La publicación ha sido compartida'
72
          msg: 'La publicación ha sido compartida'
76
        })
73
        })
77
      )
74
      )
78
      dispatch(addFeed(newFeed, feedSharedId))
75
      dispatch(addFeed(newFeed, feedSharedId))
79
      reset()
76
      reset()
80
      close()
77
      closeModal()
81
    } catch (error) {
78
    } catch (error) {
82
      console.error(error)
79
      console.error(error)
83
      dispatch(addNotification({ style: 'danger', msg: error.message }))
80
      dispatch(addNotification({ style: 'danger', msg: error.message }))
84
    }
81
    }
85
  })
82
  })
Línea -... Línea 83...
-
 
83
 
-
 
84
  const handleClose = () => {
-
 
85
    if (description || file) return toggleConfirm()
-
 
86
    closeModal()
-
 
87
  }
-
 
88
 
-
 
89
  const handleConfirm = () => {
-
 
90
    reset()
-
 
91
    closeModal()
-
 
92
  }
86
 
93
 
87
  return (
94
  return (
88
    <>
95
    <>
89
      <Modal
96
      <Modal
90
        show={show}
97
        show={show}
91
        title={labels.share_a_post}
98
        title={labels.share_a_post}
92
        labelAccept={labels.send}
99
        labelAccept={labels.send}
93
        labelReject={labels.cancel}
100
        labelReject={labels.cancel}
94
        loading={isSubmitting}
101
        loading={isSubmitting}
95
        onAccept={onSubmit}
102
        onAccept={onSubmit}
96
        onClose={close}
103
        onClose={handleClose}
97
      >
104
      >
98
        {feedType === feedTypes.DASHBOARD && (
105
        {feedType === feedTypes.DASHBOARD && (
99
          <Select
106
          <Select
100
            name='shared_with'
107
            name='shared_with'
Línea 134... Línea 141...
134
          <FormErrorFeedback>{errors.file.message}</FormErrorFeedback>
141
          <FormErrorFeedback>{errors.file.message}</FormErrorFeedback>
135
        )}
142
        )}
136
      </Modal>
143
      </Modal>
137
      <ConfirmModal
144
      <ConfirmModal
138
        show={showConfirm}
145
        show={showConfirm}
139
        onClose={onReject}
146
        onAccept={handleConfirm}
140
        onAccept={onConfirm}
147
        onClose={toggleConfirm}
141
        message='¿No se ha compartido tu publicación , desea descartarlo?'
148
        message='¿Estás seguro de que quieres salir sin publicar tu post?'
142
      />
149
      />
143
    </>
150
    </>
144
  )
151
  )
145
}
152
}