Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Make leave prompt optional
dominik-zeglenfd22f7941f67
diff --git a/saleor/static/dashboard-next/components/Form/Form.tsx b/saleor/static/dashboard-next/components/Form/Form.tsxindex c15beb78da..d93e90e783 100644--- a/saleor/static/dashboard-next/components/Form/Form.tsx+++ b/saleor/static/dashboard-next/components/Form/Form.tsx@@ -13,6 +13,7 @@ export interface FormProps<T extends {}> {) => React.ReactElement<any>);errors?: UserError[];initial?: T;+ confirmLeave?: boolean;useForm?: boolean;onSubmit?(data: T);}@@ -65,22 +66,22 @@ class FormComponent<T extends {} = {}> extends React.Component<};componentDidUpdate() {- const { hasChanged, toggleFormChangeState } = this.props;- if (this.hasChanged() !== hasChanged) {+ const { hasChanged, confirmLeave, toggleFormChangeState } = this.props;+ if (this.hasChanged() !== hasChanged && confirmLeave) {toggleFormChangeState();}}componentDidMount() {- const { hasChanged, toggleFormChangeState } = this.props;- if (this.hasChanged() !== hasChanged) {+ const { hasChanged, confirmLeave, toggleFormChangeState } = this.props;+ if (this.hasChanged() !== hasChanged && confirmLeave) {toggleFormChangeState();}}componentWillUnmount() {- const { hasChanged, toggleFormChangeState } = this.props;- if (hasChanged) {+ const { hasChanged, confirmLeave, toggleFormChangeState } = this.props;+ if (hasChanged && confirmLeave) {toggleFormChangeState();}}@@ -124,7 +125,7 @@ class FormComponent<T extends {} = {}> extends React.Component<JSON.stringify(this.state.initial) !== JSON.stringify(this.state.fields);render() {- const { children, errors, hasChanged, useForm = true } = this.props;+ const { children, errors, useForm = true } = this.props;const contents = children({change: this.handleChange,@@ -138,7 +139,7 @@ class FormComponent<T extends {} = {}> extends React.Component<{}): {},- hasChanged,+ hasChanged: this.hasChanged(),submit: this.handleSubmit});diff --git a/saleor/static/dashboard-next/components/Form/FormContext.tsx b/saleor/static/dashboard-next/components/Form/FormContext.tsxindex a5a6f9c870..b8d73029cb 100644--- a/saleor/static/dashboard-next/components/Form/FormContext.tsx+++ b/saleor/static/dashboard-next/components/Form/FormContext.tsx@@ -19,9 +19,9 @@ export class FormProvider extends React.Component<{}, FormProviderState> {};toggle = () =>- this.setState({- hasChanged: !this.state.hasChanged- });+ this.setState(prevState => ({+ hasChanged: !prevState.hasChanged+ }));render() {return (