Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5475 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5473 stevensc 1
/* eslint-disable react/prop-types */
2
import React from 'react'
3
import { useState, useRef } from 'react'
4
import Experience from './experience/Experience'
5
import Spinner from '../../../../shared/loading-spinner/Spinner'
6
import ExperienceModal from './experience/ExperienceModal'
7
 
8
const Experiences = (props) => {
9
  // props destructuring
10
  const {
11
    userExperiences,
12
    months,
13
    companySizesOptions,
14
    industriesOptions,
15
    userIdEncrypted
16
  } = props
17
 
18
  // states
19
  const [isModalOpen, setIsModalOpen] = useState(false)
20
  const [loading, setLoading] = useState(false)
21
  const [settedUserExperiences, setSettedUserExperiences] = useState(userExperiences)
22
  const [settedDescription, setSettedDescription] = useState('')
23
 
24
  // refs
25
  const postUrl = useRef('')
26
 
27
  const handleDelete = async (newUserExperiences) => setSettedUserExperiences(newUserExperiences)
28
 
29
  const addExperience = (event) => {
30
    event.preventDefault()
31
    postUrl.current = `/profile/my-profiles/experience/${userIdEncrypted}/operation/add`
32
    setSettedDescription('')
33
    setIsModalOpen(true)
34
  }
35
 
36
  const handleEdit = async (linkEdit) => {
37
    postUrl.current = linkEdit
38
    const currentDescription = settedUserExperiences.find(experience => experience.link_edit === linkEdit)
39
    setSettedDescription(currentDescription.description)
40
    setIsModalOpen(true)
41
  }
42
 
43
  return (
44
    <>
45
      <div className="user-profile-extended-ov st2 position-relative">
46
        <h3 style={{ display: 'flex' }}>
47
          Experiencia
48
          <div style={{ marginLeft: '5px' }}>
49
            <a
50
              href="#"
51
              className="btn-experience-add"
52
              onClick={addExperience}
53
            >
54
              <i className="fa fa-plus-square" />
55
            </a>
56
          </div>
57
        </h3>
58
        <span>
59
          {settedUserExperiences.length
60
            ? settedUserExperiences.map((userExperience, id) =>
61
              <Experience
62
                key={id}
63
                userExperience={userExperience}
64
                months={months}
65
                id={id}
66
                onDelete={handleDelete}
67
                setLoading={setLoading}
68
                handleEdit={handleEdit}
69
              />
70
            )
71
            : 'Sin información'
72
          }
73
        </span>
74
        {loading && <Spinner />}
75
      </div>
76
      <ExperienceModal
77
        closeModal={() => setIsModalOpen(false)}
78
        companySizesOptions={companySizesOptions}
79
        industriesOptions={industriesOptions}
80
        months={months}
81
        postUrl={postUrl.current}
82
        setUserExperiences={(value) => setSettedUserExperiences(value)}
83
        settedDescription={settedDescription}
84
        show={isModalOpen}
85
      />
86
    </>
87
  )
88
}
89
 
90
export default Experiences