Commit 69f213a4 authored by PDuarte's avatar PDuarte

show save result

parent ac19ac50
// ** React Imports // ** React Imports
import { useState, useEffect, Fragment } from 'react' import { useState, useEffect, Fragment } from 'react'
import { useDispatch } from 'react-redux' import { useSelector, useDispatch } from 'react-redux'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import Avatar from '@components/avatar' import Avatar from '@components/avatar'
...@@ -12,7 +12,7 @@ import { Bell, Check, X, AlertTriangle, Info } from 'react-feather' ...@@ -12,7 +12,7 @@ import { Bell, Check, X, AlertTriangle, Info } from 'react-feather'
// ** Store & Actions // ** Store & Actions
import { updateProject } from '../../store/actions' import { updateProject, resetResults } from '../../store/actions'
import { useForm } from 'react-hook-form' import { useForm } from 'react-hook-form'
import classnames from 'classnames' import classnames from 'classnames'
...@@ -28,7 +28,7 @@ const SuccessProgressToast = () => ( ...@@ -28,7 +28,7 @@ const SuccessProgressToast = () => (
<div className='toastify-header'> <div className='toastify-header'>
<div className='title-wrapper'> <div className='title-wrapper'>
<Avatar size='sm' color='success' icon={<Check size={12} />} /> <Avatar size='sm' color='success' icon={<Check size={12} />} />
<h6 className='toast-title'>Saving Project !</h6> <h6 className='toast-title'>Saved !</h6>
</div> </div>
<small className='text-muted'></small> <small className='text-muted'></small>
</div> </div>
...@@ -42,13 +42,15 @@ const SuccessProgressToast = () => ( ...@@ -42,13 +42,15 @@ const SuccessProgressToast = () => (
const ProjectCard = ({ selectedProject }) => { const ProjectCard = ({ selectedProject }) => {
const store = useSelector(state => state.projectsettings)
const MySwal = withReactContent(Swal) const MySwal = withReactContent(Swal)
const handleError = () => { const handleError = (text) => {
return MySwal.fire({ return MySwal.fire({
title: 'Error!', title: 'Error!',
text: ' You clicked the button!', text,
icon: 'error', icon: 'error',
customClass: { customClass: {
confirmButton: 'btn btn-primary' confirmButton: 'btn btn-primary'
...@@ -63,8 +65,6 @@ const handleError = () => { ...@@ -63,8 +65,6 @@ const handleError = () => {
notifySuccessProgress = () => toast.success(<SuccessProgressToast />), notifySuccessProgress = () => toast.success(<SuccessProgressToast />),
onSubmit = values => { onSubmit = values => {
if (isObjEmpty(errors)) { if (isObjEmpty(errors)) {
notifySuccessProgress()
// handleError()
dispatch( dispatch(
updateProject({ updateProject({
id: values.id, id: values.id,
...@@ -82,6 +82,20 @@ const handleError = () => { ...@@ -82,6 +82,20 @@ const handleError = () => {
} }
}, [selectedProject]) }, [selectedProject])
useEffect(() => {
if (store.errorMsg !== '') {
handleError(store.errorMsg)
dispatch(resetResults())
}
}, [store.errorMsg])
useEffect(() => {
if (store.saveSucces) {
notifySuccessProgress()
dispatch(resetResults())
}
}, [store.saveSucces])
return ( return (
<Fragment> <Fragment>
......
...@@ -80,6 +80,16 @@ export const cleanProject = id => { ...@@ -80,6 +80,16 @@ export const cleanProject = id => {
} }
} }
export const resetResults = id => {
return async dispatch => {
dispatch({
type: 'RESET_RESULTS',
saveSucces: false,
errorMsg: ''
})
}
}
// ** Add new project // ** Add new project
export const updateProject = project => { export const updateProject = project => {
return (dispatch, getState) => { return (dispatch, getState) => {
...@@ -97,14 +107,14 @@ export const updateProject = project => { ...@@ -97,14 +107,14 @@ export const updateProject = project => {
// dispatch(getData_projects()) // dispatch(getData_projects())
}) })
.catch(err => { .catch(err => {
dispatch(setErrorMsg('error')) dispatch(setErrorMsg(err.response.data.message))
console.log(err) console.log(err.response.data)
}) })
} }
} }
// ** Get table Data ///api/datatables/data // ** Get table Data platforms
export const getData_platforms = params => { export const getData_platforms = params => {
return async dispatch => { return async dispatch => {
await axios.get(`${process.env.REACT_APP_API}/api/platforms`, params await axios.get(`${process.env.REACT_APP_API}/api/platforms`, params
......
...@@ -41,7 +41,12 @@ const settings = (state = initialState, action) => { ...@@ -41,7 +41,12 @@ const settings = (state = initialState, action) => {
...state, ...state,
errorMsg: action.errorMsg errorMsg: action.errorMsg
} }
case 'RESET_RESULTS':
return {
...state,
saveSucces: false,
errorMsg: ''
}
case 'GET_DATA_PROJECTS': case 'GET_DATA_PROJECTS':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment