Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
224 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";
5 stevensc 19
 
20
const View = () => {
224 stevensc 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();
5 stevensc 35
 
36
  const handleEdit = (modalName, url, description) => {
224 stevensc 37
    setModalShow(modalName);
38
    setPostUrl(url);
39
    setSettedDescription(description);
40
  };
5 stevensc 41
 
42
  const handleAdd = (modalName, url) => {
224 stevensc 43
    setModalShow(modalName);
44
    setPostUrl(url);
45
  };
5 stevensc 46
 
47
  const closeModal = () => {
224 stevensc 48
    setSettedDescription("");
49
    setPostUrl("");
50
    setIsEdit(false);
51
    setModalShow(null);
52
  };
5 stevensc 53
 
54
  const renderModal = {
55
    Experiencia: (
56
      <ExperienceModal
224 stevensc 57
        show={modalShow === "Experiencia"}
5 stevensc 58
        url={postUrl}
59
        isEdit={isEdit}
60
        onClose={closeModal}
61
        onComplete={(newExperiences) => setExperiences(newExperiences)}
62
      />
63
    ),
64
    Educación: (
65
      <EducationModal
224 stevensc 66
        show={modalShow === "Educación"}
5 stevensc 67
        postUrl={postUrl}
68
        closeModal={closeModal}
69
        setEducations={(newEducations) => setEducations(newEducations)}
70
        settedDescription={settedDescription}
71
      />
72
    ),
73
    Habilidades: (
74
      <SkillsModal
224 stevensc 75
        show={modalShow === "Habilidades"}
5 stevensc 76
        userSkills={skills}
77
        userId={profile?.user_profile_uuid}
78
        onClose={closeModal}
79
        onComplete={(newSkills) => setSkills(newSkills)}
80
      />
81
    ),
82
    Idiomas: (
83
      <LanguagesModal
224 stevensc 84
        show={modalShow === "Idiomas"}
5 stevensc 85
        userId={profile?.user_profile_uuid}
86
        userLanguages={languages}
87
        onClose={closeModal}
88
        onComplete={(newLanguages) => setLanguages(newLanguages)}
89
      />
90
    ),
91
    Aptitudes: (
92
      <AptitudesModal
224 stevensc 93
        show={modalShow === "Aptitudes"}
5 stevensc 94
        userId={profile?.user_profile_uuid}
95
        userAptitudes={aptitudes}
96
        onClose={closeModal}
97
        onComplete={(newAptitudes) => setAptitudes(newAptitudes)}
98
      />
99
    ),
224 stevensc 100
    "Hobbies e Intereses": (
5 stevensc 101
      <HobbiesModal
102
        onClose={closeModal}
224 stevensc 103
        show={modalShow === "Hobbies e Intereses"}
5 stevensc 104
        userId={profile?.user_profile_uuid}
105
        userHobbies={hobbiesAndInterests}
106
        onComplete={(newHobbiesAndInterests) =>
107
          setHobbiesAndInterests(newHobbiesAndInterests)
108
        }
109
      />
110
    ),
111
    Ubicación: (
112
      <LocationModal
224 stevensc 113
        show={modalShow === "Ubicación"}
5 stevensc 114
        onClose={() => setModalShow(null)}
115
        onComplete={(newAddress) => setAddress(newAddress)}
116
        id={profile?.user_profile_uuid}
117
      />
118
    ),
224 stevensc 119
  };
5 stevensc 120
 
121
  useEffect(() => {
122
    getBackendVars(`/profile/my-profiles/edit/${uuid}`)
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
224 stevensc 133
        } = vars;
5 stevensc 134
 
135
        const attrAdapter = (attr) => {
136
          return Object.entries(attr).map(([key, value]) => {
224 stevensc 137
            return { name: value, value: key };
138
          });
139
        };
5 stevensc 140
 
224 stevensc 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));
5 stevensc 149
      })
150
      .catch((err) => {
224 stevensc 151
        console.log(`Error: ${err}`);
152
        throw new Error(err);
153
      });
154
  }, []);
5 stevensc 155
 
156
  return (
157
    <>
158
      <main className="w-100">
159
        <div className="container">
224 stevensc 160
          <div className="main d-flex flex-column" style={{ gap: ".5rem" }}>
5 stevensc 161
            <ProfileCard
162
              {...profile}
163
              sizes={{
164
                image: profile.image_size_profile,
165
                cover: profile.image_size_cover,
166
              }}
167
              uuid={profile.user_uuid}
224 stevensc 168
              image={profile.image}
169
              cover={profile.cover}
5 stevensc 170
            />
171
            <ProfileWidget
172
              title={labels.experience}
173
              onEdit={() => setIsEdit(!isEdit)}
174
              onAdd={handleAdd}
175
              addUrl={`/profile/my-profiles/experience/${uuid}/operation/add`}
176
            >
177
              {experiences.length ? (
178
                experiences.map((experience, index) => (
179
                  <ExperienceCard
180
                    key={index}
181
                    isEdit={isEdit}
182
                    experience={experience}
183
                    onEdit={handleEdit}
184
                    onDelete={(newExperiences) =>
185
                      setExperiences(newExperiences)
186
                    }
187
                  />
188
                ))
189
              ) : (
190
                <EmptySection align="left" message={labels.empty} />
191
              )}
192
            </ProfileWidget>
193
            <ProfileWidget
194
              title={labels.education}
195
              onEdit={() => setIsEdit(!isEdit)}
196
              onAdd={handleAdd}
197
              addUrl={`/profile/my-profiles/education/${profile?.user_profile_uuid}/operation/add`}
198
            >
199
              {educations.length ? (
200
                educations.map((education, index) => (
201
                  <EducationCard key={index} education={education} />
202
                ))
203
              ) : (
204
                <EmptySection align="left" message={labels.empty} />
205
              )}
206
            </ProfileWidget>
207
            <ProfileWidget
208
              title={labels.location}
224 stevensc 209
              onEdit={() => setModalShow("Ubicación")}
5 stevensc 210
              justEdit
211
            >
212
              <div className="card__items">
213
                <p>{address}</p>
214
              </div>
215
            </ProfileWidget>
216
            <ProfileWidget
217
              title={labels.languages}
224 stevensc 218
              onEdit={() => setModalShow("Idiomas")}
5 stevensc 219
              justEdit
220
            >
221
              {languages.length ? (
222
                <ItemsList value={languages} />
223
              ) : (
224
                <EmptySection align="left" message={labels.empty} />
225
              )}
226
            </ProfileWidget>
227
            <ProfileWidget
228
              title={labels.skills}
224 stevensc 229
              onEdit={() => setModalShow("Habilidades")}
5 stevensc 230
              justEdit
231
            >
232
              {skills.length ? (
233
                <ItemsList value={skills} />
234
              ) : (
235
                <EmptySection align="left" message={labels.empty} />
236
              )}
237
            </ProfileWidget>
238
            <ProfileWidget
239
              title={labels.aptitudes}
224 stevensc 240
              onEdit={() => setModalShow("Aptitudes")}
5 stevensc 241
              justEdit
242
            >
243
              {aptitudes.length ? (
244
                <ItemsList value={aptitudes} />
245
              ) : (
246
                <EmptySection align="left" message={labels.empty} />
247
              )}
248
            </ProfileWidget>
249
            <ProfileWidget
250
              title={labels.hobbies_and_interests}
224 stevensc 251
              onEdit={() => setModalShow("Hobbies e Intereses")}
5 stevensc 252
              justEdit
253
            >
254
              {hobbiesAndInterests.length ? (
255
                <ItemsList value={hobbiesAndInterests} />
256
              ) : (
257
                <EmptySection align="left" message={labels.empty} />
258
              )}
259
            </ProfileWidget>
260
          </div>
261
        </div>
262
      </main>
263
      {renderModal[modalShow]}
264
    </>
224 stevensc 265
  );
266
};
5 stevensc 267
 
224 stevensc 268
export default View;