Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Reset form after submitting message
dominik-zeglen7d112725416b
diff --git a/saleor/static/dashboard-next/components/Form/Form.tsx b/saleor/static/dashboard-next/components/Form/Form.tsxindex 2878b6195b..5a87b5aaff 100644--- a/saleor/static/dashboard-next/components/Form/Form.tsx+++ b/saleor/static/dashboard-next/components/Form/Form.tsx@@ -2,19 +2,18 @@ import * as React from "react";import { UserError } from "../../types";export interface FormProps<T extends {}> {- children: ((- props: {- data: T;- hasChanged: boolean;- errors: { [key: string]: string };- change(event: React.ChangeEvent<any>, cb?: () => void);- submit(event?: React.FormEvent<any>);- }- ) => React.ReactElement<any>);+ children: (props: {+ data: T;+ hasChanged: boolean;+ errors: { [key: string]: string };+ change(event: React.ChangeEvent<any>, cb?: () => void);+ submit(event?: React.FormEvent<any>);+ }) => React.ReactElement<any>;errors?: UserError[];initial?: T;confirmLeave?: boolean;useForm?: boolean;+ resetOnSubmit?: boolean;onSubmit?(data: T);}@@ -114,8 +113,8 @@ class FormComponent<T extends {} = {}> extends React.Component<}};- handleSubmit = (event?: React.FormEvent<any>) => {- const { onSubmit } = this.props;+ handleSubmit = (event?: React.FormEvent<any>, cb?: () => void) => {+ const { resetOnSubmit, onSubmit } = this.props;if (event) {event.stopPropagation();event.preventDefault();@@ -123,6 +122,14 @@ class FormComponent<T extends {} = {}> extends React.Component<if (onSubmit !== undefined) {onSubmit(this.state.fields);}+ if (cb) {+ cb();+ }+ if (resetOnSubmit) {+ this.setState({+ fields: this.state.initial+ });+ }};hasChanged = () =>diff --git a/saleor/static/dashboard-next/orders/components/OrderHistory/OrderHistory.tsx b/saleor/static/dashboard-next/orders/components/OrderHistory/OrderHistory.tsxindex a67fd4cf60..138ca72900 100644--- a/saleor/static/dashboard-next/orders/components/OrderHistory/OrderHistory.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderHistory/OrderHistory.tsx@@ -131,7 +131,7 @@ const OrderHistory = withStyles(styles, { name: "OrderHistory" })(/>{history ? (<Timeline>- <Form initial={{ message: "" }} onSubmit={onNoteAdd}>+ <Form initial={{ message: "" }} onSubmit={onNoteAdd} resetOnSubmit>{({ change, data, submit }) => (<TimelineAddNotemessage={data.message}