| 3736 |
stevensc |
1 |
import React from 'react';
|
|
|
2 |
|
|
|
3 |
import { useAlert, useApi } from '@shared/hooks';
|
|
|
4 |
import { saveGroupWebsite } from '@groups/services';
|
|
|
5 |
|
|
|
6 |
import { Form, FormButton, FormInput } from '@shared/components';
|
|
|
7 |
|
|
|
8 |
export function WebsiteForm({ uuid = '', website = '', onSubmit = () => {} }) {
|
|
|
9 |
const { showSuccess, showError } = useAlert();
|
|
|
10 |
|
|
|
11 |
const { execute } = useApi(saveGroupWebsite, {
|
|
|
12 |
onSuccess: (data) => {
|
|
|
13 |
showSuccess('Página web actualizada correctamente');
|
|
|
14 |
onSubmit(data);
|
|
|
15 |
},
|
|
|
16 |
onError: (error) => {
|
|
|
17 |
showError(error.message);
|
|
|
18 |
}
|
|
|
19 |
});
|
|
|
20 |
|
|
|
21 |
const handleSubmit = (data) => {
|
|
|
22 |
execute(uuid, data);
|
|
|
23 |
};
|
|
|
24 |
|
|
|
25 |
return (
|
|
|
26 |
<Form onSubmit={handleSubmit} defaultValues={{ website }}>
|
|
|
27 |
<FormInput
|
|
|
28 |
name='website'
|
|
|
29 |
placeholder='Página web'
|
|
|
30 |
rules={{
|
|
|
31 |
pattern: { value: /^https?:\/\/.+$/, message: 'La página web debe ser una URL válida' }
|
|
|
32 |
}}
|
|
|
33 |
/>
|
|
|
34 |
<FormButton type='submit'>Guardar</FormButton>
|
|
|
35 |
</Form>
|
|
|
36 |
);
|
|
|
37 |
}
|