3719 |
stevensc |
1 |
import React from 'react';
|
|
|
2 |
import { useDispatch } from 'react-redux';
|
|
|
3 |
|
|
|
4 |
import { useHabitProgress } from '@hooks';
|
|
|
5 |
import { saveProgress } from '@services/habits/habits';
|
|
|
6 |
import { addNotification } from '@store/notification/notification.actions';
|
|
|
7 |
|
|
|
8 |
import PageHeader from '@components/common/page-header';
|
|
|
9 |
import LoadingWrapper from '@components/common/loading-wrapper';
|
|
|
10 |
import ProgressForm from '@components/habits/progress/progress-form';
|
|
|
11 |
|
|
|
12 |
export default function AddHabitProgress() {
|
|
|
13 |
const dispatch = useDispatch();
|
|
|
14 |
|
|
|
15 |
const { addUrl, loading, addItem } = useHabitProgress();
|
|
|
16 |
|
|
|
17 |
const onSubmit = async (progress) => {
|
|
|
18 |
try {
|
|
|
19 |
const response = await saveProgress(addUrl, progress);
|
|
|
20 |
addItem(response.data);
|
|
|
21 |
dispatch(addNotification({ style: 'success', msg: response.message }));
|
|
|
22 |
} catch (error) {
|
|
|
23 |
dispatch(addNotification({ style: 'danger', msg: error.message }));
|
|
|
24 |
}
|
|
|
25 |
};
|
|
|
26 |
|
|
|
27 |
return (
|
|
|
28 |
<>
|
|
|
29 |
<PageHeader title='Agregar progreso' goBack />
|
|
|
30 |
|
|
|
31 |
<LoadingWrapper loading={loading}>
|
|
|
32 |
<ProgressForm onSubmit={onSubmit} />
|
|
|
33 |
</LoadingWrapper>
|
|
|
34 |
</>
|
|
|
35 |
);
|
|
|
36 |
}
|