Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3302 | Rev 3371 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3270 stevensc 1
import React from 'react'
2
import { useNavigate } from 'react-router-dom'
3
import { useDispatch } from 'react-redux'
4
 
3303 stevensc 5
import {  useHabits } from '@hooks'
3270 stevensc 6
import { saveHabit } from '@services/habits/habits'
7
import { addNotification } from '@store/notification/notification.actions'
8
 
9
import PageHeader from '@components/common/page-header'
10
import HabitForm from '@components/habits/habits/habit-form'
11
 
12
export default function CreateHabitPage() {
13
  const navigate = useNavigate()
14
  const dispatch = useDispatch()
15
 
16
  const { addUrl, addHabit } = useHabits()
17
 
18
  const onSubmit = async (habit) => {
19
    console.log(habit)
20
    try {
21
      const response = await saveHabit(addUrl, habit)
22
      dispatch(addNotification({ style: 'success', msg: response.message }))
23
      addHabit(response.data)
24
      navigate('/habits/habits')
25
    } catch (error) {
26
      dispatch(addNotification({ style: 'danger', msg: error.message }))
27
    }
28
  }
29
 
30
  return (
31
    <>
32
      <PageHeader title='Crear hábito o competencia' goBack />
33
      <HabitForm onSubmit={onSubmit} />
34
    </>
35
  )
36
}