Reset form after closing dialog
This commit is contained in:
parent
1f190c50da
commit
8131d15d23
4 changed files with 20 additions and 8 deletions
|
@ -1,9 +1,9 @@
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import Card from "@material-ui/core/Card";
|
import Card from "@material-ui/core/Card";
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
|
import AppHeader from "@saleor/components/AppHeader";
|
||||||
import SearchBar from "@saleor/components/SearchBar";
|
import SearchBar from "@saleor/components/SearchBar";
|
||||||
import { sectionNames } from "@saleor/intl";
|
import { sectionNames } from "@saleor/intl";
|
||||||
import Container from "../../../components/Container";
|
import Container from "../../../components/Container";
|
||||||
|
@ -23,10 +23,12 @@ export interface AttributeListPageProps
|
||||||
SearchPageProps,
|
SearchPageProps,
|
||||||
TabPageProps {
|
TabPageProps {
|
||||||
attributes: AttributeList_attributes_edges_node[];
|
attributes: AttributeList_attributes_edges_node[];
|
||||||
|
onBack: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AttributeListPage: React.FC<AttributeListPageProps> = ({
|
const AttributeListPage: React.FC<AttributeListPageProps> = ({
|
||||||
onAdd,
|
onAdd,
|
||||||
|
onBack,
|
||||||
initialSearch,
|
initialSearch,
|
||||||
onSearchChange,
|
onSearchChange,
|
||||||
currentTab,
|
currentTab,
|
||||||
|
@ -41,6 +43,9 @@ const AttributeListPage: React.FC<AttributeListPageProps> = ({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
|
<AppHeader onBack={onBack}>
|
||||||
|
<FormattedMessage {...sectionNames.configuration} />
|
||||||
|
</AppHeader>
|
||||||
<PageHeader title={intl.formatMessage(sectionNames.attributes)}>
|
<PageHeader title={intl.formatMessage(sectionNames.attributes)}>
|
||||||
<Button onClick={onAdd} color="primary" variant="contained">
|
<Button onClick={onAdd} color="primary" variant="contained">
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
|
|
@ -15,6 +15,7 @@ import DeleteFilterTabDialog from "@saleor/components/DeleteFilterTabDialog";
|
||||||
import SaveFilterTabDialog, {
|
import SaveFilterTabDialog, {
|
||||||
SaveFilterTabDialogFormData
|
SaveFilterTabDialogFormData
|
||||||
} from "@saleor/components/SaveFilterTabDialog";
|
} from "@saleor/components/SaveFilterTabDialog";
|
||||||
|
import { configurationMenuUrl } from "@saleor/configuration";
|
||||||
import useNavigator from "@saleor/hooks/useNavigator";
|
import useNavigator from "@saleor/hooks/useNavigator";
|
||||||
import useNotifier from "@saleor/hooks/useNotifier";
|
import useNotifier from "@saleor/hooks/useNotifier";
|
||||||
import usePaginator, {
|
import usePaginator, {
|
||||||
|
@ -165,6 +166,7 @@ const AttributeList: React.FC<AttributeListProps> = ({ params }) => {
|
||||||
isChecked={isSelected}
|
isChecked={isSelected}
|
||||||
onAdd={() => navigate(attributeAddUrl())}
|
onAdd={() => navigate(attributeAddUrl())}
|
||||||
onAll={() => navigate(attributeListUrl())}
|
onAll={() => navigate(attributeListUrl())}
|
||||||
|
onBack={() => navigate(configurationMenuUrl)}
|
||||||
onNextPage={loadNextPage}
|
onNextPage={loadNextPage}
|
||||||
onPreviousPage={loadPreviousPage}
|
onPreviousPage={loadPreviousPage}
|
||||||
onRowClick={id => () => navigate(attributeUrl(id))}
|
onRowClick={id => () => navigate(attributeUrl(id))}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import { buttonMessages, sectionNames } from "@saleor/intl";
|
||||||
import { UserError } from "@saleor/types";
|
import { UserError } from "@saleor/types";
|
||||||
import { getErrors, getFieldError } from "@saleor/utils/errors";
|
import { getErrors, getFieldError } from "@saleor/utils/errors";
|
||||||
import { getMenuItemByValue, IMenu } from "@saleor/utils/menu";
|
import { getMenuItemByValue, IMenu } from "@saleor/utils/menu";
|
||||||
|
import useModalDialogOpen from "@saleor/hooks/useModalDialogOpen";
|
||||||
|
|
||||||
export type MenuItemType = "category" | "collection" | "link" | "page";
|
export type MenuItemType = "category" | "collection" | "link" | "page";
|
||||||
export interface MenuItemData {
|
export interface MenuItemData {
|
||||||
|
@ -97,17 +98,20 @@ const MenuItemDialog: React.StatelessComponent<MenuItemDialogProps> = ({
|
||||||
);
|
);
|
||||||
const [url, setUrl] = React.useState<string>(undefined);
|
const [url, setUrl] = React.useState<string>(undefined);
|
||||||
|
|
||||||
|
// Reset input state after closing dialog
|
||||||
|
useModalDialogOpen(open, {
|
||||||
|
onClose: () => {
|
||||||
|
setData(initial || defaultInitial);
|
||||||
|
setDisplayValue(initialDisplayValue);
|
||||||
|
setUrl(undefined);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Refresh initial display value if changed
|
// Refresh initial display value if changed
|
||||||
React.useEffect(() => setDisplayValue(initialDisplayValue), [
|
React.useEffect(() => setDisplayValue(initialDisplayValue), [
|
||||||
initialDisplayValue
|
initialDisplayValue
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Reset input state after closing dialog
|
|
||||||
React.useEffect(() => {
|
|
||||||
setDisplayValue(initialDisplayValue);
|
|
||||||
setUrl(undefined);
|
|
||||||
}, [open]);
|
|
||||||
|
|
||||||
const mutationErrors = getErrors(errors);
|
const mutationErrors = getErrors(errors);
|
||||||
|
|
||||||
let options: IMenu = [];
|
let options: IMenu = [];
|
||||||
|
|
|
@ -18,7 +18,8 @@ const props: AttributeListPageProps = {
|
||||||
...listActionsProps,
|
...listActionsProps,
|
||||||
...tabPageProps,
|
...tabPageProps,
|
||||||
...searchPageProps,
|
...searchPageProps,
|
||||||
attributes
|
attributes,
|
||||||
|
onBack: () => undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
storiesOf("Views / Attributes / Attribute list", module)
|
storiesOf("Views / Attributes / Attribute list", module)
|
||||||
|
|
Loading…
Reference in a new issue