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