Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Reset errors after closing modal
dominik-zeglena84e770ee609
diff --git a/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx b/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsxindex d49ebf9f24..27b1be23d4 100644--- a/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx+++ b/saleor/static/dashboard-next/components/AssignAttributeDialog/AssignAttributeDialog.tsx@@ -19,6 +19,7 @@ import InfiniteScroll from "react-infinite-scroller";import ConfirmButton, {ConfirmButtonTransitionState} from "@saleor/components/ConfirmButton";+import useModalDialogErrors from "@saleor/hooks/useModalDialogErrors";import useSearchQuery from "@saleor/hooks/useSearchQuery";import { maybe, renderCollection } from "@saleor/misc";import { FetchMoreProps } from "@saleor/types";@@ -58,7 +59,7 @@ export interface AssignAttributeDialogProps extends FetchMoreProps {const AssignAttributeDialog: React.FC<AssignAttributeDialogProps> = ({attributes,confirmButtonState,- errors,+ errors: apiErrors,hasMore,loading,open,@@ -71,6 +72,7 @@ const AssignAttributeDialog: React.FC<AssignAttributeDialogProps> = ({}: AssignAttributeDialogProps) => {const classes = useStyles({});const [query, onQueryChange] = useSearchQuery(onFetch);+ const errors = useModalDialogErrors(apiErrors, open);return (<Dialog onClose={onClose} open={open} fullWidth maxWidth="sm">diff --git a/saleor/static/dashboard-next/hooks/useModalDialogErrors.ts b/saleor/static/dashboard-next/hooks/useModalDialogErrors.tsnew file mode 100644index 0000000000..59c9cdb4ee--- /dev/null+++ b/saleor/static/dashboard-next/hooks/useModalDialogErrors.ts@@ -0,0 +1,22 @@+import { useState } from "react";++import useStateFromProps from "./useStateFromProps";++function useModalDialogErrors<TError>(+ errors: TError[],+ open: boolean+): TError[] {+ const [state, setState] = useStateFromProps(errors);+ const [prevOpenState, setPrevOpenstate] = useState(open);++ if (open !== prevOpenState) {+ setPrevOpenstate(open);+ if (!open) {+ setState([]);+ }+ }++ return state;+}++export default useModalDialogErrors;