Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1979 | Rev 3047 | 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
 
3040 stevensc 6
import { updateSkills } from '@services/profile/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 }) => {
1979 stevensc 26
    updateSkills(uuid, skills)
1854 stevensc 27
      .then(({ data: response }) => {
28
        const { data, success } = response
29
        if (!success) {
30
          const errorMessage = typeof data === 'string' ? data : data.skills[0]
31
          throw new Error(errorMessage)
32
        }
33
 
34
        toggleModal()
35
        setSkills(skills)
36
      })
37
      .catch((error) => {
38
        dispatch(addNotification({ style: 'danger', msg: error.message }))
39
      })
40
  }
41
 
42
  useEffect(() => {
1862 stevensc 43
    setSkills(defaultSkills)
44
  }, [defaultSkills])
1854 stevensc 45
 
46
  return (
47
    <>
48
      <ProfileWidget
49
        title={labels.skills}
50
        action={
51
          edit && (
52
            <IconButton onClick={toggleModal}>
53
              <Edit />
54
            </IconButton>
55
          )
56
        }
57
      >
58
        <TagsList tags={skills} />
59
      </ProfileWidget>
60
 
61
      <SkillsModal
62
        show={showModal}
63
        onClose={toggleModal}
64
        onConfirm={handleEditSkills}
65
        skills={skills}
66
      />
67
    </>
68
  )
69
}
70
 
71
export default SkillsCard