Commit 0d148b49 authored by Matija Obreza's avatar Matija Obreza

Fix: Don't update Subset and Dataset basic info unless form is dirty

- Prevents updates on simple UI navigation
parent 6eca93c4
import * as React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { submit, isInvalid } from 'redux-form';
import { submit, isDirty, isInvalid } from 'redux-form';
// actions
import { loadMyPartners } from 'partners/actions/dashboard';
import { loadCrops } from 'crop/actions/public';
......@@ -10,14 +10,13 @@ import { DATASET_BASIC_INFO_FORM } from 'datasets/constants';
// models
import Partner from 'model/genesys/Partner';
import Crop from 'model/genesys/Crop';
// utilities
import { log } from 'utilities/debug';
// ui
import StepperTemplate from 'ui/common/stepper/StepperTemplate';
import BasicInfoForm from './BasicInfoForm';
interface IDatasetProps extends React.ClassAttributes<any> {
isFormDirty: boolean;
loadMyPartners: any;
myPartners: Partner[];
submit: any;
......@@ -28,9 +27,13 @@ interface IDatasetProps extends React.ClassAttributes<any> {
class BasicInfoStep extends StepperTemplate<IDatasetProps> {
protected gotoStep = (id) => {
const { submit, onGotoStep } = this.props;
log('Saving form');
submit(DATASET_BASIC_INFO_FORM);
const { submit, isFormDirty, onGotoStep } = this.props;
if (isFormDirty) {
// log('Saving form');
submit(DATASET_BASIC_INFO_FORM);
} else {
console.log(`Form ${DATASET_BASIC_INFO_FORM} not dirty`);
}
setTimeout(() => onGotoStep(id));
}
......@@ -52,6 +55,7 @@ const mapStateToProps = (state, ownProps) => ({
crops: state.crop.public.list,
myPartners: state.partner.dashboard.myPartners,
isInvalidForm: isInvalid(DATASET_BASIC_INFO_FORM)(state),
isFormDirty: isDirty(DATASET_BASIC_INFO_FORM)(state),
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
......
import * as React from 'react';
import { translate } from 'react-i18next';
import {bindActionCreators} from 'redux';
import {isInvalid, submit} from 'redux-form';
import {isInvalid, isDirty, submit} from 'redux-form';
import {connect} from 'react-redux';
// constants
import {SUBSET_FORM} from 'subsets/constants';
......@@ -13,6 +13,7 @@ import StepperTemplate from 'ui/common/stepper/StepperTemplate';
interface ISubsetProps extends React.ClassAttributes<any> {
isInvalidForm: boolean;
isFormDirty: boolean;
submit: any;
crops: Crop[];
t: any;
......@@ -23,9 +24,14 @@ class BasicInfoStep extends StepperTemplate<ISubsetProps> {
protected renderContent = () => (<BasicInfoForm initialValues={ this.props.item } t={ this.props.t } crops={ this.props.crops }/>);
protected gotoStep = (id) => {
const {onGotoStep, submit} = this.props;
const { onGotoStep, submit, isFormDirty } = this.props;
if (onGotoStep) {
submit(SUBSET_FORM);
if (isFormDirty) {
submit(SUBSET_FORM);
} else {
console.log(`Form ${SUBSET_FORM} not dirty`);
}
setTimeout(() => onGotoStep(id));
}
}
......@@ -39,6 +45,7 @@ class BasicInfoStep extends StepperTemplate<ISubsetProps> {
const mapStateToProps = (state, ownProps) => ({
crops: state.crop.public.list,
isInvalidForm: isInvalid(SUBSET_FORM)(state),
isFormDirty: isDirty(SUBSET_FORM)(state),
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
......
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