Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Set changed status permanently

dominik-zeglenc0e7d740a214
diff --git a/saleor/static/dashboard-next/components/Form/Form.tsx b/saleor/static/dashboard-next/components/Form/Form.tsx
index 5b7dba2d1b..7b19a244b4 100644
--- a/saleor/static/dashboard-next/components/Form/Form.tsx
+++ b/saleor/static/dashboard-next/components/Form/Form.tsx
@@ -26,6 +26,7 @@ interface FormComponentProps<T extends {}> extends FormProps<T> {
interface FormState<T extends {}> {
initial: T;
fields: T;
+ hasChanged: boolean;
}
class FormComponent<T extends {} = {}> extends React.Component<
@@ -52,6 +53,7 @@ class FormComponent<T extends {} = {}> extends React.Component<
...(prevState.fields as any),
...swapFields
},
+ hasChanged: false,
initial: {
...(prevState.initial as any),
...swapFields
@@ -63,19 +65,20 @@ class FormComponent<T extends {} = {}> extends React.Component<
state: FormState<T> = {
fields: this.props.initial,
+ hasChanged: false,
initial: this.props.initial
};
componentDidUpdate() {
const { hasChanged, confirmLeave, toggleFormChangeState } = this.props;
- if (this.hasChanged() !== hasChanged && confirmLeave) {
+ if (this.state.hasChanged !== hasChanged && confirmLeave) {
toggleFormChangeState();
}
}
componentDidMount() {
const { hasChanged, confirmLeave, toggleFormChangeState } = this.props;
- if (this.hasChanged() !== hasChanged && confirmLeave) {
+ if (this.state.hasChanged !== hasChanged && confirmLeave) {
toggleFormChangeState();
}
}
@@ -99,7 +102,8 @@ class FormComponent<T extends {} = {}> extends React.Component<
fields: {
...(this.state.fields as any),
[target.name]: target.value
- }
+ },
+ hasChanged: true
},
typeof cb === "function" ? cb : undefined
);
@@ -133,9 +137,6 @@ class FormComponent<T extends {} = {}> extends React.Component<
}
};
- hasChanged = () =>
- JSON.stringify(this.state.initial) !== JSON.stringify(this.state.fields);
-
render() {
const { children, errors, useForm = true } = this.props;
@@ -151,7 +152,7 @@ class FormComponent<T extends {} = {}> extends React.Component<
{}
)
: {},
- hasChanged: this.hasChanged(),
+ hasChanged: this.state.hasChanged,
reset: () =>
this.setState({
fields: this.state.initial