Commit 7b9e180b authored by Oleksii Savran's avatar Oleksii Savran
Browse files

Unable to apply filters after reset

parent cbe43c57
......@@ -3,6 +3,7 @@ import {translate} from 'react-i18next';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {withStyles} from '@material-ui/core/styles';
import { getFormValues } from 'redux-form';
import {log} from 'utilities/debug';
import { showSnackbar } from 'actions/snackbar';
......@@ -31,7 +32,7 @@ const styles = (theme) => ({
//
// Renders a standard filters block
const FiltersBlock = ({ title, children, handleSubmit, onSubmit, initialize, classes, showSnackbar, t }) => {
const FiltersBlock = ({ title, children, handleSubmit, onSubmit, initialize, classes, showSnackbar, values, t }) => {
const scrollToTop = () => {
if (window) {
window.scrollTo(0, 0);
......@@ -41,7 +42,11 @@ const FiltersBlock = ({ title, children, handleSubmit, onSubmit, initialize, cla
const onReset = (e) => {
showSnackbar('Resetting filters...');
log('Clearing form');
initialize({});
const initialValues = {};
Object.keys(values).forEach((key) => {
initialValues[key] = null;
});
initialize(initialValues);
setTimeout(handleSubmit, 100);
scrollToTop();
};
......@@ -68,8 +73,12 @@ const FiltersBlock = ({ title, children, handleSubmit, onSubmit, initialize, cla
);
};
const mapStateToProps = (state, ownProps) => ({
values: getFormValues(ownProps.form)(state),
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
showSnackbar,
}, dispatch);
export default translate()(connect(null, mapDispatchToProps)(withStyles(styles)<any>(FiltersBlock)));
export default translate()(connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)<any>(FiltersBlock)));
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