Commit 69f213a4 authored by PDuarte's avatar PDuarte

show save result

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