| 3719 |
stevensc |
1 |
import React from 'react';
|
|
|
2 |
import { useSelector } from 'react-redux';
|
|
|
3 |
import Add from '@mui/icons-material/Add';
|
|
|
4 |
import { IconButton } from '@mui/material';
|
|
|
5 |
|
|
|
6 |
import { addEducation, deleteEducation, editEducation } from '@services/profile/education';
|
|
|
7 |
import { useResource } from '@hooks';
|
|
|
8 |
|
|
|
9 |
import Widget from '@components/UI/Widget';
|
|
|
10 |
import EducationItem from './education-item';
|
|
|
11 |
import EducationModal from './education-modal';
|
|
|
12 |
import EmptySection from '@components/UI/EmptySection';
|
|
|
13 |
import ConfirmModal from '@components/modals/ConfirmModal';
|
|
|
14 |
|
|
|
15 |
const EducationsCard = ({ uuid = '', educations = [], edit = false }) => {
|
|
|
16 |
const labels = useSelector(({ intl }) => intl.labels);
|
|
|
17 |
|
|
|
18 |
const { showModal, modalState, onAdd, onEdit, onDelete, resources, clearModal, currentResource } =
|
|
|
19 |
useResource({
|
|
|
20 |
defaultResources: educations,
|
|
|
21 |
addResource: addEducation,
|
|
|
22 |
editResource: editEducation,
|
|
|
23 |
deleteResource: deleteEducation
|
|
|
24 |
});
|
|
|
25 |
|
|
|
26 |
return (
|
|
|
27 |
<>
|
|
|
28 |
<Widget>
|
|
|
29 |
<Widget.Header
|
|
|
30 |
title={labels.education}
|
|
|
31 |
renderAction={() => {
|
|
|
32 |
if (!edit) return null;
|
|
|
33 |
return (
|
|
|
34 |
<IconButton onClick={() => showModal('add')}>
|
|
|
35 |
<Add />
|
|
|
36 |
</IconButton>
|
|
|
37 |
);
|
|
|
38 |
}}
|
|
|
39 |
/>
|
|
|
40 |
|
|
|
41 |
<Widget.Body>
|
|
|
42 |
{resources.length ? (
|
|
|
43 |
resources.map((education) => (
|
|
|
44 |
<EducationItem
|
|
|
45 |
key={education}
|
|
|
46 |
education={education}
|
|
|
47 |
onEdit={() => showModal('edit', education)}
|
|
|
48 |
onDelete={() => showModal('delete', education)}
|
|
|
49 |
edit={edit}
|
|
|
50 |
/>
|
|
|
51 |
))
|
|
|
52 |
) : (
|
|
|
53 |
<EmptySection align='left' message={labels.datatable_empty} />
|
|
|
54 |
)}
|
|
|
55 |
</Widget.Body>
|
|
|
56 |
</Widget>
|
|
|
57 |
|
|
|
58 |
<EducationModal
|
|
|
59 |
show={modalState === 'add' || modalState === 'edit'}
|
|
|
60 |
currentEducation={currentResource}
|
|
|
61 |
onClose={clearModal}
|
|
|
62 |
onConfirm={(education) => {
|
|
|
63 |
console.log(modalState);
|
|
|
64 |
if (modalState === 'add') onAdd(uuid, education);
|
|
|
65 |
if (modalState === 'edit') onEdit(education);
|
|
|
66 |
}}
|
|
|
67 |
/>
|
|
|
68 |
|
|
|
69 |
<ConfirmModal
|
|
|
70 |
show={modalState === 'delete'}
|
|
|
71 |
title='Eliminar Educación'
|
|
|
72 |
message='¿Esta seguro de eliminar esta educación?'
|
|
|
73 |
onAccept={onDelete}
|
|
|
74 |
onClose={clearModal}
|
|
|
75 |
/>
|
|
|
76 |
</>
|
|
|
77 |
);
|
|
|
78 |
};
|
|
|
79 |
|
|
|
80 |
export default EducationsCard;
|