* allow returning & refunding partially paid orders * change function name
This commit is contained in:
parent
31adc671a3
commit
241be6b6ee
1 changed files with 35 additions and 9 deletions
|
@ -121,18 +121,42 @@ const OrderRefundAmount: React.FC<OrderRefundAmountProps> = props => {
|
||||||
replacedProductsValue
|
replacedProductsValue
|
||||||
} = amountData;
|
} = amountData;
|
||||||
|
|
||||||
const selectedRefundAmount =
|
const isRefundAutomatic =
|
||||||
type === OrderRefundType.PRODUCTS &&
|
type === OrderRefundType.PRODUCTS &&
|
||||||
data.amountCalculationMode === OrderRefundAmountCalculationMode.AUTOMATIC
|
data.amountCalculationMode === OrderRefundAmountCalculationMode.AUTOMATIC;
|
||||||
? refundTotalAmount?.amount
|
|
||||||
: data.amount;
|
const selectedRefundAmount = isRefundAutomatic
|
||||||
|
? refundTotalAmount?.amount
|
||||||
|
: data.amount;
|
||||||
|
|
||||||
const isAmountTooSmall = selectedRefundAmount && selectedRefundAmount <= 0;
|
const isAmountTooSmall = selectedRefundAmount && selectedRefundAmount <= 0;
|
||||||
const isAmountTooBig = selectedRefundAmount > maxRefund?.amount;
|
const isAmountTooBig = selectedRefundAmount > maxRefund?.amount;
|
||||||
|
|
||||||
const disableRefundButton = isReturn
|
const parsedRefundTotalAmount = isAmountTooBig
|
||||||
? disableSubmitButton || isAmountTooSmall || isAmountTooBig
|
? maxRefund
|
||||||
: !selectedRefundAmount || isAmountTooBig || isAmountTooSmall;
|
: refundTotalAmount;
|
||||||
|
|
||||||
|
const shouldRefundButtonBeDisabled = () => {
|
||||||
|
if (isAmountTooSmall) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
data.amountCalculationMode === OrderRefundAmountCalculationMode.MANUAL ||
|
||||||
|
type === OrderRefundType.MISCELLANEOUS
|
||||||
|
) {
|
||||||
|
if (isAmountTooBig) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isReturn) {
|
||||||
|
return disableSubmitButton;
|
||||||
|
}
|
||||||
|
return !selectedRefundAmount;
|
||||||
|
};
|
||||||
|
|
||||||
|
const disableRefundButton = shouldRefundButtonBeDisabled();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
|
@ -199,7 +223,7 @@ const OrderRefundAmount: React.FC<OrderRefundAmountProps> = props => {
|
||||||
previouslyRefunded={previouslyRefunded}
|
previouslyRefunded={previouslyRefunded}
|
||||||
maxRefund={maxRefund}
|
maxRefund={maxRefund}
|
||||||
selectedProductsValue={selectedProductsValue}
|
selectedProductsValue={selectedProductsValue}
|
||||||
refundTotalAmount={refundTotalAmount}
|
refundTotalAmount={parsedRefundTotalAmount}
|
||||||
shipmentCost={data.refundShipmentCosts && shipmentCost}
|
shipmentCost={data.refundShipmentCosts && shipmentCost}
|
||||||
replacedProductsValue={replacedProductsValue}
|
replacedProductsValue={replacedProductsValue}
|
||||||
/>
|
/>
|
||||||
|
@ -285,7 +309,9 @@ const OrderRefundAmount: React.FC<OrderRefundAmountProps> = props => {
|
||||||
defaultMessage="Refund {currency} {amount}"
|
defaultMessage="Refund {currency} {amount}"
|
||||||
description="order refund amount, input button"
|
description="order refund amount, input button"
|
||||||
values={{
|
values={{
|
||||||
amount: Number(selectedRefundAmount).toFixed(2),
|
amount: isRefundAutomatic
|
||||||
|
? parsedRefundTotalAmount.amount.toFixed(2)
|
||||||
|
: Number(selectedRefundAmount).toFixed(2),
|
||||||
currency: amountCurrency
|
currency: amountCurrency
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue