Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3309 Rev 3313
Línea 1... Línea 1...
1
import React from 'react'
1
import React from 'react'
2
import { useDispatch } from 'react-redux'
2
import { useNavigate } from 'react-router-dom'
3
import { useForm } from 'react-hook-form'
-
 
4
import {
-
 
5
  Accordion,
-
 
6
  AccordionDetails,
-
 
7
  AccordionSummary,
-
 
8
  Button,
-
 
9
  Typography
-
 
10
} from '@mui/material'
-
 
11
import { ExpandMore } from '@mui/icons-material'
-
 
12
 
-
 
13
import { saveProgress } from '@services/habits/habits'
-
 
14
import { addNotification } from '@store/notification/notification.actions'
-
 
Línea 15... Línea 3...
15
 
3
 
16
import Widget from '@components/UI/Widget'
-
 
17
import Form from '@components/common/form'
-
 
18
import Input from '@components/UI/inputs/Input'
-
 
19
import Ckeditor from '@components/common/ckeditor/Ckeditor'
-
 
Línea 20... Línea 4...
20
import LoadingWrapper from '@components/common/loading-wrapper'
4
import Widget from '@components/UI/Widget'
21
 
5
 
22
export default function ProgressItem({ habit }) {
-
 
23
  const dispatch = useDispatch()
-
 
24
 
-
 
25
  const { uuid, name, link } = habit
-
 
26
 
-
 
27
  const {
-
 
28
    handleSubmit,
-
 
29
    control,
-
 
30
    formState: { errors, isSubmitting }
-
 
31
  } = useForm({
-
 
32
    defaultValues: {}
-
 
33
  })
-
 
34
 
-
 
35
  function getCurrentDate() {
-
 
36
    const date = new Date()
-
 
37
    const year = date.getFullYear()
-
 
38
    const month = String(date.getMonth() + 1).padStart(2, '0') // Enero es 0
-
 
39
    const day = String(date.getDate()).padStart(2, '0')
-
 
40
    const hours = String(date.getHours()).padStart(2, '0')
-
 
41
    const minutes = String(date.getMinutes()).padStart(2, '0')
-
 
42
    const seconds = String(date.getSeconds()).padStart(2, '0')
-
 
Línea 43... Línea -...
43
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
-
 
44
  }
-
 
45
 
6
export default function ProgressItem({ habit }) {
46
  const onSubmit = handleSubmit(async (data) => {
-
 
47
    try {
-
 
48
      const date = getCurrentDate()
-
 
49
      const response = await saveProgress(link, { ...data, date })
-
 
50
      console.log(response)
-
 
51
    } catch (error) {
-
 
Línea 52... Línea 7...
52
      dispatch(addNotification({ style: 'danger', msg: error.message }))
7
  const navigate = useNavigate()
53
    }
8
 
54
  })
-
 
55
 
-
 
56
  return (
-
 
57
    <Widget>
-
 
58
      <Widget.Body>
-
 
59
        <Accordion
-
 
60
          sx={{
-
 
61
            border: 'none',
-
 
62
            width: '100%',
-
 
63
            boxShadow: 'none',
-
 
64
            padding: 0,
-
 
65
            '&::before': {
-
 
66
              display: 'none'
-
 
67
            }
-
 
68
          }}
-
 
69
        >
-
 
70
          <AccordionSummary
-
 
71
            sx={{ padding: '0.5rem 0 !important' }}
-
 
72
            expandIcon={<ExpandMore />}
-
 
73
          >
-
 
74
            <Typography variant='h2'>{name}</Typography>
-
 
75
          </AccordionSummary>
-
 
76
 
-
 
77
          <AccordionDetails sx={{ padding: 0 }}>
-
 
78
            <Form onSubmit={onSubmit} id={`${uuid}_progress-form`}>
-
 
79
              <LoadingWrapper loading={isSubmitting} displayChildren>
-
 
80
                <Input
-
 
81
                  control={control}
9
  const { uuid, name } = habit
82
                  label='Valor cuantitativo:'
-
 
83
                  name='quantitative_value'
-
 
84
                  type='number'
-
 
85
                  rules={{ required: 'El valor es requerido' }}
-
 
86
                  error={errors.quantitative_value?.message}
-
 
87
                />
-
 
88
 
-
 
89
                <Ckeditor
-
 
90
                  control={control}
-
 
91
                  name='qualitative_description'
-
 
92
                  error={errors.qualitative_description?.message}
-
 
93
                  rules={{ required: 'La descripción es requerida' }}
-
 
94
                  label='Descripción cualitativa:'
-
 
95
                />
-
 
96
 
-
 
97
                <Button
-
 
98
                  color='primary'
-
 
99
                  type='submit'
-
 
100
                  form={`${uuid}_progress-form`}
-
 
101
                >
-
 
102
                  Enviar
-
 
103
                </Button>
-
 
104
              </LoadingWrapper>
-
 
105
            </Form>
10
 
106
          </AccordionDetails>
11
  return (
107
        </Accordion>
12
    <Widget>