Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 6348 Rev 6349
Línea 16... Línea 16...
16
  aptitudesOptions = [],
16
  aptitudesOptions = [],
17
  userAptitudes = [],
17
  userAptitudes = [],
18
  closeModal = () => {},
18
  closeModal = () => {},
19
  setAptitudes = () => {},
19
  setAptitudes = () => {},
20
}) => {
20
}) => {
21
  const { register, errors, handleSubmit, setValue, getValues, setError } =
21
  const { register, errors, handleSubmit, setValue, setError } = useForm()
22
    useForm()
-
 
23
  const [modalLoading, setModalLoading] = useState(false)
22
  const [modalLoading, setModalLoading] = useState(false)
24
  const [settedAptitudeTags, setSettedAptitudeTags] = useState([])
-
 
25
  const dispatch = useDispatch()
23
  const dispatch = useDispatch()
Línea 26... Línea 24...
26
 
24
 
27
  const handleModalOpen = () => {
25
  const handleModalOpen = () => {
28
    Object.keys(getValues()).map(([key]) => setValue(key, ''))
26
    setValue('aptitudes', '')
29
    closeModal()
27
    closeModal()
Línea 30... Línea 28...
30
  }
28
  }
31
 
-
 
32
  const handleTagsChange = (tags) => {
-
 
33
    if (tags.length) {
-
 
34
      let newTags = []
-
 
35
      tags.map((tag) => {
-
 
36
        newTags = [...newTags, tag.value]
29
 
37
      })
-
 
38
      setValue('aptitudes', newTags)
-
 
39
      setSettedAptitudeTags(tags)
-
 
40
    } else {
-
 
41
      setValue('aptitudes', '')
-
 
42
      setSettedAptitudeTags('')
30
  const handleTagsChange = (tags) => {
Línea 43... Línea 31...
43
    }
31
    setValue('aptitudes', tags)
44
  }
32
  }
Línea 45... Línea 33...
45
 
33
 
46
  const onSubmitHandler = async (data) => {
-
 
-
 
34
  const onSubmitHandler = async ({ aptitudes }) => {
47
    setModalLoading(true)
35
    setModalLoading(true)
48
 
-
 
49
    console.log(data)
36
 
50
    console.log(getValues('aptitudes'))
-
 
Línea 51... Línea 37...
51
    const formData = new FormData()
37
    console.log(aptitudes)
52
    getValues('aptitudes').map((language) =>
38
 
53
      formData.append('aptitudes[]', language)
39
    const formData = new FormData()
54
    )
40
    aptitudes.map((aptitude) => formData.append('aptitudes[]', aptitude.value))
55
 
41
 
56
    await axios
-
 
57
      .post(`/profile/my-profiles/aptitude/${userIdEncrypted}`, formData)
-
 
58
      .then(({ data: response }) => {
-
 
59
        const { data, success } = response
-
 
60
        if (success) {
-
 
61
          setAptitudes(settedAptitudeTags)
-
 
62
          dispatch(
42
    axios
63
            addNotification({ style: 'success', msg: 'Registro actualizado' })
43
      .post(`/profile/my-profiles/aptitude/${userIdEncrypted}`, formData)
64
          )
44
      .then(({ data: response }) => {
65
          handleModalOpen()
-
 
66
        } else {
45
        const { data, success } = response
67
          const resError = data
46
        if (!success) {
68
          if (resError.constructor.name === 'Object') {
47
          const resError = data
69
            Object.entries(resError).map(([key, value]) => {
48
          typeof resError === 'string'
70
              if (key in getValues()) {
49
            ? Object.entries(resError).map(([key, value]) => {
71
                setError(key, {
-
 
72
                  type: 'manual',
-
 
73
                  message: Array.isArray(value) ? value[0] : value,
50
                setError('aptitudes', {
74
                })
51
                  type: 'manual',
75
              }
52
                  message: Array.isArray(value) ? value[0] : value,
-
 
53
                })
-
 
54
              })
-
 
55
            : dispatch(addNotification({ style: 'danger', msg: resError }))
-
 
56
          return
-
 
57
        }
-
 
58
 
-
 
59
        setAptitudes(aptitudes)
76
            })
60
        dispatch(
77
          } else {
61
          addNotification({ style: 'success', msg: 'Registro actualizado' })
78
            dispatch(addNotification({ style: 'danger', msg: resError }))
62
        )
Línea 79... Línea 63...
79
          }
63