3320 |
stevensc |
1 |
import React from 'react'
|
|
|
2 |
import { useParams } from 'react-router-dom'
|
|
|
3 |
import { useDispatch } from 'react-redux'
|
|
|
4 |
|
|
|
5 |
import { useFetch, useHabitProgress } from '@hooks'
|
|
|
6 |
import { updateProgress } from '@services/habits/habits'
|
|
|
7 |
import { editNotification } from '@store/notification/notification.actions'
|
|
|
8 |
|
|
|
9 |
import PageHeader from '@components/common/page-header'
|
|
|
10 |
import LoadingWrapper from '@components/common/loading-wrapper'
|
|
|
11 |
import ProgressForm from '@components/habits/progress/progress-form'
|
|
|
12 |
|
|
|
13 |
export default function EditHabitProgress() {
|
|
|
14 |
const { id } = useParams()
|
|
|
15 |
const dispatch = useDispatch()
|
|
|
16 |
|
|
|
17 |
const { getItemById, loading, editItem } = useHabitProgress()
|
|
|
18 |
const currentRegister = getItemById(id)
|
|
|
19 |
const { data: registerValues, isLoading } = useFetch(
|
|
|
20 |
currentRegister?.actions.link_edit
|
|
|
21 |
)
|
|
|
22 |
|
|
|
23 |
const onSubmit = async (progress) => {
|
|
|
24 |
try {
|
|
|
25 |
const response = await updateProgress(
|
|
|
26 |
currentRegister?.actions.link_edit,
|
|
|
27 |
progress
|
|
|
28 |
)
|
|
|
29 |
editItem(response.data)
|
|
|
30 |
dispatch(editNotification({ style: 'success', msg: response.message }))
|
|
|
31 |
} catch (error) {
|
|
|
32 |
dispatch(editNotification({ style: 'danger', msg: error.message }))
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
return (
|
|
|
37 |
<>
|
|
|
38 |
<PageHeader title='Editar progreso' goBack />
|
|
|
39 |
<LoadingWrapper loading={loading || isLoading}>
|
|
|
40 |
<ProgressForm onSubmit={onSubmit} values={registerValues} />
|
|
|
41 |
</LoadingWrapper>
|
|
|
42 |
</>
|
|
|
43 |
)
|
|
|
44 |
}
|