fix(ui) - reset errors

This commit is contained in:
Shekar Siri 2021-12-06 11:09:53 +05:30
parent d9dcdf68d5
commit 0f83d77fb6
2 changed files with 19 additions and 3 deletions

View file

@ -4,7 +4,7 @@ import { Loader, IconButton, Popup, NoContent, SlideModal } from 'UI'
import { connect } from 'react-redux'
import stl from './roles.css'
import RoleForm from './components/RoleForm'
import { init, edit, fetchList, remove as deleteRole } from 'Duck/roles';
import { init, edit, fetchList, remove as deleteRole, resetErrors } from 'Duck/roles';
import RoleItem from './components/RoleItem'
import { confirm } from 'UI/Confirmation';
import { toast } from 'react-toastify';
@ -19,7 +19,8 @@ interface Props {
fetchList: () => Promise<void>,
account: any,
permissionsMap: any,
removeErrors: any
removeErrors: any,
resetErrors: () => void
}
function Roles(props: Props) {
@ -37,6 +38,9 @@ function Roles(props: Props) {
toast.error(e)
})
}
return () => {
props.resetErrors()
}
}, [removeErrors])
const closeModal = () => {
@ -134,4 +138,4 @@ export default connect(state => {
loading: state.getIn(['roles', 'fetchRequest', 'loading']),
account: state.getIn([ 'user', 'account' ])
}
}, { init, edit, fetchList, deleteRole })(Roles)
}, { init, edit, fetchList, deleteRole, resetErrors })(Roles)

View file

@ -6,6 +6,8 @@ import { reduceDucks } from 'Duck/tools';
const crudDuck = crudDuckGenerator('client/role', Role, { idKey: 'roleId' });
export const { fetchList, init, edit, remove, } = crudDuck.actions;
const RESET_ERRORS = 'roles/RESET_ERRORS';
const initialState = Map({
list: List(),
permissions: List([
@ -19,6 +21,10 @@ const initialState = Map({
});
const reducer = (state = initialState, action = {}) => {
switch (action.type) {
case RESET_ERRORS:
return state.setIn(['removeRequest', 'errors'], null);
}
return state;
};
@ -29,4 +35,10 @@ export function save(instance) {
};
}
export function resetErrors() {
return {
type: RESET_ERRORS,
}
}
export default reduceDucks(crudDuck, { initialState, reducer }).reducer;