Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3212 | Ir a la última revisión | | 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'
3
import { Button } from '@mui/material'
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}
68
                suggestions={values.skills}
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
          defaultValue={Date.now()}
83
          // rules={{ required: 'La fecha es requerida' }}
84
          render={({ field: { onChange, value } }) => (
85
            <Datetime
86
              dateFormat='DD-MM-YYYY'
87
              onChange={(e) => onChange(e.toString())}
88
              timeFormat={false}
89
              inputProps={{ className: 'form-control' }}
90
              initialValue={value}
91
              closeOnSelect
92
            />
93
          )}
94
        />
95
 
96
        <Button type='submit' color='primary'>
97
          Enviar
98
        </Button>
99
      </LoadingWrapper>
100
    </Form>
101
  )
102
}