Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3084 Rev 3085
Línea 1... Línea 1...
1
import React from 'react'
1
import React from 'react'
2
import { connect } from 'react-redux'
2
import { connect } from 'react-redux'
3
import { useForm } from 'react-hook-form'
3
import { useForm } from 'react-hook-form'
Línea 4... Línea -...
4
 
-
 
5
import { axios } from '@utils'
4
 
Línea 6... Línea 5...
6
import { addNotification } from '@store/notification/notification.actions'
5
import { addNotification } from '@store/notification/notification.actions'
7
 
6
 
Línea 8... Línea 7...
8
import Modal from '@components/UI/modal/Modal'
7
import Modal from '@components/UI/modal/Modal'
9
import Select from '@components/UI/inputs/Select'
-
 
10
 
8
import Select from '@components/UI/inputs/Select'
11
const ApplyModal = ({
9
 
12
  jobId,
10
const ApplyModal = ({
13
  show,
11
  show,
14
  userProfiles,
-
 
15
  onApplied,
12
  profiles,
16
  onHide = function () {},
13
  onConfirm,
17
  addNotification = function () {} // redux destructuring
14
  onClose = function () {}
18
}) => {
15
}) => {
19
  const {
16
  const {
20
    control,
-
 
21
    formState: { errors },
-
 
22
    handleSubmit,
17
    control,
Línea 23... Línea 18...
23
    getValues,
18
    formState: { errors, isSubmitting },
24
    setError
-
 
25
  } = useForm()
-
 
26
 
-
 
27
  const onSubmit = handleSubmit((data) => {
-
 
28
    const formData = new FormData()
-
 
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) {
-
 
33
        onApplied()
-
 
34
        onHide()
-
 
35
      } else {
-
 
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
            }
-
 
41
          })
-
 
42
        } else if (typeof data.data === 'string') {
-
 
43
          addNotification({
-
 
44
            style: 'danger',
-
 
45
            msg: data.data
-
 
46
          })
-
 
47
        } else {
-
 
48
          addNotification({
-
 
49
            style: 'danger',
-
 
50
            msg: 'Ha ocurrido un error, por favor intente más tarde'
-
 
51
          })
-
 
Línea 52... Línea 19...
52
        }
19
    handleSubmit
53
      }
20
  } = useForm()
54
    })
21
 
55
  })
22
  const onSubmit = handleSubmit((data) => onConfirm(data))
56
 
23
 
57
  return (
24
  return (
-
 
25
    <Modal
58
    <Modal
26
      title='Perfil de Applicación'
59
      title='Perfil de Applicación'
27
      show={show}
60
      show={show}
28
      onClose={onClose}
61
      onClose={onHide}
29
      onAccept={onSubmit}
62
      onAccept={onSubmit}
30
      loading={isSubmitting}
63
    >
31
    >
64
      <Select
32
      <Select
65
        name='user_profile_id'
33
        name='user_profile_id'
66
        control={control}
34
        control={control}
67
        rules={{ required: 'Por favor seleccione un perfil' }}
35
        rules={{ required: 'Por favor seleccione un perfil' }}
68
        error={errors?.user_profile_id.message}
36
        error={errors?.user_profile_id?.message}
69
        options={Object.entries(userProfiles).map(([value, name]) => ({
37
        options={Object.entries(profiles).map(([value, name]) => ({