Fix initial discount calculation on draft order line (#1651)

This commit is contained in:
Jakub Majorek 2021-12-07 10:44:49 +01:00 committed by GitHub
parent 05cc720b6e
commit f78d5fcc5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -0,0 +1,14 @@
import { useEffect, useRef } from "react";
export function useUpdateEffect(fn: () => void, depArr: any[]) {
const mounted = useRef(false);
useEffect(() => {
if (mounted.current) {
return fn();
}
mounted.current = true;
}, depArr);
}
export default useUpdateEffect;

View file

@ -14,6 +14,7 @@ import ConfirmButton, {
import PriceField from "@saleor/components/PriceField";
import RadioGroupField from "@saleor/components/RadioGroupField";
import { Money } from "@saleor/fragments/types/Money";
import { useUpdateEffect } from "@saleor/hooks/useUpdateEffect";
import { buttonMessages } from "@saleor/intl";
import { makeStyles } from "@saleor/macaw-ui";
import { DiscountValueTypeEnum } from "@saleor/types/globalTypes";
@ -258,7 +259,7 @@ const OrderDiscountCommonModal: React.FC<OrderDiscountCommonModalProps> = ({
setValue(recalculatedValue);
};
useEffect(handleValueConversion, [calculationMode]);
useUpdateEffect(handleValueConversion, [calculationMode]);
const dialogTitle =
modalType === ORDER_LINE_DISCOUNT