Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3374 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React from 'react';
2
import { useParams, useNavigate } from 'react-router-dom';
3
import { useDispatch } from 'react-redux';
4
 
5
import { useValues } from '@hooks';
6
import { editValue } from '@services/habits/values';
7
import { addNotification } from '@store/notification/notification.actions';
8
 
9
import PageHeader from '@components/common/page-header';
10
import ValueForm from '@components/habits/values/value-form';
11
 
12
export default function EditValuePage() {
13
  const { id } = useParams();
14
  const navigate = useNavigate();
15
  const dispatch = useDispatch();
16
 
17
  const { updateValue, getValueById } = useValues();
18
  const currentValue = getValueById(id);
19
 
20
  const onSubmit = async (value) => {
21
    try {
22
      const response = await editValue(currentValue.actions.link_edit, value);
23
      dispatch(addNotification({ style: 'success', msg: response.message }));
24
      updateValue(response.data);
25
      navigate('/habits/values');
26
    } catch (error) {
27
      dispatch(addNotification({ style: 'danger', msg: error.message }));
28
    }
29
  };
30
 
31
  return (
32
    <>
33
      <PageHeader title='Edita tú valor' goBack />
34
      <ValueForm
35
        onSubmit={onSubmit}
36
        defaultValues={{
37
          name: '',
38
          description: ''
39
        }}
40
        values={{
41
          name: currentValue?.name,
42
          description: currentValue?.description
43
        }}
44
      />
45
    </>
46
  );
47
}