Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3174 Rev 3175
Línea 41... Línea 41...
41
    unregister,
41
    unregister,
42
    handleSubmit,
42
    handleSubmit,
43
    setValue,
43
    setValue,
44
    getValues,
44
    getValues,
45
    clearErrors,
45
    clearErrors,
46
    setError,
-
 
47
    watch
46
    watch
48
  } = useForm({
47
  } = useForm({
49
    defaultValues: {
48
    defaultValues: {
50
      description: '',
49
      description: '',
51
      share_width: 'p'
50
      share_width: 'p'
Línea 67... Línea 66...
67
    setModalType(lastModalType)
66
    setModalType(lastModalType)
68
    dispatch(closeShareModal())
67
    dispatch(closeShareModal())
69
    dispatch(openShareModal(postUrl, lastModalType, feedType))
68
    dispatch(openShareModal(postUrl, lastModalType, feedType))
70
  }
69
  }
Línea -... Línea 70...
-
 
70
 
-
 
71
  const onUploadedHandler = (files) => {
-
 
72
    setValue('file', files)
-
 
73
    clearErrors('file')
-
 
74
  }
-
 
75
 
-
 
76
  const onClose = () => {
-
 
77
    clearErrors()
-
 
78
    dispatch(closeShareModal())
-
 
79
  }
71
 
80
 
72
  const onSubmit = handleSubmit((data) => {
81
  const onSubmit = (data) => {
73
    const form = new FormData()
82
    const form = new FormData()
74
    form.append(
83
    form.append(
75
      'posted_or_shared',
84
      'posted_or_shared',
76
      modalType === shareModalTypes.SHARE ? 's' : 'p'
85
      modalType === shareModalTypes.SHARE ? 's' : 'p'
Línea 80... Línea 89...
80
    axios
89
    axios
81
      .post(postUrl, form)
90
      .post(postUrl, form)
82
      .then((response) => {
91
      .then((response) => {
83
        const { data, success } = response.data
92
        const { data, success } = response.data
Línea 84... Línea 93...
84
 
93
 
85
        if (!success && typeof data !== 'string') {
94
        if (!success) {
86
          Object.entries(data).map(([key, value]) =>
95
          const errorMessage =
87
            setError(key, { type: 'required', message: value[0] })
-
 
88
          )
96
            typeof data === 'string'
89
          return
-
 
90
        }
-
 
91
 
97
              ? data
92
        if (!success && typeof data === 'string') {
98
              : 'Ha ocurrido un error al publicar, inténtalo de nuevo más tarde.'
93
          throw new Error(data)
99
          throw new Error(errorMessage)
Línea 94... Línea 100...
94
        }
100
        }
Línea 95... Línea 101...
95
 
101
 
Línea 113... Línea 119...
113
        setValue('description', '')
119
        setValue('description', '')
114
        setValue('file', '')
120
        setValue('file', '')
115
      })
121
      })
116
      .catch((error) => {
122
      .catch((error) => {
117
        console.error(error)
123
        console.error(error)
118
        dispatch(
-
 
119
          addNotification({
-
 
120
            style: 'danger',
-
 
121
            msg: 'Ha ocurrido un error al publicar, intente más tarde.'
124
        dispatch(addNotification({ style: 'danger', msg: error.message }))
122
          })
-
 
123
        )
-
 
124
      })
125
      })
125
  })
-
 
126
 
-
 
127
  const onUploadedHandler = (files) => {
-
 
128
    setValue('file', files)
-
 
129
    clearErrors('file')
-
 
130
  }
-
 
131
 
-
 
132
  const onClose = () => {
-
 
133
    clearErrors()
-
 
134
    dispatch(closeShareModal())
-
 
135
  }
126
  }
Línea 136... Línea 127...
136
 
127
 
137
  useEffect(() => {
128
  useEffect(() => {
138
    if (
129
    if (
Línea 159... Línea 150...
159
      <Modal
150
      <Modal
160
        show={isOpen}
151
        show={isOpen}
161
        title={labels.share_a_post}
152
        title={labels.share_a_post}
162
        labelAccept={labels.send}
153
        labelAccept={labels.send}
163
        labelReject={labels.cancel}
154
        labelReject={labels.cancel}
164
        onClose={onClose}
-
 
165
        loading={isSubmitting}
155
        loading={isSubmitting}
-
 
156
        onClose={onClose}
166
        formId='share-form'
157
        formId='share-form'
167
      >
158
      >
168
        <Form onSubmit={onSubmit} id='share-form'>
159
        <Form onSubmit={handleSubmit(onSubmit)} id='share-form'>
169
          {feedType === feedTypes.DASHBOARD && (
160
          {feedType === feedTypes.DASHBOARD && (
170
            <Select
161
            <Select
171
              name='shared_with'
162
              name='shared_with'
172
              defaultValue='p'
163
              defaultValue='p'
173
              control={control}
164
              control={control}
Línea 185... Línea 176...
185
            error={errors.description?.message}
176
            error={errors.description?.message}
186
          />
177
          />
Línea 187... Línea 178...
187
 
178
 
188
          {![shareModalTypes.POST, shareModalTypes.SHARE].includes(
179
          {![shareModalTypes.POST, shareModalTypes.SHARE].includes(
189
            modalType
180
            modalType
190
          ) ? (
181
          ) && (
191
            <DropzoneComponent
182
            <DropzoneComponent
192
              modalType={modalType}
183
              modalType={modalType}
193
              onUploaded={onUploadedHandler}
184
              onUploaded={onUploadedHandler}
194
              settedFile={watch('file')}
185
              settedFile={watch('file')}
195
              recomendationText={recomendationText[modalType] ?? ''}
186
              recomendationText={recomendationText[modalType] ?? ''}
196
            />
187
            />
Línea 197... Línea 188...
197
          ) : null}
188
          )}
198
 
189
 
199
          {errors.file && (
190
          {errors.file && (
200
            <FormErrorFeedback>{errors.file.message}</FormErrorFeedback>
191
            <FormErrorFeedback>{errors.file.message}</FormErrorFeedback>