Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 6753 Rev 6807
Línea 5... Línea 5...
5
import { useDispatch, useSelector } from 'react-redux'
5
import { useDispatch, useSelector } from 'react-redux'
6
import { addNotification } from '../../../redux/notification/notification.actions'
6
import { addNotification } from '../../../redux/notification/notification.actions'
Línea 7... Línea 7...
7
 
7
 
8
import Spinner from '../../../shared/loading-spinner/Spinner'
8
import Spinner from '../../../shared/loading-spinner/Spinner'
-
 
9
import TagsInput from '../../../shared/tags-input/TagsInput'
Línea 9... Línea 10...
9
import TagsInput from '../../../shared/tags-input/TagsInput'
10
import useFetchHelper from '../../hooks/useFetchHelper'
10
 
11
 
11
const HobbiesModal = ({
12
const HobbiesModal = ({
12
  show = false,
13
  show = false,
13
  userIdEncrypted = '',
-
 
14
  userHobbiesAndInterests = [],
14
  userId = '',
15
  hobbiesAndInterestsOptions = [],
15
  userHobbies = [],
16
  closeModal = () => {},
16
  onClose = () => {},
17
  setUserHobbiesAndInterests = () => {},
17
  onComplete = () => {},
-
 
18
}) => {
18
}) => {
19
  const [modalLoading, setModalLoading] = useState(false)
19
  const [modalLoading, setModalLoading] = useState(false)
20
  const { data: hobbies } = useFetchHelper('hobbies')
Línea 20... Línea 21...
20
  const labels = useSelector(({ intl }) => intl.labels)
21
  const labels = useSelector(({ intl }) => intl.labels)
Línea 33... Línea 34...
33
    hobbiesAndInterests.map((language) =>
34
    hobbiesAndInterests.map((language) =>
34
      formData.append('hobbies_and_interests[]', language.value)
35
      formData.append('hobbies_and_interests[]', language.value)
35
    )
36
    )
Línea 36... Línea 37...
36
 
37
 
37
    axios
-
 
38
      .post(
38
    axios
39
        `/profile/my-profiles/hobby-and-interest/${userIdEncrypted}`,
-
 
40
        formData
-
 
41
      )
39
      .post(`/profile/my-profiles/hobby-and-interest/${userId}`, formData)
42
      .then(({ data: response }) => {
40
      .then(({ data: response }) => {
43
        const { data, success } = response
41
        const { data, success } = response
44
        if (!success) {
42
        if (!success) {
45
          const errorMessage = data.hobbies_and_interests[0]
43
          const errorMessage = data.hobbies_and_interests[0]
46
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
44
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
47
          return
45
          return
Línea 48... Línea 46...
48
        }
46
        }
49
 
47
 
50
        setUserHobbiesAndInterests(hobbiesAndInterests)
48
        onComplete(hobbiesAndInterests)
51
        dispatch(
49
        dispatch(
52
          addNotification({ style: 'success', msg: 'Registro actualizado' })
50
          addNotification({ style: 'success', msg: 'Registro actualizado' })
53
        )
51
        )
54
        closeModal()
52
        onClose()
55
      })
53
      })
56
      .catch((error) => {
54
      .catch((error) => {
57
        dispatch(addNotification({ style: 'danger', msg: error }))
55
        dispatch(addNotification({ style: 'danger', msg: error }))
Línea 64... Línea 62...
64
    register('hobbiesAndInterests')
62
    register('hobbiesAndInterests')
65
  }, [])
63
  }, [])
Línea 66... Línea 64...
66
 
64
 
67
  useEffect(() => {
65
  useEffect(() => {
68
    show
66
    show
69
      ? setValue('hobbiesAndInterests', userHobbiesAndInterests)
67
      ? setValue('hobbiesAndInterests', userHobbies)
70
      : setValue('hobbiesAndInterests', [''])
68
      : setValue('hobbiesAndInterests', [''])
Línea 71... Línea 69...
71
  }, [show])
69
  }, [show])
72
 
70
 
73
  return (
71
  return (
74
    <Modal show={show} onHide={closeModal}>
72
    <Modal show={show} onHide={onClose}>
75
      <Modal.Header closeButton>
73
      <Modal.Header closeButton>
76
        <Modal.Title>{labels.hobbies_and_interests}</Modal.Title>
74
        <Modal.Title>{labels.hobbies_and_interests}</Modal.Title>
77
      </Modal.Header>
75
      </Modal.Header>
78
      <form onSubmit={handleSubmit(onSubmitHandler)}>
76
      <form onSubmit={handleSubmit(onSubmitHandler)}>
79
        <Modal.Body>
77
        <Modal.Body>
80
          <div className="form-group">
78
          <div className="form-group">
81
            <TagsInput
79
            <TagsInput
82
              suggestions={hobbiesAndInterestsOptions}
80
              suggestions={hobbies}
83
              settedTags={userHobbiesAndInterests}
81
              settedTags={userHobbies}
84
              onChange={handleTagsChange}
82
              onChange={handleTagsChange}
85
            />
83
            />
86
          </div>
84
          </div>
87
        </Modal.Body>
85
        </Modal.Body>
88
        <Modal.Footer>
86
        <Modal.Footer>
89
          <Button size="sm" type="submit">
87
          <Button size="sm" type="submit">
90
            {labels.accept}
88
            {labels.accept}
91
          </Button>
89
          </Button>
92
          <Button size="sm" variant="danger" onClick={closeModal}>
90
          <Button size="sm" variant="danger" onClick={onClose}>
93
            {labels.cancel}
91
            {labels.cancel}
94
          </Button>
92
          </Button>
95
        </Modal.Footer>
93
        </Modal.Footer>