Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3320 Rev 3719
Línea 1... Línea 1...
1
import React from 'react'
1
import React from 'react';
2
import { useDispatch } from 'react-redux'
2
import { useDispatch } from 'react-redux';
3
 
3
 
4
import { useHabitProgress } from '@hooks'
4
import { useHabitProgress } from '@hooks';
5
import { saveProgress } from '@services/habits/habits'
5
import { saveProgress } from '@services/habits/habits';
6
import { addNotification } from '@store/notification/notification.actions'
6
import { addNotification } from '@store/notification/notification.actions';
7
 
7
 
8
import PageHeader from '@components/common/page-header'
8
import PageHeader from '@components/common/page-header';
9
import LoadingWrapper from '@components/common/loading-wrapper'
9
import LoadingWrapper from '@components/common/loading-wrapper';
10
import ProgressForm from '@components/habits/progress/progress-form'
10
import ProgressForm from '@components/habits/progress/progress-form';
11
 
11
 
12
export default function AddHabitProgress() {
12
export default function AddHabitProgress() {
13
  const dispatch = useDispatch()
13
  const dispatch = useDispatch();
14
 
14
 
15
  const { addUrl, loading, addItem } = useHabitProgress()
15
  const { addUrl, loading, addItem } = useHabitProgress();
16
 
16
 
17
  const onSubmit = async (progress) => {
17
  const onSubmit = async (progress) => {
18
    try {
18
    try {
19
      const response = await saveProgress(addUrl, progress)
19
      const response = await saveProgress(addUrl, progress);
20
      addItem(response.data)
20
      addItem(response.data);
21
      dispatch(addNotification({ style: 'success', msg: response.message }))
21
      dispatch(addNotification({ style: 'success', msg: response.message }));
22
    } catch (error) {
22
    } catch (error) {
23
      dispatch(addNotification({ style: 'danger', msg: error.message }))
23
      dispatch(addNotification({ style: 'danger', msg: error.message }));
24
    }
24
    }
25
  }
25
  };
26
 
26
 
27
  return (
27
  return (
28
    <>
28
    <>
29
      <PageHeader title='Agregar progreso' goBack />
29
      <PageHeader title='Agregar progreso' goBack />
30
 
30
 
31
      <LoadingWrapper loading={loading}>
31
      <LoadingWrapper loading={loading}>
32
        <ProgressForm onSubmit={onSubmit} />
32
        <ProgressForm onSubmit={onSubmit} />
33
      </LoadingWrapper>
33
      </LoadingWrapper>
34
    </>
34
    </>
35
  )
35
  );
36
}
36
}