Reset form state after closing it
This commit is contained in:
parent
b75ceed7cc
commit
8a2f240719
1 changed files with 20 additions and 8 deletions
|
@ -8,6 +8,8 @@ import { makeStyles } from "@material-ui/styles";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
|
|
||||||
|
import useModalDialogErrors from "@saleor/hooks/useModalDialogErrors";
|
||||||
|
import useModalDialogOpen from "@saleor/hooks/useModalDialogOpen";
|
||||||
import { ProductVariantBulkCreateInput } from "../../../types/globalTypes";
|
import { ProductVariantBulkCreateInput } from "../../../types/globalTypes";
|
||||||
import { createInitialForm, ProductVariantCreateFormData } from "./form";
|
import { createInitialForm, ProductVariantCreateFormData } from "./form";
|
||||||
import ProductVariantCreateContent, {
|
import ProductVariantCreateContent, {
|
||||||
|
@ -90,6 +92,7 @@ const ProductVariantCreateDialog: React.FC<
|
||||||
const {
|
const {
|
||||||
attributes,
|
attributes,
|
||||||
defaultPrice,
|
defaultPrice,
|
||||||
|
errors: apiErrors,
|
||||||
open,
|
open,
|
||||||
onClose,
|
onClose,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
@ -125,14 +128,22 @@ const ProductVariantCreateDialog: React.FC<
|
||||||
createInitialForm(attributes, defaultPrice)
|
createInitialForm(attributes, defaultPrice)
|
||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(
|
const reloadForm = () =>
|
||||||
() =>
|
dispatchFormDataAction({
|
||||||
dispatchFormDataAction({
|
data: createInitialForm(attributes, defaultPrice),
|
||||||
data: createInitialForm(attributes, defaultPrice),
|
type: "reload"
|
||||||
type: "reload"
|
});
|
||||||
}),
|
|
||||||
[attributes.length]
|
React.useEffect(reloadForm, [attributes.length]);
|
||||||
);
|
|
||||||
|
useModalDialogOpen(open, {
|
||||||
|
onClose: () => {
|
||||||
|
reloadForm();
|
||||||
|
setStep("values");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const errors = useModalDialogErrors(apiErrors, open);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} maxWidth="md">
|
<Dialog open={open} maxWidth="md">
|
||||||
|
@ -148,6 +159,7 @@ const ProductVariantCreateDialog: React.FC<
|
||||||
attributes={attributes}
|
attributes={attributes}
|
||||||
data={data}
|
data={data}
|
||||||
dispatchFormDataAction={dispatchFormDataAction}
|
dispatchFormDataAction={dispatchFormDataAction}
|
||||||
|
errors={errors}
|
||||||
step={step}
|
step={step}
|
||||||
onStepClick={step => setStep(step)}
|
onStepClick={step => setStep(step)}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue