Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5481 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5473 stevensc 1
/* eslint-disable react/prop-types */
5475 stevensc 2
import React, { useState, useRef } from 'react'
3
import { axios } from '../../../utils'
4
import { useDispatch, useSelector } from 'react-redux'
5
import { addNotification } from '../../../redux/notification/notification.actions'
5473 stevensc 6
 
5475 stevensc 7
import ExperienceItem from './ExperienceItem'
8
import ExperienceModal from './ExperienceModal'
9
import EmptySection from '../../../shared/empty-section/EmptySection'
10
import IconButton from '@mui/material/IconButton'
11
import AddIcon from '@mui/icons-material/Add'
5473 stevensc 12
 
5475 stevensc 13
const Experiences = ({
14
  experiences,
15
  months,
16
  companySizesOptions,
17
  industriesOptions,
18
  userId,
19
  isEdit,
20
}) => {
5473 stevensc 21
  const [isModalOpen, setIsModalOpen] = useState(false)
22
  const [settedDescription, setSettedDescription] = useState('')
5475 stevensc 23
  const [settedExperiences, setSettedExperiences] = useState(experiences)
5473 stevensc 24
 
5475 stevensc 25
  const labels = useSelector((state) => state.labels)
26
  const dispatch = useDispatch()
27
 
5473 stevensc 28
  const postUrl = useRef('')
29
 
5475 stevensc 30
  const handleDelete = (deleteUrl) => {
31
    axios.post(deleteUrl).then(({ data: response }) => {
32
      if (!response.success) {
33
        dispatch(addNotification({ style: 'danger', msg: response.data }))
34
      }
35
      setSettedExperiences(response.data)
36
    })
37
  }
5473 stevensc 38
 
5475 stevensc 39
  const addExperience = () => {
40
    postUrl.current = `/profile/my-profiles/experience/${userId}/operation/add`
5473 stevensc 41
    setSettedDescription('')
42
    setIsModalOpen(true)
43
  }
44
 
45
  const handleEdit = async (linkEdit) => {
46
    postUrl.current = linkEdit
5475 stevensc 47
    const currentDescription = settedExperiences.find(
48
      (experience) => experience.link_edit === linkEdit
49
    )
5473 stevensc 50
    setSettedDescription(currentDescription.description)
51
    setIsModalOpen(true)
52
  }
53
 
54
  return (
55
    <>
5475 stevensc 56
      <div className="profile-attr">
57
        <div className="profile-attr-header">
5481 stevensc 58
          <h2>Experiencia</h2>
5475 stevensc 59
          {isEdit && (
60
            <IconButton onClick={addExperience}>
61
              <AddIcon />
62
            </IconButton>
63
          )}
64
        </div>
65
        {settedExperiences.length ? (
66
          settedExperiences.map((experience) => (
67
            <ExperienceItem
68
              key={`${experience.company} - ${experience.title}`}
69
              experience={experience}
70
              months={months}
71
              onDelete={handleDelete}
72
              onEdit={handleEdit}
5488 stevensc 73
              isEdit={isEdit}
5475 stevensc 74
            />
75
          ))
76
        ) : (
77
          <EmptySection align="left" message={labels.EMPTY} />
78
        )}
5473 stevensc 79
      </div>
80
      <ExperienceModal
81
        closeModal={() => setIsModalOpen(false)}
82
        companySizesOptions={companySizesOptions}
83
        industriesOptions={industriesOptions}
84
        months={months}
85
        postUrl={postUrl.current}
5475 stevensc 86
        setUserExperiences={(value) => setSettedExperiences(value)}
5473 stevensc 87
        settedDescription={settedDescription}
88
        show={isModalOpen}
89
      />
90
    </>
91
  )
92
}
93
 
94
export default Experiences