| 5473 | stevensc | 1 | /* eslint-disable react/prop-types */
 | 
        
           |  |  | 2 | import React from "react";
 | 
        
           |  |  | 3 | import { useState, useRef } from "react";
 | 
        
           |  |  | 4 | import Education from "./education/Education";
 | 
        
           |  |  | 5 | import Spinner from "../../../../shared/loading-spinner/Spinner";
 | 
        
           |  |  | 6 | import EducationModal from "./education/EducationModal";
 | 
        
           |  |  | 7 | import { axios } from "../../../../utils";
 | 
        
           |  |  | 8 |   | 
        
           |  |  | 9 | const Educations = (props) => {
 | 
        
           |  |  | 10 |   // props destructuring
 | 
        
           |  |  | 11 |   const {
 | 
        
           |  |  | 12 |     userEducations,
 | 
        
           |  |  | 13 |     degreesOptions,
 | 
        
           |  |  | 14 |     userIdEncrypted,
 | 
        
           |  |  | 15 |   } = props;
 | 
        
           |  |  | 16 |   const [isModalOpen, setIsModalOpen] = useState(false);
 | 
        
           |  |  | 17 |   const [loading, setLoading] = useState(false);
 | 
        
           |  |  | 18 |   const [settedEducations, setSettedEducations] = useState(userEducations);
 | 
        
           |  |  | 19 |   const [settedDescription, setSettedDescription] = useState("");
 | 
        
           |  |  | 20 |   | 
        
           |  |  | 21 |   const postUrl = useRef("");
 | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 |   const addEducation = () => {
 | 
        
           |  |  | 24 |     postUrl.current = `/profile/my-profiles/education/${userIdEncrypted}/operation/add`;
 | 
        
           |  |  | 25 |     setSettedDescription("");
 | 
        
           |  |  | 26 |     setIsModalOpen(true);
 | 
        
           |  |  | 27 |   };
 | 
        
           |  |  | 28 |   | 
        
           |  |  | 29 |   const handleDelete = async (delete_link) => {
 | 
        
           |  |  | 30 |     setLoading(true);
 | 
        
           |  |  | 31 |     await axios.post(delete_link).then((response) => {
 | 
        
           |  |  | 32 |       const resData = response.data;
 | 
        
           |  |  | 33 |       if (resData.success) setSettedEducations(resData.data)
 | 
        
           |  |  | 34 |     });
 | 
        
           |  |  | 35 |     setLoading(false);
 | 
        
           |  |  | 36 |   };
 | 
        
           |  |  | 37 |   | 
        
           |  |  | 38 |   const handleEdit = async (edit_link) => {
 | 
        
           |  |  | 39 |     postUrl.current = edit_link;
 | 
        
           |  |  | 40 |     const currentDescription = settedEducations.find(education => education.link_edit === edit_link)
 | 
        
           |  |  | 41 |     setSettedDescription(currentDescription.description)
 | 
        
           |  |  | 42 |     setIsModalOpen(true)
 | 
        
           |  |  | 43 |   };
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 |   return (
 | 
        
           |  |  | 46 |     <>
 | 
        
           |  |  | 47 |       <div className="user-profile-extended-ov position-relative">
 | 
        
           |  |  | 48 |         <h3 className="d-flex">
 | 
        
           |  |  | 49 |           Educación
 | 
        
           |  |  | 50 |           <div className="ml-1">
 | 
        
           |  |  | 51 |             <a
 | 
        
           |  |  | 52 |               href="#"
 | 
        
           |  |  | 53 |               title=""
 | 
        
           |  |  | 54 |               className="btn-education-add"
 | 
        
           |  |  | 55 |               onClick={addEducation}
 | 
        
           |  |  | 56 |             >
 | 
        
           |  |  | 57 |               <i className="fa fa-plus-square"></i>
 | 
        
           |  |  | 58 |             </a>
 | 
        
           |  |  | 59 |           </div>
 | 
        
           |  |  | 60 |         </h3>
 | 
        
           |  |  | 61 |         <span>
 | 
        
           |  |  | 62 |           {
 | 
        
           |  |  | 63 |             settedEducations.length
 | 
        
           |  |  | 64 |               ? settedEducations.map((userEducation, id) =>
 | 
        
           |  |  | 65 |                 <Education
 | 
        
           |  |  | 66 |                   key={id}
 | 
        
           |  |  | 67 |                   id={id}
 | 
        
           |  |  | 68 |                   userEducation={userEducation}
 | 
        
           |  |  | 69 |                   onDelete={handleDelete}
 | 
        
           |  |  | 70 |                   onEdit={handleEdit}
 | 
        
           |  |  | 71 |                 />
 | 
        
           |  |  | 72 |               )
 | 
        
           |  |  | 73 |               : 'Sin información'
 | 
        
           |  |  | 74 |           }
 | 
        
           |  |  | 75 |         </span>
 | 
        
           |  |  | 76 |         {loading && <Spinner />}
 | 
        
           |  |  | 77 |       </div>
 | 
        
           |  |  | 78 |       <EducationModal
 | 
        
           |  |  | 79 |         degreesOptions={degreesOptions}
 | 
        
           |  |  | 80 |         closeModal={() => setIsModalOpen(false)}
 | 
        
           |  |  | 81 |         postUrl={postUrl.current}
 | 
        
           |  |  | 82 |         setEducations={(newEducations) => setSettedEducations(newEducations)}
 | 
        
           |  |  | 83 |         settedDescription={settedDescription}
 | 
        
           |  |  | 84 |         show={isModalOpen}
 | 
        
           |  |  | 85 |       />
 | 
        
           |  |  | 86 |     </>
 | 
        
           |  |  | 87 |   );
 | 
        
           |  |  | 88 | };
 | 
        
           |  |  | 89 |   | 
        
           |  |  | 90 | export default Educations;
 |