Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 16694 Rev 16696
Línea 3... Línea 3...
3
import { config } from './helpers/ckeditor_config'
3
import { config } from './helpers/ckeditor_config'
4
import { useForm } from 'react-hook-form'
4
import { useForm } from 'react-hook-form'
5
import { connect } from 'react-redux'
5
import { connect } from 'react-redux'
6
import { Button, Modal } from 'react-bootstrap'
6
import { Button, Modal } from 'react-bootstrap'
7
import { CKEditor } from 'ckeditor4-react'
7
import { CKEditor } from 'ckeditor4-react'
-
 
8
import Datetime from 'react-datetime'
Línea 8... Línea 9...
8
 
9
 
9
import {
10
import {
10
  closeShareModal,
11
  closeShareModal,
11
  setModalType
12
  setModalType
Línea 52... Línea 53...
52
  const onSubmit = handleSubmit((data) => {
53
  const onSubmit = handleSubmit((data) => {
53
    setLoading(true)
54
    setLoading(true)
54
    const formData = new FormData()
55
    const formData = new FormData()
Línea 55... Línea 56...
55
 
56
 
-
 
57
    Object.entries(data).map(([entry, value]) => formData.append(entry, value))
Línea 56... Línea 58...
56
    Object.entries(data).map(([entry, value]) => formData.append(entry, value))
58
    console.log(data)
57
 
59
 
58
    axios
60
    /* axios
59
      .post(postUrl, formData)
61
      .post(postUrl, formData)
60
      .then(({ data: response }) => {
62
      .then(({ data: response }) => {
61
        const { success, data } = response
63
        const { success, data } = response
Línea 88... Línea 90...
88
      })
90
      })
89
      .catch((err) => {
91
      .catch((err) => {
90
        addNotification({ style: 'danger', msg: `Error: ${err}` })
92
        addNotification({ style: 'danger', msg: `Error: ${err}` })
91
        throw new Error(err)
93
        throw new Error(err)
92
      })
94
      })
93
      .finally(() => setLoading(false))
95
      .finally(() => setLoading(false)) */
94
  })
96
  })
Línea 95... Línea 97...
95
 
97
 
96
  useEffect(() => {
98
  useEffect(() => {
97
    clearErrors()
99
    clearErrors()
Línea 114... Línea 116...
114
    }
116
    }
Línea 115... Línea 117...
115
 
117
 
116
    if (modalType === shareModalTypes.POST) {
118
    if (modalType === shareModalTypes.POST) {
117
      register('description', { required: 'El campo es requerido' })
119
      register('description', { required: 'El campo es requerido' })
-
 
120
    }
-
 
121
 
-
 
122
    if (modalType === shareModalTypes.SURVEY) {
-
 
123
      register('date', { required: 'El campo es requerido' })
118
    }
124
    }
Línea 119... Línea 125...
119
  }, [modalType])
125
  }, [modalType])
120
 
126
 
121
  return (
127
  return (
Línea 126... Línea 132...
126
        </Modal.Header>
132
        </Modal.Header>
127
        <Modal.Body>
133
        <Modal.Body>
128
          {!loading ? (
134
          {!loading ? (
129
            <>
135
            <>
130
              {modalType === shareModalTypes.SURVEY && (
136
              {modalType === shareModalTypes.SURVEY && (
131
                <SurveyForm register={register} />
137
                <SurveyForm register={register} setValue={setValue} />
132
              )}
138
              )}
133
              {modalType !== shareModalTypes.SURVEY && (
139
              {modalType !== shareModalTypes.SURVEY && (
134
                <>
140
                <>
135
                  <CKEditor
141
                  <CKEditor
136
                    onChange={(e) =>
142
                    onChange={(e) =>
Línea 183... Línea 189...
183
      </form>
189
      </form>
184
    </Modal>
190
    </Modal>
185
  )
191
  )
186
}
192
}
Línea 187... Línea 193...
187
 
193
 
188
const SurveyForm = ({ register }) => {
194
const SurveyForm = ({ register, setValue }) => {
Línea 189... Línea 195...
189
  const [optionsNumber, setOptionsNumber] = useState(2)
195
  const [optionsNumber, setOptionsNumber] = useState(2)
190
 
196
 
191
  const options = [
197
  const options = [
Línea 212... Línea 218...
212
          className="form-control"
218
          className="form-control"
213
          name="privacy"
219
          name="privacy"
214
          id="privacy"
220
          id="privacy"
215
          ref={register}
221
          ref={register}
216
        >
222
        >
-
 
223
          <option value="c">Compañía</option>
217
          <option value="public">Público</option>
224
          <option value="p">Público</option>
-
 
225
        </select>
-
 
226
      </div>
-
 
227
      <div className="form-group">
-
 
228
        <label htmlFor="result">Resultado</label>
-
 
229
        <select
-
 
230
          className="form-control"
-
 
231
          name="result"
-
 
232
          id="result"
-
 
233
          ref={register}
-
 
234
        >
218
          <option value="private">Privado</option>
235
          <option value="pr">Privado</option>
-
 
236
          <option value="pu">Público</option>
219
        </select>
237
        </select>
220
      </div>
238
      </div>
221
      <div className="form-group">
239
      <div className="form-group">
222
        <label htmlFor="question">Tu pregunta*</label>
240
        <label htmlFor="question">Tu pregunta*</label>
223
        <input
241
        <input
Línea 252... Línea 270...
252
      {optionsNumber < options.length && (
270
      {optionsNumber < options.length && (
253
        <button className="btn btn-outline-primary rounded" onClick={addOption}>
271
        <button className="btn btn-outline-primary rounded" onClick={addOption}>
254
          Añadir opción
272
          Añadir opción
255
        </button>
273
        </button>
256
      )}
274
      )}
-
 
275
      <Datetime
-
 
276
        onChange={(e) => {
-
 
277
          const date = e.toDate()
-
 
278
          setValue('date', date)
-
 
279
        }}
-
 
280
      />
257
    </>
281
    </>
258
  )
282
  )
259
}
283
}
Línea 260... Línea 284...
260
 
284