Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
6830 stevensc 1
import React, { useState, useEffect } from 'react'
2
import { useParams } from 'react-router-dom'
3
import { useSelector } from 'react-redux'
4
import { getBackendVars } from '../../services/backendVars'
5
import ProfileCard from '../../components/linkedin/profile/ProfileCard'
6
import ProfileWidget from '../../components/linkedin/profile/ProfileWidget'
7
import ExperienceCard from '../../components/linkedin/profile/cards/ExperienceCard'
8
import EducationCard from '../../components/linkedin/profile/cards/EducationCard'
9
import EmptySection from '../../components/UI/EmptySection'
10
import ItemsList from '../../components/linkedin/profile/cards/ItemsList'
11
import '../../styles/profile/profile.scss'
12
import ExperienceModal from '../../components/experiences/ExperienceModal'
13
import EducationModal from '../../components/educations/EducationModal'
14
import SkillsModal from '../../components/skills/SkillsModal'
15
import LanguagesModal from '../../components/languages/LanguagesModal'
16
import AptitudesModal from '../../components/aptitudes/AptitudesModal'
17
import HobbiesModal from '../../components/hobbies-and-interests/HobbiesModal'
18
import LocationModal from '../../components/location/LocationModal'
19
 
20
const View = () => {
21
  const [profile, setProfile] = useState({})
22
  const [experiences, setExperiences] = useState([])
23
  const [educations, setEducations] = useState([])
24
  const [languages, setLanguages] = useState([])
25
  const [skills, setSkills] = useState([])
26
  const [aptitudes, setAptitudes] = useState([])
27
  const [hobbiesAndInterests, setHobbiesAndInterests] = useState([])
28
  const [address, setAddress] = useState('')
29
  const [modalShow, setModalShow] = useState(null)
30
  const [settedDescription, setSettedDescription] = useState('')
31
  const [postUrl, setPostUrl] = useState('')
32
  const [isEdit, setIsEdit] = useState(false)
33
  const labels = useSelector(({ intl }) => intl.labels)
34
  const { uuid } = useParams()
35
 
36
  const handleEdit = (modalName, url, description) => {
37
    setModalShow(modalName)
38
    setPostUrl(url)
39
    setSettedDescription(description)
40
  }
41
 
42
  const handleAdd = (modalName, url) => {
43
    setModalShow(modalName)
44
    setPostUrl(url)
45
  }
46
 
47
  const closeModal = () => {
48
    setSettedDescription('')
49
    setPostUrl('')
50
    setIsEdit(false)
51
    setModalShow(null)
52
  }
53
 
54
  const renderModal = {
55
    Experiencia: (
56
      <ExperienceModal
57
        show={modalShow === 'Experiencia'}
58
        url={postUrl}
59
        isEdit={isEdit}
60
        onClose={closeModal}
61
        onComplete={(newExperiences) => setExperiences(newExperiences)}
62
      />
63
    ),
64
    Educación: (
65
      <EducationModal
66
        show={modalShow === 'Educación'}
67
        postUrl={postUrl}
68
        closeModal={closeModal}
69
        setEducations={(newEducations) => setEducations(newEducations)}
70
        settedDescription={settedDescription}
71
      />
72
    ),
73
    Habilidades: (
74
      <SkillsModal
75
        show={modalShow === 'Habilidades'}
76
        userSkills={skills}
77
        userId={profile?.user_profile_uuid}
78
        onClose={closeModal}
79
        onComplete={(newSkills) => setSkills(newSkills)}
80
      />
81
    ),
82
    Idiomas: (
83
      <LanguagesModal
84
        show={modalShow === 'Idiomas'}
85
        userId={profile?.user_profile_uuid}
86
        userLanguages={languages}
87
        onClose={closeModal}
88
        onComplete={(newLanguages) => setLanguages(newLanguages)}
89
      />
90
    ),
91
    Aptitudes: (
92
      <AptitudesModal
93
        show={modalShow === 'Aptitudes'}
94
        userId={profile?.user_profile_uuid}
95
        userAptitudes={aptitudes}
96
        onClose={closeModal}
97
        onComplete={(newAptitudes) => setAptitudes(newAptitudes)}
98
      />
99
    ),
100
    'Hobbies e Intereses': (
101
      <HobbiesModal
102
        onClose={closeModal}
103
        show={modalShow === 'Hobbies e Intereses'}
104
        userId={profile?.user_profile_uuid}
105
        userHobbies={hobbiesAndInterests}
106
        onComplete={(newHobbiesAndInterests) =>
107
          setHobbiesAndInterests(newHobbiesAndInterests)
108
        }
109
      />
110
    ),
111
    Ubicación: (
112
      <LocationModal
113
        show={modalShow === 'Ubicación'}
114
        onClose={() => setModalShow(null)}
115
        onComplete={(newAddress) => setAddress(newAddress)}
116
        id={profile?.user_profile_uuid}
117
      />
118
    ),
119
  }
120
 
121
  useEffect(() => {
6872 stevensc 122
    getBackendVars(`/profile/my-profiles/edit/${uuid}`)
6830 stevensc 123
      .then((vars) => {
124
        const {
125
          user_experiences,
126
          user_educations,
127
          user_hobbies_and_interests,
128
          user_skills,
129
          user_aptitudes,
130
          user_languages,
131
          formatted_address,
132
          ...profileInfo
133
        } = vars
134
 
135
        const attrAdapter = (attr) => {
136
          return Object.entries(attr).map(([key, value]) => {
137
            return { name: value, value: key }
138
          })
139
        }
140
 
141
        setExperiences(user_experiences)
142
        setEducations(user_educations)
143
        setAddress(formatted_address)
144
        setProfile(profileInfo)
145
        setHobbiesAndInterests(attrAdapter(user_hobbies_and_interests))
146
        setSkills(attrAdapter(user_skills))
147
        setAptitudes(attrAdapter(user_aptitudes))
148
        setLanguages(attrAdapter(user_languages))
149
      })
150
      .catch((err) => {
151
        console.log(`Error: ${err}`)
152
        throw new Error(err)
153
      })
154
  }, [])
155
 
156
  return (
157
    <>
158
      <main className="w-100">
159
        <div className="container">
160
          <div className="main d-flex flex-column" style={{ gap: '.5rem' }}>
161
            <ProfileCard {...profile} />
162
            <ProfileWidget
163
              title={labels.experience}
164
              onEdit={() => setIsEdit(!isEdit)}
165
              onAdd={handleAdd}
166
              addUrl={`/profile/my-profiles/experience/${profile?.user_profile_uuid}/operation/add`}
167
            >
168
              {experiences.length ? (
169
                experiences.map((experience, index) => (
170
                  <ExperienceCard
171
                    key={index}
172
                    isEdit={isEdit}
173
                    experience={experience}
174
                    onEdit={handleEdit}
175
                    onDelete={(newExperiences) =>
176
                      setExperiences(newExperiences)
177
                    }
178
                  />
179
                ))
180
              ) : (
181
                <EmptySection align="left" message={labels.empty} />
182
              )}
183
            </ProfileWidget>
184
            <ProfileWidget
185
              title={labels.education}
186
              onEdit={() => setIsEdit(!isEdit)}
187
              onAdd={handleAdd}
188
              addUrl={`/profile/my-profiles/education/${profile?.user_profile_uuid}/operation/add`}
189
            >
190
              {educations.length ? (
191
                educations.map((education, index) => (
192
                  <EducationCard key={index} education={education} />
193
                ))
194
              ) : (
195
                <EmptySection align="left" message={labels.empty} />
196
              )}
197
            </ProfileWidget>
198
            <ProfileWidget
199
              title={labels.location}
200
              onEdit={() => setModalShow('Ubicación')}
201
              justEdit
202
            >
203
              <div className="card__items">
204
                <p>{address}</p>
205
              </div>
206
            </ProfileWidget>
207
            <ProfileWidget
208
              title={labels.languages}
209
              onEdit={() => setModalShow('Idiomas')}
210
              justEdit
211
            >
212
              {languages.length ? (
213
                <ItemsList value={languages} />
214
              ) : (
215
                <EmptySection align="left" message={labels.empty} />
216
              )}
217
            </ProfileWidget>
218
            <ProfileWidget
219
              title={labels.skills}
220
              onEdit={() => setModalShow('Habilidades')}
221
              justEdit
222
            >
223
              {skills.length ? (
224
                <ItemsList value={skills} />
225
              ) : (
226
                <EmptySection align="left" message={labels.empty} />
227
              )}
228
            </ProfileWidget>
229
            <ProfileWidget
230
              title={labels.aptitudes}
231
              onEdit={() => setModalShow('Aptitudes')}
232
              justEdit
233
            >
234
              {aptitudes.length ? (
235
                <ItemsList value={aptitudes} />
236
              ) : (
237
                <EmptySection align="left" message={labels.empty} />
238
              )}
239
            </ProfileWidget>
240
            <ProfileWidget
241
              title={labels.hobbies_and_interests}
242
              onEdit={() => setModalShow('Hobbies e Intereses')}
243
              justEdit
244
            >
245
              {hobbiesAndInterests.length ? (
246
                <ItemsList value={hobbiesAndInterests} />
247
              ) : (
248
                <EmptySection align="left" message={labels.empty} />
249
              )}
250
            </ProfileWidget>
251
          </div>
252
        </div>
253
      </main>
254
      {renderModal[modalShow]}
255
    </>
256
  )
257
}
258
 
259
export default View