Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3270 Rev 3719
Línea 1... Línea 1...
1
import React from 'react'
1
import React from 'react';
2
import { useNavigate } from 'react-router-dom'
2
import { useNavigate } from 'react-router-dom';
3
import { useDispatch } from 'react-redux'
3
import { useDispatch } from 'react-redux';
4
 
4
 
5
import { usePurposes } from '@hooks'
5
import { usePurposes } from '@hooks';
6
import { savePurpose } from '@services/habits/purposes'
6
import { savePurpose } from '@services/habits/purposes';
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 PurposeForm from '@components/habits/purposes/purpose-form'
10
import PurposeForm from '@components/habits/purposes/purpose-form';
11
 
11
 
12
export default function CreatePurposePage() {
12
export default function CreatePurposePage() {
13
  const navigate = useNavigate()
13
  const navigate = useNavigate();
14
  const dispatch = useDispatch()
14
  const dispatch = useDispatch();
15
 
15
 
16
  const { addUrl, addPurpose } = usePurposes()
16
  const { addUrl, addPurpose } = usePurposes();
17
 
17
 
18
  const onSubmit = async (purpose) => {
18
  const onSubmit = async (purpose) => {
19
    try {
19
    try {
20
      const response = await savePurpose(addUrl, purpose)
20
      const response = await savePurpose(addUrl, purpose);
21
      dispatch(addNotification({ style: 'success', msg: response.message }))
21
      dispatch(addNotification({ style: 'success', msg: response.message }));
22
      addPurpose(response.data)
22
      addPurpose(response.data);
23
      navigate('/habits/purposes')
23
      navigate('/habits/purposes');
24
    } catch (error) {
24
    } catch (error) {
25
      dispatch(addNotification({ style: 'danger', msg: error.message }))
25
      dispatch(addNotification({ style: 'danger', msg: error.message }));
26
    }
26
    }
27
  }
27
  };
28
 
28
 
29
  return (
29
  return (
30
    <>
30
    <>
31
      <PageHeader title='Crea tú propósito' goBack />
31
      <PageHeader title='Crea tú propósito' goBack />
32
      <PurposeForm onSubmit={onSubmit} />
32
      <PurposeForm onSubmit={onSubmit} />
33
    </>
33
    </>
34
  )
34
  );
35
}
35
}