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';
4
 
-
 
5
import { useFetchHelper } from '@hooks'
-
 
6
 
-
 
7
import Modal from '@app/components/UI/modal/Modal'
-
 
8
import TagsInput from '@app/components/UI/TagsInput'
-
 
9
 
-
 
10
const SkillsModal = ({
-
 
11
  show = false,
-
 
12
  skills: userSkills = [],
-
 
13
  onConfirm = () => null,
-
 
14
  onClose = () => null
-
 
15
}) => {
-
 
16
  const { data: skills } = useFetchHelper('skills', [])
-
 
17
  const labels = useSelector(({ intl }) => intl.labels)
-
 
Línea 18... Línea 3...
18
 
3
 
Línea -... Línea 4...
-
 
4
import { useFetchHelper } from '@hooks';
-
 
5
 
-
 
6
import Modal from '@app/components/UI/modal/Modal';
-
 
7
import TagsInput from '@app/components/UI/TagsInput';
-
 
8
 
-
 
9
const SkillsModal = ({ show = false, skills: userSkills = [], onConfirm, onClose }) => {
-
 
10
  const { data: skills = [] } = useFetchHelper('skills');
-
 
11
 
-
 
12
  const { register, handleSubmit, setValue } = useForm();
-
 
13
 
-
 
14
  const currentValues = useMemo(() => {
-
 
15
    return userSkills?.map(({ value }) => value) || [];
19
  const { register, handleSubmit, setValue } = useForm()
16
  }, [userSkills]);
Línea 20... Línea 17...
20
 
17
 
21
  const onSubmit = handleSubmit((data) => onConfirm(data))
18
  const handleConfirm = handleSubmit((data) => onConfirm?.(data));
22
 
19
 
Línea 23... Línea 20...
23
  useEffect(() => {
20
  useEffect(() => {
24
    register('skills')
-
 
25
  }, [])
21
    register('skills');
26
 
-
 
27
  useEffect(() => {
22
  }, [register]);
Línea 28... Línea 23...
28
    userSkills.length
23
 
29
      ? setValue('skills', userSkills)
-
 
30
      : setValue('skills', [''])
-
 
31
  }, [userSkills])
24
  useEffect(() => {
32
 
-
 
33
  return (
-
 
34
    <Modal
-
 
35
      show={show}
25
    show ? setValue('skills', currentValues) : setValue('skills', ['']);
-
 
26
  }, [show, currentValues]);
-
 
27
 
36
      onClose={onClose}
28
  return (
37
      title={labels.skills}
29
    <Modal title='Habilidades' show={show} onClose={onClose} onAccept={handleConfirm}>
38
      onAccept={onSubmit}
30
      <TagsInput
39
    >
31
        label='Seleccionar habilidades'
40
      <TagsInput
32
        name='skills'
41
        suggestions={skills}
33
        options={skills}
42
        defaultValue={userSkills}
34
        defaultValues={currentValues}
Línea 43... Línea 35...
43
        onChange={(tags) => setValue('skills', tags)}
35
        onChange={(tags) => setValue('skills', tags)}