Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3669 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3669 Rev 3719
Línea 1... Línea 1...
1
import React from 'react';
1
import React from 'react';
2
 
2
 
3
import {
3
import {
4
  Form,
4
  Form,
5
  FormButton,
5
  FormButton,
6
  FormFilePicker,
6
  FormFilePicker,
7
  FormInput,
7
  FormInput,
8
  FormRichEditor,
8
  FormRichEditor,
9
  FormSelect
9
  FormSelect
10
} from '@shared/components';
10
} from '@shared/components';
11
 
11
 
12
export function KnowledgeForm({
12
export function KnowledgeForm({
13
  categories = [],
13
  categories = [],
14
  imageSize = '100x100',
14
  imageSize = '100x100',
15
  onSubmit = () => {},
15
  onSubmit = () => {},
16
  defaultValues = {
16
  defaultValues = {
17
    category_id: '',
17
    category_id: '',
18
    title: '',
18
    title: '',
19
    description: '',
19
    description: '',
20
    image: '',
20
    image: '',
21
    attachment: ''
21
    attachment: ''
22
  }
22
  }
23
}) {
23
}) {
24
  const handleSubmit = (data) => {
24
  const handleSubmit = (data) => {
25
    onSubmit({
25
    onSubmit({
26
      ...data,
26
      ...data,
27
      image: data.image?.[0],
27
      image: data.image?.[0],
28
      attachment: data.attachment?.[0]
28
      attachment: data.attachment?.[0]
29
    });
29
    });
30
  };
30
  };
31
 
31
 
32
  return (
32
  return (
33
    <Form onSubmit={handleSubmit} defaultValues={defaultValues} reset>
33
    <Form onSubmit={handleSubmit} defaultValues={defaultValues} reset>
34
      <FormSelect
34
      <FormSelect
35
        name='category_id'
35
        name='category_id'
36
        label='Categoría'
36
        label='Categoría'
37
        placeholder='Seleccione un opción'
37
        placeholder='Seleccione un opción'
38
        options={categories}
38
        options={categories}
39
        rules={{ required: 'Por favor, seleccione una categoría' }}
39
        rules={{ required: 'Por favor, seleccione una categoría' }}
40
      />
40
      />
41
 
41
 
42
      <FormInput
42
      <FormInput
43
        name='title'
43
        name='title'
44
        label='Título'
44
        label='Título'
45
        placeholder='Ingrese el título del conocimiento'
45
        placeholder='Ingrese el título del conocimiento'
46
        rules={{ required: 'Por favor, ingrese un título' }}
46
        rules={{ required: 'Por favor, ingrese un título' }}
47
      />
47
      />
48
 
48
 
49
      <FormRichEditor
49
      <FormRichEditor
50
        name='description'
50
        name='description'
51
        label='Descripción'
51
        label='Descripción'
52
        rules={{ required: 'Por favor, ingrese una descripción' }}
52
        rules={{ required: 'Por favor, ingrese una descripción' }}
53
      />
53
      />
54
 
54
 
55
      <FormFilePicker
55
      <FormFilePicker
56
        label='Seleccione una imagen'
56
        label='Seleccione una imagen'
57
        type='image'
57
        type='image'
58
        name='image'
58
        name='image'
59
        rules={{ required: 'Por favor, seleccione una imagen' }}
59
        rules={{ required: 'Por favor, seleccione una imagen' }}
60
        description={`Tamaño máximo: ${imageSize}`}
60
        description={`Tamaño máximo: ${imageSize}`}
61
      />
61
      />
62
 
62
 
63
      <FormFilePicker
63
      <FormFilePicker
64
        label='Seleccione un archivo'
64
        label='Seleccione un archivo'
65
        type='file'
65
        type='file'
66
        name='attachment'
66
        name='attachment'
67
        rules={{ required: 'Por favor, seleccione un archivo' }}
67
        rules={{ required: 'Por favor, seleccione un archivo' }}
68
      />
68
      />
69
 
69
 
70
      <FormButton type='submit'>Guardar</FormButton>
70
      <FormButton type='submit'>Guardar</FormButton>
71
    </Form>
71
    </Form>
72
  );
72
  );
73
}
73
}