Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3374 | Rev 3432 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3374 Rev 3416
Línea 1... Línea 1...
1
import React from 'react'
1
import React from "react";
2
import { useParams, useNavigate } from 'react-router-dom'
2
import { useParams, useNavigate } from "react-router-dom";
3
import { useDispatch } from 'react-redux'
3
import { useDispatch } from "react-redux";
4
 
4
 
5
import { useFetch, useHabits } from '@hooks'
5
import { useFetch, useHabits } from "@hooks";
6
import { editHabit } from '@services/habits/habits'
6
import { editHabit } from "@services/habits/habits";
7
import { addNotification } from '@store/notification/notification.actions'
7
import { addNotification } from "@store/notification/notification.actions";
8
 
8
 
9
import PageHeader from '@components/common/page-header'
9
import PageHeader from "@components/common/page-header";
10
import LoadingWrapper from '@components/common/loading-wrapper'
10
import LoadingWrapper from "@components/common/loading-wrapper";
11
import HabitForm from '@components/habits/habits/habit-form'
11
import HabitForm from "@components/habits/habits/habit-form";
Línea 12... Línea 12...
12
 
12
 
13
export default function EditHabitPage() {
13
export default function EditHabitPage() {
14
  const { id } = useParams()
14
  const { id } = useParams();
15
  const navigate = useNavigate()
15
  const navigate = useNavigate();
Línea 16... Línea 16...
16
  const dispatch = useDispatch()
16
  const dispatch = useDispatch();
17
 
17
 
Línea 18... Línea 18...
18
  const { updateHabit, getHabitById } = useHabits()
18
  const { updateHabit, getHabitById } = useHabits();
19
  const currentHabit = getHabitById(id)
19
  const currentHabit = getHabitById(id);
20
 
20
 
Línea 21... Línea 21...
21
  const { data: habitValues, isLoading } = useFetch(
21
  const { data: habitValues, loading } = useFetch(
22
    currentHabit?.actions.link_edit
22
    currentHabit?.actions.link_edit
23
  )
23
  );
24
 
24
 
25
  const onSubmit = async (habit) => {
25
  const onSubmit = async (habit) => {
26
    try {
26
    try {
27
      const response = await editHabit(currentHabit?.actions.link_edit, habit)
27
      const response = await editHabit(currentHabit?.actions.link_edit, habit);
28
      dispatch(addNotification({ style: 'success', msg: response.message }))
28
      dispatch(addNotification({ style: "success", msg: response.message }));
29
      updateHabit(response.data)
29
      updateHabit(response.data);
30
      navigate('/habits/habits')
30
      navigate("/habits/habits");
Línea 31... Línea 31...
31
    } catch (error) {
31
    } catch (error) {
32
      dispatch(addNotification({ style: 'danger', msg: error.message }))
32
      dispatch(addNotification({ style: "danger", msg: error.message }));
33
    }
33
    }
34
  }
34
  };
35
 
35
 
36
  return (
36
  return (
37
    <>
37
    <>
38
      <PageHeader title='Editar hábito o competencia' goBack />
38
      <PageHeader title="Editar hábito o competencia" goBack />
39
      <LoadingWrapper loading={isLoading}>
39
      <LoadingWrapper loading={loading}>