Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3319 | Rev 3321 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3319 Rev 3320
Línea 1... Línea 1...
1
import React from 'react'
1
import React, { useState } from 'react'
2
import { useNavigate } from 'react-router-dom'
2
import { useNavigate } from 'react-router-dom'
-
 
3
import { useDispatch } from 'react-redux'
-
 
4
import { Typography } from '@mui/material'
-
 
5
 
-
 
6
import { useHabitProgress } from '@hooks'
-
 
7
import { deleteProgress } from '@services/habits/habits'
-
 
8
import { addNotification } from '@store/notification/notification.actions'
Línea 3... Línea 9...
3
 
9
 
-
 
10
import Widget from '@components/UI/Widget'
-
 
11
import Options from '@components/UI/Option'
Línea 4... Línea 12...
4
import Widget from '@components/UI/Widget'
12
import ConfirmModal from '@components/modals/ConfirmModal'
-
 
13
 
5
 
14
export default function ProgressItem({ progress }) {
-
 
15
  const [show, setShow] = useState(false)
-
 
16
  const navigate = useNavigate()
-
 
17
  const dispatch = useDispatch()
-
 
18
 
-
 
19
  const { id, date, quantitative_value, qualitative_description, actions } =
-
 
20
    progress
-
 
21
  const formatDate = new Intl.DateTimeFormat('es', {
-
 
22
    dateStyle: 'full',
-
 
23
    timeStyle: 'medium',
-
 
24
    timeZone: 'America/Bogota'
-
 
25
  }).format(date)
-
 
26
 
Línea -... Línea 27...
-
 
27
  const { removeItem, getItemById } = useHabitProgress()
-
 
28
  const currentRegister = getItemById(id)
6
export default function ProgressItem({ habit }) {
29
 
-
 
30
  const toggleConfirmModal = () => setShow(!show)
-
 
31
 
-
 
32
  const handleDelete = async () => {
-
 
33
    try {
-
 
34
      const response = await deleteProgress(
-
 
35
        currentRegister?.actions.link_delete
-
 
36
      )
-
 
37
      dispatch(addNotification({ style: 'success', msg: response }))
-
 
38
      removeItem(id)
-
 
39
    } catch (error) {
Línea 7... Línea 40...
7
  const navigate = useNavigate()
40
      dispatch(addNotification({ style: 'danger', msg: error.message }))
-
 
41
    }
-
 
42
  }
-
 
43
 
-
 
44
  return (
-
 
45
    <>
-
 
46
      <Widget>
-
 
47
        <Widget.Header
-
 
48
          title={formatDate}
8
 
49
          subheader={quantitative_value}
-
 
50
          renderAction={() => (
-
 
51
            <Options>
-
 
52
              {actions.link_edit && (
-
 
53
                <Options.Item onClick={() => navigate(`edit/${id}`)}>
-
 
54
                  Editar
-
 
55
                </Options.Item>
-
 
56
              )}
-
 
57
              {actions.link_delete && (
-
 
58
                <Options.Item onClick={toggleConfirmModal}>Borrar</Options.Item>
-
 
59
              )}
9
  const { uuid, name } = habit
60
            </Options>
-
 
61
          )}
-
 
62
        />
10
 
63
 
-
 
64
        <Widget.Body>
-
 
65
          <Typography>{qualitative_description}</Typography>
-
 
66
        </Widget.Body>
-
 
67
      </Widget>
-
 
68
      <ConfirmModal
-
 
69
        show={show}
-
 
70
        title='Borrar'
-
 
71
        message='¿Estás seguro de que deseas borrar este registro?'
11
  return (
72
        onAccept={handleDelete}
12
    <Widget styles={{ cursor: 'pointer' }} onClick={() => navigate(uuid)}>
73
        onClose={toggleConfirmModal}