Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3688 Rev 3719
Línea 1... Línea 1...
1
import React from 'react';
1
import React from 'react';
2
 
2
 
3
import { useApi } from '@shared/hooks';
3
import { useApi } from '@shared/hooks';
4
import { parseHelperToSelect } from '@shared/utils';
4
import { parseHelperToSelect } from '@shared/utils';
5
import { getGroupTypes, getIndustries } from '@groups/services';
5
import { getGroupTypes, getIndustries } from '@groups/services';
6
 
6
 
7
import { Form, FormButton, FormInput, FormSelect, Spinner } from '@shared/components';
7
import { Form, FormButton, FormInput, FormSelect, Spinner } from '@shared/components';
8
 
8
 
9
export const AddGroupForm = ({ onSubmit }) => {
9
export const AddGroupForm = ({ onSubmit }) => {
10
  const { data: groupTypes, loading: loadingGroupTypes } = useApi(getGroupTypes, {
10
  const { data: groupTypes, loading: loadingGroupTypes } = useApi(getGroupTypes, {
11
    autoFetch: true
11
    autoFetch: true
12
  });
12
  });
13
  const { data: industries, loading: loadingIndustries } = useApi(getIndustries, {
13
  const { data: industries, loading: loadingIndustries } = useApi(getIndustries, {
14
    autoFetch: true
14
    autoFetch: true
15
  });
15
  });
16
 
16
 
17
  if (loadingGroupTypes || loadingIndustries || !groupTypes || !industries) return <Spinner />;
17
  if (loadingGroupTypes || loadingIndustries || !groupTypes || !industries) return <Spinner />;
18
 
18
 
19
  return (
19
  return (
20
    <Form onSubmit={onSubmit} defaultValues={{ name: '', type_id: '', industry_id: '' }} reset>
20
    <Form onSubmit={onSubmit} defaultValues={{ name: '', type_id: '', industry_id: '' }} reset>
21
      <FormInput
21
      <FormInput
22
        name='name'
22
        name='name'
23
        label='Nombre'
23
        label='Nombre'
24
        placeholder='Nombre del grupo'
24
        placeholder='Nombre del grupo'
25
        rules={{ required: 'Este campo es requerido' }}
25
        rules={{ required: 'Este campo es requerido' }}
26
      />
26
      />
27
 
27
 
28
      <FormSelect
28
      <FormSelect
29
        label='Industria'
29
        label='Industria'
30
        name='type_id'
30
        name='type_id'
31
        rules={{ required: 'Por favor eliga un tipo' }}
31
        rules={{ required: 'Por favor eliga un tipo' }}
32
        options={parseHelperToSelect(groupTypes)}
32
        options={parseHelperToSelect(groupTypes)}
33
      />
33
      />
34
 
34
 
35
      <FormSelect
35
      <FormSelect
36
        label='Tipo'
36
        label='Tipo'
37
        name='industry_id'
37
        name='industry_id'
38
        rules={{ required: 'Por favor eliga un tipo' }}
38
        rules={{ required: 'Por favor eliga un tipo' }}
39
        options={parseHelperToSelect(industries)}
39
        options={parseHelperToSelect(industries)}
40
      />
40
      />
41
 
41
 
42
      <FormButton type='submit'>Crear grupo</FormButton>
42
      <FormButton type='submit'>Crear grupo</FormButton>
43
    </Form>
43
    </Form>
44
  );
44
  );
45
};
45
};