Fix not updated file attribute field on delete (#911)
This commit is contained in:
parent
962b84b256
commit
d5ae972b0e
3 changed files with 36 additions and 18 deletions
|
@ -29,7 +29,7 @@ import { mapMetadataItemToInput } from "@saleor/utils/maps";
|
||||||
import getMetadata from "@saleor/utils/metadata/getMetadata";
|
import getMetadata from "@saleor/utils/metadata/getMetadata";
|
||||||
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
|
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
|
||||||
import useRichText from "@saleor/utils/richText/useRichText";
|
import useRichText from "@saleor/utils/richText/useRichText";
|
||||||
import React, { useEffect } from "react";
|
import React from "react";
|
||||||
|
|
||||||
export interface PageFormData extends MetadataFormData {
|
export interface PageFormData extends MetadataFormData {
|
||||||
isPublished: boolean;
|
isPublished: boolean;
|
||||||
|
@ -144,10 +144,6 @@ function usePageForm(
|
||||||
triggerChange
|
triggerChange
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
attributesWithNewFileValue.set([]);
|
|
||||||
}, [page]);
|
|
||||||
|
|
||||||
// Need to make it function to always have content.current up to date
|
// Need to make it function to always have content.current up to date
|
||||||
const getData = (): PageData => ({
|
const getData = (): PageData => ({
|
||||||
...form.data,
|
...form.data,
|
||||||
|
@ -165,9 +161,19 @@ function usePageForm(
|
||||||
attributesWithNewFileValue: attributesWithNewFileValue.data
|
attributesWithNewFileValue: attributesWithNewFileValue.data
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleSubmit = async (data: PageData) => {
|
||||||
|
const errors = await onSubmit(data);
|
||||||
|
|
||||||
|
if (!errors?.length && pageExists) {
|
||||||
|
attributesWithNewFileValue.set([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
};
|
||||||
|
|
||||||
const submit = () =>
|
const submit = () =>
|
||||||
pageExists
|
pageExists
|
||||||
? handleFormSubmit(getSubmitData(), onSubmit, setChanged)
|
? handleFormSubmit(getSubmitData(), handleSubmit, setChanged)
|
||||||
: onSubmit(getSubmitData());
|
: onSubmit(getSubmitData());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -37,7 +37,7 @@ import getMetadata from "@saleor/utils/metadata/getMetadata";
|
||||||
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
|
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
|
||||||
import useRichText from "@saleor/utils/richText/useRichText";
|
import useRichText from "@saleor/utils/richText/useRichText";
|
||||||
import { diff } from "fast-array-diff";
|
import { diff } from "fast-array-diff";
|
||||||
import React, { useEffect } from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { ProductStockFormsetData, ProductStockInput } from "../ProductStocks";
|
import { ProductStockFormsetData, ProductStockInput } from "../ProductStocks";
|
||||||
|
|
||||||
|
@ -260,10 +260,6 @@ function useProductUpdateForm(
|
||||||
triggerChange
|
triggerChange
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
attributesWithNewFileValue.set([]);
|
|
||||||
}, [product]);
|
|
||||||
|
|
||||||
const data: ProductUpdateData = {
|
const data: ProductUpdateData = {
|
||||||
...form.data,
|
...form.data,
|
||||||
attributes: getAttributesDisplayData(
|
attributes: getAttributesDisplayData(
|
||||||
|
@ -284,8 +280,18 @@ function useProductUpdateForm(
|
||||||
description: description.current
|
description: description.current
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleSubmit = async (data: ProductUpdateSubmitData) => {
|
||||||
|
const errors = await onSubmit(data);
|
||||||
|
|
||||||
|
if (!errors?.length) {
|
||||||
|
attributesWithNewFileValue.set([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
};
|
||||||
|
|
||||||
const submit = async () =>
|
const submit = async () =>
|
||||||
handleFormSubmit(getSubmitData(), onSubmit, setChanged);
|
handleFormSubmit(getSubmitData(), handleSubmit, setChanged);
|
||||||
|
|
||||||
const disabled =
|
const disabled =
|
||||||
!opts.hasVariants &&
|
!opts.hasVariants &&
|
||||||
|
|
|
@ -29,7 +29,7 @@ import { mapMetadataItemToInput } from "@saleor/utils/maps";
|
||||||
import getMetadata from "@saleor/utils/metadata/getMetadata";
|
import getMetadata from "@saleor/utils/metadata/getMetadata";
|
||||||
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
|
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
|
||||||
import { diff } from "fast-array-diff";
|
import { diff } from "fast-array-diff";
|
||||||
import React, { useEffect } from "react";
|
import React from "react";
|
||||||
|
|
||||||
import handleFormSubmit from "../../../utils/handlers/handleFormSubmit";
|
import handleFormSubmit from "../../../utils/handlers/handleFormSubmit";
|
||||||
import { ProductStockInput } from "../ProductStocks";
|
import { ProductStockInput } from "../ProductStocks";
|
||||||
|
@ -166,10 +166,6 @@ function useProductVariantUpdateForm(
|
||||||
triggerChange();
|
triggerChange();
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
attributesWithNewFileValue.set([]);
|
|
||||||
}, [variant]);
|
|
||||||
|
|
||||||
const dataStocks = stocks.data.map(stock => stock.id);
|
const dataStocks = stocks.data.map(stock => stock.id);
|
||||||
const variantStocks = variant?.stocks.map(stock => stock.warehouse.id) || [];
|
const variantStocks = variant?.stocks.map(stock => stock.warehouse.id) || [];
|
||||||
const stockDiff = diff(variantStocks, dataStocks);
|
const stockDiff = diff(variantStocks, dataStocks);
|
||||||
|
@ -206,7 +202,17 @@ function useProductVariantUpdateForm(
|
||||||
updateStocks
|
updateStocks
|
||||||
};
|
};
|
||||||
|
|
||||||
const submit = () => handleFormSubmit(submitData, onSubmit, setChanged);
|
const handleSubmit = async (data: ProductVariantUpdateSubmitData) => {
|
||||||
|
const errors = await onSubmit(data);
|
||||||
|
|
||||||
|
if (!errors?.length) {
|
||||||
|
attributesWithNewFileValue.set([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
};
|
||||||
|
|
||||||
|
const submit = () => handleFormSubmit(submitData, handleSubmit, setChanged);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
change: handleChange,
|
change: handleChange,
|
||||||
|
|
Loading…
Reference in a new issue