Fix initial discount calculation on draft order line (#1651)
This commit is contained in:
parent
05cc720b6e
commit
f78d5fcc5d
2 changed files with 16 additions and 1 deletions
14
src/hooks/useUpdateEffect.ts
Normal file
14
src/hooks/useUpdateEffect.ts
Normal 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;
|
|
@ -14,6 +14,7 @@ import ConfirmButton, {
|
||||||
import PriceField from "@saleor/components/PriceField";
|
import PriceField from "@saleor/components/PriceField";
|
||||||
import RadioGroupField from "@saleor/components/RadioGroupField";
|
import RadioGroupField from "@saleor/components/RadioGroupField";
|
||||||
import { Money } from "@saleor/fragments/types/Money";
|
import { Money } from "@saleor/fragments/types/Money";
|
||||||
|
import { useUpdateEffect } from "@saleor/hooks/useUpdateEffect";
|
||||||
import { buttonMessages } from "@saleor/intl";
|
import { buttonMessages } from "@saleor/intl";
|
||||||
import { makeStyles } from "@saleor/macaw-ui";
|
import { makeStyles } from "@saleor/macaw-ui";
|
||||||
import { DiscountValueTypeEnum } from "@saleor/types/globalTypes";
|
import { DiscountValueTypeEnum } from "@saleor/types/globalTypes";
|
||||||
|
@ -258,7 +259,7 @@ const OrderDiscountCommonModal: React.FC<OrderDiscountCommonModalProps> = ({
|
||||||
setValue(recalculatedValue);
|
setValue(recalculatedValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(handleValueConversion, [calculationMode]);
|
useUpdateEffect(handleValueConversion, [calculationMode]);
|
||||||
|
|
||||||
const dialogTitle =
|
const dialogTitle =
|
||||||
modalType === ORDER_LINE_DISCOUNT
|
modalType === ORDER_LINE_DISCOUNT
|
||||||
|
|
Loading…
Reference in a new issue