Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
3320 stevensc 1
import React from 'react'
2
import { useForm } from 'react-hook-form'
3
 
4
import Form from '@components/common/form'
5
import Input from '@components/UI/inputs/Input'
6
import Button from '@components/UI/buttons/Buttons'
7
import Ckeditor from '@components/common/ckeditor/Ckeditor'
8
import LoadingWrapper from '@components/common/loading-wrapper'
3324 stevensc 9
import DatetimePicker from '@components/common/inputs/datetime-picker'
3320 stevensc 10
 
11
function ProgressForm({
12
  onSubmit = () => {},
13
  defaultValues = {
14
    quantitative_value: 0,
15
    qualitative_description: ''
16
  },
17
  values = {}
18
}) {
19
  const {
20
    control,
21
    formState: { errors, isSubmitting },
22
    handleSubmit
23
  } = useForm({
24
    defaultValues,
25
    values
26
  })
27
 
3324 stevensc 28
  /* const getCurrentDate = () => {
3320 stevensc 29
    const date = new Date()
30
    const year = date.getFullYear()
31
    const month = String(date.getMonth() + 1).padStart(2, '0') // Enero es 0
32
    const day = String(date.getDate()).padStart(2, '0')
33
    const hours = String(date.getHours()).padStart(2, '0')
34
    const minutes = String(date.getMinutes()).padStart(2, '0')
35
    const seconds = String(date.getSeconds()).padStart(2, '0')
36
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
3324 stevensc 37
  } */
3320 stevensc 38
 
39
  return (
40
    <Form onSubmit={handleSubmit(onSubmit)}>
41
      <LoadingWrapper loading={isSubmitting} displayChildren>
3324 stevensc 42
        <DatetimePicker
43
          label='Fecha'
44
          name='date'
45
          control={control}
46
          rules={{
47
            required: { value: true, message: 'La fecha es requerida' },
48
            validate: {
49
              beGreaterThanToday: (value) =>
50
                new Date(value) > new Date() ||
51
                'La fecha debe ser mayor a la fecha actual'
52
            }
53
          }}
54
          displayTime
55
          dateFormat='YYYY-MM-DDTHH:mm:ss'
56
        />
57
 
3320 stevensc 58
        <Input
59
          control={control}
60
          label='Valor cuantitativo:'
61
          name='quantitative_value'
62
          type='number'
63
          rules={{ required: 'El valor es requerido' }}
64
          error={errors.quantitative_value?.message}
65
        />
66
 
67
        <Ckeditor
68
          control={control}
69
          name='qualitative_description'
70
          error={errors.qualitative_description?.message}
71
          rules={{ required: 'La descripción es requerida' }}
72
          label='Descripción cualitativa:'
73
        />
74
 
75
        <Button color='primary' type='submit'>
76
          Enviar
77
        </Button>
78
      </LoadingWrapper>
79
    </Form>
80
  )
81
}
82
 
83
export default ProgressForm