Proyectos de Subversion LeadersLinked - SPA

Rev

Autoría | Ultima modificación | Ver Log |

import React from 'react';

import { useAlert, useApi } from '@shared/hooks';
import { saveGroupWebsite } from '@groups/services';

import { Form, FormButton, FormInput } from '@shared/components';

export function WebsiteForm({ uuid = '', website = '', onSubmit = () => {} }) {
  const { showSuccess, showError } = useAlert();

  const { execute } = useApi(saveGroupWebsite, {
    onSuccess: (data) => {
      showSuccess('Página web actualizada correctamente');
      onSubmit(data);
    },
    onError: (error) => {
      showError(error.message);
    }
  });

  const handleSubmit = (data) => {
    execute(uuid, data);
  };

  return (
    <Form onSubmit={handleSubmit} defaultValues={{ website }}>
      <FormInput
        name='website'
        placeholder='Página web'
        rules={{
          pattern: { value: /^https?:\/\/.+$/, message: 'La página web debe ser una URL válida' }
        }}
      />
      <FormButton type='submit'>Guardar</FormButton>
    </Form>
  );
}