Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2780 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1854 stevensc 1
import React, { useEffect } from 'react'
2
import { useSelector } from 'react-redux'
3
import { useForm } from 'react-hook-form'
4
 
5
import useFetchHelper from '@app/hooks/useFetchHelper'
6
 
7
import Modal from '@app/components/UI/modal/Modal'
8
import TagsInput from '@app/components/UI/TagsInput'
9
 
10
const HobbiesModal = ({
11
  show = false,
12
  hobbies: userHobbies = [],
13
  onClose = () => {},
14
  onConfirm = () => {}
15
}) => {
16
  const { data: hobbies } = useFetchHelper('hobbies')
17
  const labels = useSelector(({ intl }) => intl.labels)
18
 
19
  const { register, handleSubmit, setValue } = useForm()
20
 
21
  const onSubmitHandler = handleSubmit((data) => onConfirm(data))
22
 
23
  useEffect(() => {
24
    register('hobbies')
25
  }, [])
26
 
27
  useEffect(() => {
28
    userHobbies.length
29
      ? setValue('hobbies', userHobbies)
30
      : setValue('hobbies', [''])
31
  }, [userHobbies])
32
 
33
  return (
34
    <Modal
35
      title={labels.hobbies_and_interests}
36
      show={show}
37
      onClose={onClose}
38
      onAccept={onSubmitHandler}
39
    >
40
      <TagsInput
41
        suggestions={hobbies}
42
        settedTags={userHobbies}
43
        onChange={(tags) => setValue('hobbies', tags)}
44
      />
45
    </Modal>
46
  )
47
}
48
 
49
export default HobbiesModal