Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 6346 Rev 6347
Línea 17... Línea 17...
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, getValues, setError } =
22
    useForm({
22
    useForm()
23
      defaultValues: {
-
 
24
        aptitudes: [],
-
 
25
      },
-
 
26
    })
-
 
27
  const [modalLoading, setModalLoading] = useState(false)
23
  const [modalLoading, setModalLoading] = useState(false)
28
  const [settedAptitudeTags, setSettedAptitudeTags] = useState([])
24
  const [settedAptitudeTags, setSettedAptitudeTags] = useState([])
29
  const dispatch = useDispatch()
25
  const dispatch = useDispatch()
Línea 30... Línea 26...
30
 
26
 
Línea 45... Línea 41...
45
      setValue('aptitudes', '')
41
      setValue('aptitudes', '')
46
      setSettedAptitudeTags('')
42
      setSettedAptitudeTags('')
47
    }
43
    }
48
  }
44
  }
Línea 49... Línea 45...
49
 
45
 
50
  const onSubmitHandler = async () => {
46
  const onSubmitHandler = async (data) => {
51
    setModalLoading(true)
47
    setModalLoading(true)
52
    const formData = new FormData()
48
    const formData = new FormData()
53
    getValues('aptitudes').map((language) => {
49
    getValues('aptitudes').map((language) =>
54
      formData.append('aptitudes[]', language)
50
      formData.append('aptitudes[]', language)
-
 
51
    )
-
 
52
 
-
 
53
    console.log(data)
-
 
54
    console.log(getValues('aptitudes'))
55
    })
55
 
56
    await axios
56
    await axios
57
      .post(`/profile/my-profiles/aptitude/${userIdEncrypted}`, formData)
57
      .post(`/profile/my-profiles/aptitude/${userIdEncrypted}`, formData)
58
      .then((response) => {
58
      .then(({ data: response }) => {
59
        const resData = response.data
59
        const { data, success } = response
60
        if (resData.success) {
60
        if (success) {
61
          setAptitudes(settedAptitudeTags)
61
          setAptitudes(settedAptitudeTags)
62
          dispatch(
62
          dispatch(
63
            addNotification({ style: 'success', msg: 'Registro actualizado' })
63
            addNotification({ style: 'success', msg: 'Registro actualizado' })
64
          )
64
          )
65
          handleModalOpen()
65
          handleModalOpen()
66
        } else {
66
        } else {
67
          const resError = resData.data
67
          const resError = data
68
          if (resError.constructor.name === 'Object') {
68
          if (resError.constructor.name === 'Object') {
69
            Object.entries(resError).map(([key, value]) => {
69
            Object.entries(resError).map(([key, value]) => {
70
              if (key in getValues()) {
70
              if (key in getValues()) {
71
                setError(key, {
71
                setError(key, {