Proyectos de Subversion LeadersLinked - SPA

Rev

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

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