Rev 3270 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react';
import { useNavigate } from 'react-router-dom';
import { useDispatch } from 'react-redux';
import { usePurposes } from '@hooks';
import { savePurpose } from '@services/habits/purposes';
import { addNotification } from '@store/notification/notification.actions';
import PageHeader from '@components/common/page-header';
import PurposeForm from '@components/habits/purposes/purpose-form';
export default function CreatePurposePage() {
const navigate = useNavigate();
const dispatch = useDispatch();
const { addUrl, addPurpose } = usePurposes();
const onSubmit = async (purpose) => {
try {
const response = await savePurpose(addUrl, purpose);
dispatch(addNotification({ style: 'success', msg: response.message }));
addPurpose(response.data);
navigate('/habits/purposes');
} catch (error) {
dispatch(addNotification({ style: 'danger', msg: error.message }));
}
};
return (
<>
<PageHeader title='Crea tú propósito' goBack />
<PurposeForm onSubmit={onSubmit} />
</>
);
}