Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3047 Rev 3432
Línea 1... Línea 1...
1
import React, { useState, useEffect } from 'react'
1
import React, { useState, useEffect } from "react";
2
import { useDispatch, useSelector } from 'react-redux'
2
import { useDispatch, useSelector } from "react-redux";
3
import { IconButton } from '@mui/material'
3
import { IconButton } from "@mui/material";
4
import { Edit } from '@mui/icons-material'
4
import { Edit } from "@mui/icons-material";
5
 
5
 
6
import { axios } from '@utils'
6
import { axios } from "@utils";
7
import { addNotification } from '@store/notification/notification.actions'
7
import { addNotification } from "@store/notification/notification.actions";
8
import TagsList from '@components/UI/TagsList'
8
import TagsList from "@components/UI/TagsList";
9
import HobbiesModal from './HobbiesModal'
9
import HobbiesModal from "./HobbiesModal";
10
import Widget from '@components/UI/Widget'
10
import Widget from "@components/UI/Widget";
Línea 11... Línea 11...
11
 
11
 
12
const HobbiesCard = ({
12
const HobbiesCard = ({
13
  hobbies: defaultHobbies = [],
13
  hobbies: defaultHobbies = [],
14
  uuid = '',
14
  uuid = "",
15
  edit = false
15
  edit = false,
16
}) => {
16
}) => {
17
  const [hobbies, setHobbies] = useState([])
17
  const [hobbies, setHobbies] = useState([]);
18
  const [showModal, setShoModal] = useState(false)
18
  const [showModal, setShoModal] = useState(false);
19
  const labels = useSelector(({ intl }) => intl.labels)
19
  const labels = useSelector(({ intl }) => intl.labels);
Línea 20... Línea 20...
20
  const dispatch = useDispatch()
20
  const dispatch = useDispatch();
Línea 21... Línea 21...
21
 
21
 
22
  const toggleModal = () => setShoModal(!showModal)
22
  const toggleModal = () => setShoModal(!showModal);
Línea 23... Línea 23...
23
 
23
 
24
  const handleEditHobbies = ({ hobbies }) => {
24
  const handleEditHobbies = ({ hobbies }) => {
25
    const formData = new FormData()
25
    const formData = new FormData();
Línea 26... Línea 26...
26
 
26
 
27
    hobbies.map((hobbie) =>
27
    hobbies.map((hobbie) =>
28
      formData.append('hobbies_and_interests[]', hobbie.value)
28
      formData.append("hobbies_and_interests[]", hobbie.value)
29
    )
29
    );
Línea 30... Línea 30...
30
 
30
 
31
    axios
31
    axios
32
      .post(`/profile/my-profiles/hobby-and-interest/${uuid}`, formData)
32
      .post(`/profile/my-profiles/hobby-and-interest/${uuid}`, formData)
33
      .then(({ data: response }) => {
33
      .then((response) => {
34
        const { data, success } = response
34
        const { data, success } = response.data;
Línea 35... Línea 35...
35
 
35
 
36
        if (!success) {
36
        if (!success) {
37
          const errorMessage =
37
          const errorMessage =
38
            typeof data === 'string' ? data : data.hobbies_and_interests[0]
38
            typeof data === "string" ? data : data.hobbies_and_interests[0];
39
          throw new Error(errorMessage)
39
          throw new Error(errorMessage);
40
        }
40
        }
41
 
41
 
Línea 42... Línea 42...
42
        setHobbies(hobbies)
42
        setHobbies(hobbies);
43
        toggleModal()
43
        toggleModal();
44
      })
44
      })
Línea 45... Línea 45...
45
      .catch((err) => {
45
      .catch((err) => {
46
        dispatch(addNotification({ style: 'danger', msg: err.message }))
46
        dispatch(addNotification({ style: "danger", msg: err.message }));
47
      })
47
      });
48
  }
48
  };
Línea 75... Línea 75...
75
        onClose={toggleModal}
75
        onClose={toggleModal}
76
        onConfirm={handleEditHobbies}
76
        onConfirm={handleEditHobbies}
77
        hobbies={hobbies}
77
        hobbies={hobbies}
78
      />
78
      />
79
    </>
79
    </>
80
  )
80
  );
81
}
81
};
Línea 82... Línea 82...
82
 
82