Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1866 | Rev 1979 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1862 stevensc 1
import React, { useEffect, useState } from 'react'
1854 stevensc 2
import { useDispatch, useSelector } from 'react-redux'
3
import { IconButton } from '@mui/material'
4
import { Edit } from '@mui/icons-material'
5
 
1857 stevensc 6
import { updateSkills } from '@app/services/profiles'
1854 stevensc 7
import { addNotification } from '@app/redux/notification/notification.actions'
8
 
9
import TagsList from '@app/components/UI/TagsList'
10
import ProfileWidget from '../ProfileWidget'
11
import SkillsModal from './SkillsModal'
12
 
13
const SkillsCard = ({
1866 stevensc 14
  skills: defaultSkills = [],
1854 stevensc 15
  uuid = '',
16
  edit = false
17
}) => {
18
  const [skills, setSkills] = useState([])
19
  const [showModal, setShowModal] = useState(false)
20
  const labels = useSelector(({ intl }) => intl.labels)
21
  const dispatch = useDispatch()
22
 
23
  const toggleModal = () => setShowModal(!showModal)
24
 
25
  const handleEditSkills = ({ skills }) => {
1978 stevensc 26
    const skillsValues = skills.map((skills) => skills.value)
27
    updateSkills(uuid, skillsValues)
1854 stevensc 28
      .then(({ data: response }) => {
29
        const { data, success } = response
30
        if (!success) {
31
          const errorMessage = typeof data === 'string' ? data : data.skills[0]
32
          throw new Error(errorMessage)
33
        }
34
 
35
        toggleModal()
36
        setSkills(skills)
37
      })
38
      .catch((error) => {
39
        dispatch(addNotification({ style: 'danger', msg: error.message }))
40
      })
41
  }
42
 
43
  useEffect(() => {
1862 stevensc 44
    setSkills(defaultSkills)
45
  }, [defaultSkills])
1854 stevensc 46
 
47
  return (
48
    <>
49
      <ProfileWidget
50
        title={labels.skills}
51
        action={
52
          edit && (
53
            <IconButton onClick={toggleModal}>
54
              <Edit />
55
            </IconButton>
56
          )
57
        }
58
      >
59
        <TagsList tags={skills} />
60
      </ProfileWidget>
61
 
62
      <SkillsModal
63
        show={showModal}
64
        onClose={toggleModal}
65
        onConfirm={handleEditSkills}
66
        skills={skills}
67
      />
68
    </>
69
  )
70
}
71
 
72
export default SkillsCard