Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3313 Rev 3315
Línea 2... Línea 2...
2
import { useParams } from 'react-router-dom'
2
import { useParams } from 'react-router-dom'
3
import { useDispatch } from 'react-redux'
3
import { useDispatch } from 'react-redux'
4
import { useForm } from 'react-hook-form'
4
import { useForm } from 'react-hook-form'
5
import { Button } from '@mui/material'
5
import { Button } from '@mui/material'
Línea 6... Línea 6...
6
 
6
 
7
import { useMyProgress } from '@hooks'
7
import { useFetch, useMyProgress } from '@hooks'
8
import { saveProgress } from '@services/habits/habits'
8
import { saveProgress } from '@services/habits/habits'
Línea 9... Línea 9...
9
import { addNotification } from '@store/notification/notification.actions'
9
import { addNotification } from '@store/notification/notification.actions'
10
 
10
 
Línea 19... Línea 19...
19
  const dispatch = useDispatch()
19
  const dispatch = useDispatch()
Línea 20... Línea 20...
20
 
20
 
21
  const { getHabitById } = useMyProgress()
21
  const { getHabitById } = useMyProgress()
Línea -... Línea 22...
-
 
22
  const currentHabit = getHabitById(id)
-
 
23
 
22
  const currentHabit = getHabitById(id)
24
  const { data, isLoading } = useFetch(currentHabit.link)
23
 
25
 
24
  const {
26
  const {
25
    control,
27
    control,
26
    formState: { errors, isSubmitting },
28
    formState: { errors, isSubmitting },
Línea 36... Línea 38...
36
    const minutes = String(date.getMinutes()).padStart(2, '0')
38
    const minutes = String(date.getMinutes()).padStart(2, '0')
37
    const seconds = String(date.getSeconds()).padStart(2, '0')
39
    const seconds = String(date.getSeconds()).padStart(2, '0')
38
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
40
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
39
  }
41
  }
Línea 40... Línea 42...
40
 
42
 
41
  const onSubmit = handleSubmit(async (data) => {
43
  const onSubmit = handleSubmit(async (progress) => {
42
    try {
44
    try {
43
      const date = getCurrentDate()
45
      const date = getCurrentDate()
44
      const response = await saveProgress(currentHabit.link_add, {
46
      const response = await saveProgress(data.link_add, {
45
        ...data,
47
        ...progress,
46
        date
48
        date
47
      })
49
      })
48
      console.log(response)
50
      console.log(response)
49
    } catch (error) {
51
    } catch (error) {
50
      dispatch(addNotification({ style: 'danger', msg: error.message }))
52
      dispatch(addNotification({ style: 'danger', msg: error.message }))
51
    }
53
    }
Línea 52... Línea 54...
52
  })
54
  })
53
 
55
 
-
 
56
  return (
54
  return (
57
    <>
55
    <>
58
      <PageHeader title={`${currentHabit.name} - Agregar progreso`} />
56
      <PageHeader title='' />
59
      <LoadingWrapper loading={isLoading}>
57
      <Form onSubmit={onSubmit}>
60
        <Form onSubmit={onSubmit}>
58
        <LoadingWrapper loading={isSubmitting} displayChildren>
61
          <LoadingWrapper loading={isSubmitting} displayChildren>
59
          <Input
62
            <Input
60
            control={control}
63
              control={control}
61
            label='Valor cuantitativo:'
64
              label='Valor cuantitativo:'
62
            name='quantitative_value'
65
              name='quantitative_value'
63
            type='number'
66
              type='number'
64
            rules={{ required: 'El valor es requerido' }}
67
              rules={{ required: 'El valor es requerido' }}
65
            error={errors.quantitative_value?.message}
68
              error={errors.quantitative_value?.message}
66
          />
69
            />
67
 
70
 
68
          <Ckeditor
71
            <Ckeditor
69
            control={control}
72
              control={control}
70
            name='qualitative_description'
73
              name='qualitative_description'
71
            error={errors.qualitative_description?.message}
74
              error={errors.qualitative_description?.message}
72
            rules={{ required: 'La descripción es requerida' }}
75
              rules={{ required: 'La descripción es requerida' }}
73
            label='Descripción cualitativa:'
76
              label='Descripción cualitativa:'
74
          />
77
            />
75
 
78
 
76
          <Button color='primary' type='submit'>
79
            <Button color='primary' type='submit'>
77
            Enviar
80
              Enviar
78
          </Button>
81
            </Button>
-
 
82
          </LoadingWrapper>
79
        </LoadingWrapper>
83
        </Form>
80
      </Form>
84
      </LoadingWrapper>
81
    </>
85
    </>