Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1979 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1979 Rev 2802
Línea 14... Línea 14...
14
  userProfiles,
14
  userProfiles,
15
  onApplied,
15
  onApplied,
16
  onHide = function () {},
16
  onHide = function () {},
17
  addNotification = function () {} // redux destructuring
17
  addNotification = function () {} // redux destructuring
18
}) => {
18
}) => {
19
 
19
  const {
-
 
20
    register,
-
 
21
    handleSubmit,
-
 
22
    getValues,
-
 
23
    setError,
20
  const { register, handleSubmit, errors, getValues, setError } = useForm()
24
    formState: { errors }
-
 
25
  } = useForm()
Línea 21... Línea 26...
21
 
26
 
22
  const onSubmit = handleSubmit((data) => {
-
 
23
    
27
  const onSubmit = handleSubmit((data) => {
24
    const formData = new FormData()
28
    const formData = new FormData()
Línea -... Línea 29...
-
 
29
    Object.entries(data).map(([key, value]) => formData.append(key, value))
-
 
30
 
-
 
31
    axios.post(`/job/apply-job/${jobId}`, formData).then(({ data }) => {
-
 
32
      if (data.success) {
25
    Object.entries(data).map(([key, value]) => formData.append(key, value))
33
        onApplied()
26
 
34
        onHide()
-
 
35
      } else {
27
    axios
36
        if (typeof data.data === 'object') {
-
 
37
          Object.entries(data.data).forEach(([key, value]) => {
-
 
38
            if (key in getValues()) {
-
 
39
              setError(key, { type: 'manual', message: value[0] })
-
 
40
            }
28
      .post(`/job/apply-job/${jobId}`, formData)
41
          })
-
 
42
        } else if (typeof data.data === 'string') {
29
      .then(({ data }) => {
43
          addNotification({
30
        if (data.success) {
44
            style: 'danger',
31
          onApplied()
45
            msg: data.data
32
          onHide()
-
 
33
        } else {
-
 
34
          if (typeof data.data === 'object') {
-
 
35
            Object.entries(data.data).forEach(([key, value]) => {
-
 
36
              if (key in getValues()) {
-
 
37
                setError(key, { type: 'manual', message: value[0] })
-
 
38
              }
-
 
39
            })
46
          })
40
          } else if (typeof data.data === 'string') {
47
        } else {
41
            addNotification({
-
 
42
              style: 'danger',
-
 
43
              msg: data.data
-
 
44
            })
-
 
45
          } else {
-
 
46
            addNotification({
48
          addNotification({
47
              style: 'danger',
-
 
48
              msg: 'Ha ocurrido un error, por favor intente más tarde'
49
            style: 'danger',
49
            })
50
            msg: 'Ha ocurrido un error, por favor intente más tarde'
50
          }
51
          })
-
 
52
        }
51
        }
53
      }
Línea 52... Línea 54...
52
      })
54
    })
53
  })
55
  })
54
 
56