Proyectos de Subversion LeadersLinked - SPA

Rev

Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React from 'react';

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

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

export function OverviewForm({ uuid, description = '', onSubmit }) {
  const { showError, showSuccess } = useAlert();

  const { execute } = useApi(saveGroupOverview, {
    onSuccess: (message) => {
      showSuccess(message);
      onSubmit();
    },
    onError: (error) => {
      showError(error.message);
    }
  });

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

  /* const onSubmit = (data) => {
    axios
      .post(typesUrl[type], formData)
      .then((response) => {
        const { data, success } = response.data;
        if (!success) {
          const errorMessage =
            typeof data === 'string'
              ? data
              : Object.entries(data).map(([key, value]) => `${key}: ${value}`)[0];
          throw new Error(errorMessage);
        }

        onComplete(data.description || data);
        closeModal();
      })
      .catch((err) => {
        dispatch(addNotification({ style: 'danger', msg: err.message }));
      });
  }; */

  return (
    <Form onSubmit={handleSubmit} defaultValues={{ description }}>
      <FormRichEditor name='description' rules={{ required: 'Este campo es requerido' }} />
      <FormButton type='submit'>Guardar</FormButton>
    </Form>
  );
}