Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3047 Rev 3668
Línea 1... Línea 1...
1
import React, { useEffect } from 'react'
1
import React, { useEffect, useMemo } from 'react';
2
import { useSelector } from 'react-redux'
-
 
3
import { useForm } from 'react-hook-form'
2
import { useForm } from 'react-hook-form';
Línea 4... Línea 3...
4
 
3
 
Línea 5... Línea 4...
5
import { useFetchHelper } from '@hooks'
4
import { useFetchHelper } from '@hooks';
6
 
5
 
Línea 7... Línea 6...
7
import Modal from '@app/components/UI/modal/Modal'
6
import Modal from '@app/components/UI/modal/Modal';
8
import TagsInput from '@app/components/UI/TagsInput'
7
import TagsInput from '@app/components/UI/TagsInput';
9
 
8
 
10
const HobbiesModal = ({
9
const HobbiesModal = ({
11
  show = false,
10
  show = false,
12
  hobbies: userHobbies = [],
11
  hobbies: userHobbies = [],
13
  onClose = () => {},
12
  onClose = () => {},
14
  onConfirm = () => {}
-
 
Línea 15... Línea 13...
15
}) => {
13
  onConfirm = () => {}
Línea -... Línea 14...
-
 
14
}) => {
-
 
15
  const { data: hobbies = [] } = useFetchHelper('hobbies');
-
 
16
 
-
 
17
  const { register, handleSubmit, setValue } = useForm();
16
  const { data: hobbies } = useFetchHelper('hobbies')
18
 
Línea 17... Línea 19...
17
  const labels = useSelector(({ intl }) => intl.labels)
19
  const currentValues = useMemo(() => {
18
 
20
    return userHobbies?.map(({ value }) => value) || [];
19
  const { register, handleSubmit, setValue } = useForm()
21
  }, [userHobbies]);
Línea 20... Línea 22...
20
 
22
 
21
  const onSubmitHandler = handleSubmit((data) => onConfirm(data))
-
 
22
 
23
  const handleConfirm = handleSubmit((data) => onConfirm?.(data));
23
  useEffect(() => {
-
 
24
    register('hobbies')
24
 
Línea 25... Línea 25...
25
  }, [])
25
  useEffect(() => {
26
 
-
 
27
  useEffect(() => {
26
    register('hobbies');
28
    userHobbies.length
-
 
29
      ? setValue('hobbies', userHobbies)
-
 
30
      : setValue('hobbies', [''])
-
 
31
  }, [userHobbies])
-
 
32
 
27
  }, [register]);
-
 
28
 
-
 
29
  useEffect(() => {
33
  return (
30
    show ? setValue('hobbies', currentValues) : setValue('hobbies', ['']);
34
    <Modal
31
  }, [show, currentValues]);
35
      title={labels.hobbies_and_interests}
32
 
36
      show={show}
33
  return (
37
      onClose={onClose}
34
    <Modal title='Hobbies' show={show} onClose={onClose} onAccept={handleConfirm}>
38
      onAccept={onSubmitHandler}
35
      <TagsInput
39
    >
36
        label='Seleccionar hobbies'
Línea 40... Línea 37...
40
      <TagsInput
37
        name='hobbies'