Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3374 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3374 Rev 3719
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 { useParadigms } from '@hooks'
5
import { useParadigms } from '@hooks';
6
import { editParadigm } from '@services/habits/paradigms'
6
import { editParadigm } from '@services/habits/paradigms';
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 ParadigmForm from '@components/habits/paradigms/paradigm-form'
10
import ParadigmForm from '@components/habits/paradigms/paradigm-form';
11
 
11
 
12
export default function EditParadigmPage() {
12
export default function EditParadigmPage() {
13
  const { id } = useParams()
13
  const { id } = useParams();
14
  const navigate = useNavigate()
14
  const navigate = useNavigate();
15
  const dispatch = useDispatch()
15
  const dispatch = useDispatch();
16
 
16
 
17
  const { updateParadigm, getParadigmById } = useParadigms()
17
  const { updateParadigm, getParadigmById } = useParadigms();
18
  const currentParadigm = getParadigmById(id)
18
  const currentParadigm = getParadigmById(id);
19
 
19
 
20
  const onSubmit = async (paradigm) => {
20
  const onSubmit = async (paradigm) => {
21
    try {
21
    try {
22
      const response = await editParadigm(
-
 
23
        currentParadigm.actions.link_edit,
22
      const response = await editParadigm(currentParadigm.actions.link_edit, paradigm);
24
        paradigm
-
 
25
      )
-
 
26
      dispatch(addNotification({ style: 'success', msg: response.message }))
23
      dispatch(addNotification({ style: 'success', msg: response.message }));
27
      updateParadigm(response.data)
24
      updateParadigm(response.data);
28
      navigate('/habits/paradigms')
25
      navigate('/habits/paradigms');
29
    } catch (error) {
26
    } catch (error) {
30
      dispatch(addNotification({ style: 'danger', msg: error.message }))
27
      dispatch(addNotification({ style: 'danger', msg: error.message }));
31
    }
28
    }
32
  }
29
  };
33
 
30
 
34
  return (
31
  return (
35
    <>
32
    <>
36
      <PageHeader title='Edita tú paradigma' goBack />
33
      <PageHeader title='Edita tú paradigma' goBack />
37
      <ParadigmForm
34
      <ParadigmForm
38
        onSubmit={onSubmit}
35
        onSubmit={onSubmit}
39
        defaultValues={{
36
        defaultValues={{
40
          name: '',
37
          name: '',
41
          description: ''
38
          description: ''
42
        }}
39
        }}
43
        values={{
40
        values={{
44
          name: currentParadigm?.name,
41
          name: currentParadigm?.name,
45
          description: currentParadigm?.description
42
          description: currentParadigm?.description
46
        }}
43
        }}
47
      />
44
      />
48
    </>
45
    </>
49
  )
46
  );
50
}
47
}