Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3173 Rev 3174
Línea 1... Línea 1...
1
import React, { useEffect, useState } from 'react'
1
import React, { useEffect, useState } from 'react'
2
import { useForm } from 'react-hook-form'
2
import { 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 '@app/utils'
6
import { addFeed } from '@store/feed/feed.actions'
-
 
7
import { feedTypes } from '@store/feed/feed.types'
-
 
8
import { addNotification } from '@store/notification/notification.actions'
6
import { feedTypes } from '@app/redux/feed/feed.types'
9
import { shareModalTypes } from '@store/share-modal/shareModal.types'
7
import {
10
import {
8
  closeShareModal,
11
  closeShareModal,
9
  openShareModal
12
  openShareModal
10
} from '@app/redux/share-modal/shareModal.actions'
-
 
11
import { addNotification } from '@app/redux/notification/notification.actions'
-
 
12
import { addFeed } from '@app/redux/feed/feed.actions'
-
 
Línea 13... Línea -...
13
import { shareModalTypes } from '@app/redux/share-modal/shareModal.types'
-
 
14
 
-
 
15
import Ckeditor from '@components/UI/Ckeditor'
13
} from '@store/share-modal/shareModal.actions'
-
 
14
 
-
 
15
import Modal from '@components/UI/modal/Modal'
-
 
16
import Form from '@components/common/form'
16
import FormErrorFeedback from '@components/UI/form/FormErrorFeedback'
17
import Select from '@components/UI/inputs/Select'
-
 
18
import Ckeditor from '@components/UI/Ckeditor'
17
import Modal from '@components/UI/modal/Modal'
19
import DropzoneComponent from '@components/dropzone/DropzoneComponent'
18
import DropzoneComponent from '@components/dropzone/DropzoneComponent'
-
 
19
import ConfirmModal from './ConfirmModal'
-
 
Línea 20... Línea 20...
20
import Select from '@components/UI/inputs/Select'
20
import FormErrorFeedback from '@components/UI/form/FormErrorFeedback'
21
import Form from '@components/common/form'
21
import ConfirmModal from './ConfirmModal'
22
 
22
 
23
const recomendationText = {
23
const recomendationText = {
24
  [shareModalTypes.IMAGE]: 'Tamaño recomendado: 720x720',
24
  [shareModalTypes.IMAGE]: 'Tamaño recomendado: 720x720',
Línea 25... Línea 25...
25
  [shareModalTypes.FILE]: 'solo documentos PDF',
25
  [shareModalTypes.FILE]: 'solo documentos PDF',
26
  [shareModalTypes.VIDEO]: 'Video de extensión mp4, mpeg, webm, mov'
26
  [shareModalTypes.VIDEO]: 'Video de extensión mp4, mpeg, webm, mov'
27
}
27
}
-
 
28
 
-
 
29
const ShareModal = ({ setModalType }) => {
28
 
30
  const [showConfirmModal, setShowConfirmModal] = useState(false)
29
const ShareModal = ({ setModalType }) => {
31
  const labels = useSelector(({ intl }) => intl.labels)
30
  const [showConfirmModal, setShowConfirmModal] = useState(false)
-
 
Línea 31... Línea 32...
31
  const labels = useSelector(({ intl }) => intl.labels)
32
  const dispatch = useDispatch()
32
  const { isOpen, postUrl, modalType, lastModalType, feedType, feedSharedId } =
33
 
33
    useSelector((state) => state.shareModal)
34
  const { isOpen, postUrl, modalType, lastModalType, feedType, feedSharedId } =
34
  const dispatch = useDispatch()
35
    useSelector((state) => state.shareModal)
Línea 48... Línea 49...
48
    defaultValues: {
49
    defaultValues: {
49
      description: '',
50
      description: '',
50
      share_width: 'p'
51
      share_width: 'p'
51
    }
52
    }
52
  })
53
  })
53
  const watchedDescription = watch('description')
-
 
Línea 54... Línea 54...
54
 
54
 
Línea 55... Línea 55...
55
  const toggleConfirmModal = () => setShowConfirmModal(!showConfirmModal)
55
  const toggleConfirmModal = () => setShowConfirmModal(!showConfirmModal)
56
 
56
 
Línea 68... Línea 68...
68
    dispatch(closeShareModal())
68
    dispatch(closeShareModal())
69
    dispatch(openShareModal(postUrl, lastModalType, feedType))
69
    dispatch(openShareModal(postUrl, lastModalType, feedType))
70
  }
70
  }
Línea 71... Línea 71...
71
 
71
 
72
  const onSubmit = handleSubmit((data) => {
72
  const onSubmit = handleSubmit((data) => {
73
    const currentFormData = new FormData()
73
    const form = new FormData()
74
 
74
    form.append(
75
    Object.entries(data).forEach(([key, value]) =>
75
      'posted_or_shared',
76
      currentFormData.append(key, value)
76
      modalType === shareModalTypes.SHARE ? 's' : 'p'
-
 
77
    )
Línea 77... Línea 78...
77
    )
78
    Object.entries(data).forEach(([key, value]) => form.append(key, value))
78
 
79
 
79
    axios
80
    axios
80
      .post(postUrl, currentFormData)
81
      .post(postUrl, form)
Línea 81... Línea 82...
81
      .then((response) => {
82
      .then((response) => {
82
        const { data, success } = response.data
83
        const { data, success } = response.data
Línea 132... Línea 133...
132
    clearErrors()
133
    clearErrors()
133
    dispatch(closeShareModal())
134
    dispatch(closeShareModal())
134
  }
135
  }
Línea 135... Línea 136...
135
 
136
 
136
  useEffect(() => {
-
 
137
    const postedOrShared = modalType === shareModalTypes.SHARE ? 's' : 'p'
-
 
138
 
-
 
139
    register('posted_or_shared')
-
 
140
    setValue('posted_or_shared', postedOrShared)
-
 
141
 
137
  useEffect(() => {
142
    if (
138
    if (
143
      modalType !== shareModalTypes.POST &&
139
      modalType !== shareModalTypes.POST &&
144
      modalType !== shareModalTypes.SHARE
140
      modalType !== shareModalTypes.SHARE
145
    ) {
141
    ) {
Línea 156... Línea 152...
156
        toggleConfirmModal()
152
        toggleConfirmModal()
157
      }
153
      }
158
    }
154
    }
159
  }, [modalType])
155
  }, [modalType])
Línea 160... Línea -...
160
 
-
 
161
  console.log(isSubmitting)
-
 
162
 
156
 
163
  return (
157
  return (
164
    <>
158
    <>
165
      <Modal
159
      <Modal
166
        show={isOpen}
160
        show={isOpen}
Línea 170... Línea 164...
170
        onClose={onClose}
164
        onClose={onClose}
171
        loading={isSubmitting}
165
        loading={isSubmitting}
172
        formId='share-form'
166
        formId='share-form'
173
      >
167
      >
174
        <Form onSubmit={onSubmit} id='share-form'>
168
        <Form onSubmit={onSubmit} id='share-form'>
175
          {feedType === feedTypes.DASHBOARD ? (
169
          {feedType === feedTypes.DASHBOARD && (
176
            <Select
170
            <Select
177
              name='shared_with'
171
              name='shared_with'
178
              defaultValue='p'
172
              defaultValue='p'
179
              control={control}
173
              control={control}
180
              options={[
174
              options={[
181
                { name: labels.public, value: 'p' },
175
                { name: labels.public, value: 'p' },
182
                { name: labels.connections, value: 'c' }
176
                { name: labels.connections, value: 'c' }
183
              ]}
177
              ]}
184
            />
178
            />
185
          ) : null}
179
          )}
Línea 186... Línea 180...
186
 
180
 
187
          <Ckeditor
181
          <Ckeditor
188
            name='description'
182
            name='description'
189
            control={control}
183
            control={control}
190
            defaultValue={watchedDescription}
184
            rules={{ required: 'El campo es requerido' }}
191
            onChange={(value) => setValue('description', value)}
-
 
192
            rules={{}}
185
            error={errors.description?.message}
Línea 193... Línea -...
193
          />
-
 
194
 
-
 
195
          {errors.description && (
-
 
196
            <FormErrorFeedback>{errors.description.message}</FormErrorFeedback>
-
 
197
          )}
186
          />
198
 
187
 
199
          {![shareModalTypes.POST, shareModalTypes.SHARE].includes(
188
          {![shareModalTypes.POST, shareModalTypes.SHARE].includes(
200
            modalType
189
            modalType
201
          ) ? (
190
          ) ? (