Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
3211 stevensc 1
import React from 'react'
2
import { Controller, useForm } from 'react-hook-form'
3214 stevensc 3
import { Button, InputLabel } from '@mui/material'
3211 stevensc 4
import Datetime from 'react-datetime'
5
 
6
import Form from '@components/common/form'
7
import Input from '@components/UI/inputs/Input'
8
import Ckeditor from '@components/UI/Ckeditor'
9
import TagsInput from '@components/UI/TagsInput'
10
import LoadingWrapper from '@components/common/loading-wrapper'
11
import FormErrorFeedback from '@components/UI/form/FormErrorFeedback'
12
 
13
export default function GoalForm({
14
  onSubmit = () => {},
15
  defaultValues = {},
16
  values = {}
17
}) {
18
  const {
19
    control,
20
    handleSubmit,
21
    formState: { errors, isSubmitting }
22
  } = useForm({
23
    defaultValues,
24
    values
25
  })
26
 
27
  return (
28
    <Form onSubmit={handleSubmit(onSubmit)}>
29
      <LoadingWrapper loading={isSubmitting}>
30
        <Input
31
          name='name'
32
          label='Nombre'
33
          placeholder='Escribe el nombre de la meta'
34
          control={control}
35
          // rules={{ required: 'El nombre es requerido' }}
36
          error={errors.name?.message}
37
        />
38
 
39
        <Ckeditor
40
          label='Descripción'
41
          name='description'
42
          control={control}
43
          // rules={{ required: 'La descripción es requerida' }}
44
          error={errors.description?.message}
45
        />
46
 
47
        <Input
48
          type='number'
49
          name='value'
50
          label='Valor'
51
          placeholder='Define el valor de la meta'
52
          control={control}
53
          // rules={{ required: 'El valor es requerido' }}
54
          error={errors.value?.message}
55
        />
56
 
57
        <Controller
58
          name='skill_id'
59
          control={control}
60
          defaultValue={[]}
61
          // rules={{ required: 'La habilidad es requerida' }}
62
          render={({ field: { name, onChange } }) => (
63
            <>
64
              <TagsInput
65
                name={name}
66
                label='Habitos'
67
                onChange={onChange}
3212 stevensc 68
                suggestions={[]}
3211 stevensc 69
              />
70
              {errors.skill_id && (
71
                <FormErrorFeedback>
72
                  {errors.skill_id?.message}
73
                </FormErrorFeedback>
74
              )}
75
            </>
76
          )}
77
        />
78
 
79
        <Controller
80
          name='start_date'
81
          control={control}
82
          // rules={{ required: 'La fecha es requerida' }}
3213 stevensc 83
          render={({ field: { onChange } }) => (
3214 stevensc 84
            <>
85
              <InputLabel>Fecha de inicio</InputLabel>
86
              <Datetime
87
                dateFormat='DD-MM-YYYY'
88
                onChange={(e) => onChange(e.format('YYYY-MM-DD'))}
89
                timeFormat={false}
90
                inputProps={{ className: 'form-control' }}
91
                closeOnSelect
92
              />
93
              {errors.start_date && (
94
                <FormErrorFeedback>
95
                  {errors.start_date?.message}
96
                </FormErrorFeedback>
97
              )}
98
            </>
3211 stevensc 99
          )}
100
        />
3214 stevensc 101
        <Controller
102
          name='end_date'
103
          control={control}
104
          // rules={{ required: 'La fecha es requerida' }}
105
          render={({ field: { onChange } }) => (
106
            <>
107
              <InputLabel>Fecha de finalización</InputLabel>
108
              <Datetime
109
                dateFormat='DD-MM-YYYY'
110
                onChange={(e) => onChange(e.format('YYYY-MM-DD'))}
111
                timeFormat={false}
112
                inputProps={{ className: 'form-control' }}
113
                closeOnSelect
114
              />
115
              {errors.end_date && (
116
                <FormErrorFeedback>
117
                  {errors.end_date?.message}
118
                </FormErrorFeedback>
119
              )}
120
            </>
121
          )}
122
        />
3211 stevensc 123
 
124
        <Button type='submit' color='primary'>
125
          Enviar
126
        </Button>
127
      </LoadingWrapper>
128
    </Form>
129
  )
130
}