Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3432 Rev 3640
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';
11
 
11
 
12
const HobbiesCard = ({
-
 
13
  hobbies: defaultHobbies = [],
12
const HobbiesCard = ({ hobbies: defaultHobbies = [], uuid = '', edit = false }) => {
14
  uuid = "",
-
 
15
  edit = false,
-
 
16
}) => {
-
 
17
  const [hobbies, setHobbies] = useState([]);
13
  const [hobbies, setHobbies] = useState([]);
18
  const [showModal, setShoModal] = useState(false);
14
  const [showModal, setShoModal] = useState(false);
19
  const labels = useSelector(({ intl }) => intl.labels);
15
  const labels = useSelector(({ intl }) => intl.labels);
20
  const dispatch = useDispatch();
16
  const dispatch = useDispatch();
Línea 21... Línea 17...
21
 
17
 
Línea 22... Línea 18...
22
  const toggleModal = () => setShoModal(!showModal);
18
  const toggleModal = () => setShoModal(!showModal);
23
 
19
 
Línea 24... Línea -...
24
  const handleEditHobbies = ({ hobbies }) => {
-
 
25
    const formData = new FormData();
20
  const handleEditHobbies = ({ hobbies }) => {
26
 
-
 
Línea 27... Línea 21...
27
    hobbies.map((hobbie) =>
21
    const formData = new FormData();
28
      formData.append("hobbies_and_interests[]", hobbie.value)
22
 
29
    );
23
    hobbies.map((hobbie) => formData.append('hobbies_and_interests[]', hobbie.value));
30
 
24
 
Línea 31... Línea 25...
31
    axios
25
    axios
32
      .post(`/profile/my-profiles/hobby-and-interest/${uuid}`, formData)
-
 
33
      .then((response) => {
26
      .post(`/profile/my-profiles/hobby-and-interest/${uuid}`, formData)
34
        const { data, success } = response.data;
27
      .then((response) => {
35
 
28
        const { data, success } = response.data;
Línea 36... Línea 29...
36
        if (!success) {
29
 
37
          const errorMessage =
30
        if (!success) {
38
            typeof data === "string" ? data : data.hobbies_and_interests[0];
31
          const errorMessage = typeof data === 'string' ? data : data.hobbies_and_interests[0];
39
          throw new Error(errorMessage);
32
          throw new Error(errorMessage);
40
        }
33
        }
41
 
34
 
42
        setHobbies(hobbies);
35
        setHobbies(hobbies);
Línea 43... Línea 36...
43
        toggleModal();
36
        toggleModal();
44
      })
37
      })
Línea 54... Línea 47...
54
  return (
47
  return (
55
    <>
48
    <>
56
      <Widget>
49
      <Widget>
57
        <Widget.Header
50
        <Widget.Header
58
          title={labels.hobbies_and_interests}
51
          title={labels.hobbies_and_interests}
59
          renderAction={
52
          renderAction={() => {
-
 
53
            if (!edit) return;
60
            edit && (
54
            return (
61
              <IconButton onClick={toggleModal}>
55
              <IconButton onClick={toggleModal}>
62
                <Edit />
56
                <Edit />
63
              </IconButton>
57
              </IconButton>
64
            )
58
            );
65
          }
59
          }}
66
        />
60
        />
Línea 67... Línea 61...
67
 
61
 
68
        <Widget.Body>
62
        <Widget.Body>
69
          <TagsList tags={hobbies} />
63
          <TagsList tags={hobbies} />