| 3736 |
stevensc |
1 |
import React from 'react';
|
|
|
2 |
|
|
|
3 |
import { useAlert, useApi } from '@shared/hooks';
|
|
|
4 |
import { saveGroupOverview } from '@groups/services';
|
|
|
5 |
|
|
|
6 |
import { Form, FormButton, FormRichEditor } from '@shared/components';
|
|
|
7 |
|
|
|
8 |
export function OverviewForm({ uuid, description = '', onSubmit }) {
|
|
|
9 |
const { showError, showSuccess } = useAlert();
|
|
|
10 |
|
|
|
11 |
const { execute } = useApi(saveGroupOverview, {
|
|
|
12 |
onSuccess: (message) => {
|
|
|
13 |
showSuccess(message);
|
|
|
14 |
onSubmit();
|
|
|
15 |
},
|
|
|
16 |
onError: (error) => {
|
|
|
17 |
showError(error.message);
|
|
|
18 |
}
|
|
|
19 |
});
|
|
|
20 |
|
|
|
21 |
const handleSubmit = (data) => {
|
|
|
22 |
execute(uuid, data);
|
|
|
23 |
};
|
|
|
24 |
|
|
|
25 |
/* const onSubmit = (data) => {
|
|
|
26 |
axios
|
|
|
27 |
.post(typesUrl[type], formData)
|
|
|
28 |
.then((response) => {
|
|
|
29 |
const { data, success } = response.data;
|
|
|
30 |
if (!success) {
|
|
|
31 |
const errorMessage =
|
|
|
32 |
typeof data === 'string'
|
|
|
33 |
? data
|
|
|
34 |
: Object.entries(data).map(([key, value]) => `${key}: ${value}`)[0];
|
|
|
35 |
throw new Error(errorMessage);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
onComplete(data.description || data);
|
|
|
39 |
closeModal();
|
|
|
40 |
})
|
|
|
41 |
.catch((err) => {
|
|
|
42 |
dispatch(addNotification({ style: 'danger', msg: err.message }));
|
|
|
43 |
});
|
|
|
44 |
}; */
|
|
|
45 |
|
|
|
46 |
return (
|
|
|
47 |
<Form onSubmit={handleSubmit} defaultValues={{ description }}>
|
|
|
48 |
<FormRichEditor name='description' rules={{ required: 'Este campo es requerido' }} />
|
|
|
49 |
<FormButton type='submit'>Guardar</FormButton>
|
|
|
50 |
</Form>
|
|
|
51 |
);
|
|
|
52 |
}
|