3719 |
stevensc |
1 |
import React from 'react';
|
|
|
2 |
import { useNavigate } from 'react-router-dom';
|
|
|
3 |
import { useDispatch } from 'react-redux';
|
|
|
4 |
|
|
|
5 |
import { useParadigms } from '@hooks';
|
|
|
6 |
import { saveParadigm } from '@services/habits/paradigms';
|
|
|
7 |
import { addNotification } from '@store/notification/notification.actions';
|
|
|
8 |
|
|
|
9 |
import PageHeader from '@components/common/page-header';
|
|
|
10 |
import ParadigmForm from '@components/habits/paradigms/paradigm-form';
|
|
|
11 |
|
|
|
12 |
export default function CreateParadigmPage() {
|
|
|
13 |
const navigate = useNavigate();
|
|
|
14 |
const dispatch = useDispatch();
|
|
|
15 |
|
|
|
16 |
const { addUrl, addParadigm } = useParadigms();
|
|
|
17 |
|
|
|
18 |
const onSubmit = async (paradigm) => {
|
|
|
19 |
try {
|
|
|
20 |
const response = await saveParadigm(addUrl, paradigm);
|
|
|
21 |
dispatch(addNotification({ style: 'success', msg: response.message }));
|
|
|
22 |
addParadigm(response.data);
|
|
|
23 |
navigate('/habits/paradigms');
|
|
|
24 |
} catch (error) {
|
|
|
25 |
dispatch(addNotification({ style: 'danger', msg: error.message }));
|
|
|
26 |
}
|
|
|
27 |
};
|
|
|
28 |
|
|
|
29 |
return (
|
|
|
30 |
<>
|
|
|
31 |
<PageHeader title='Crea tú paradigma' goBack />
|
|
|
32 |
<ParadigmForm onSubmit={onSubmit} />
|
|
|
33 |
</>
|
|
|
34 |
);
|
|
|
35 |
}
|