Allow returning & refunding partially paid orders (#1572) (#1612)

* allow returning & refunding partially paid orders

* change function name
This commit is contained in:
Michał Droń 2021-11-19 14:32:30 +01:00 committed by GitHub
parent 31adc671a3
commit 241be6b6ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -121,18 +121,42 @@ const OrderRefundAmount: React.FC<OrderRefundAmountProps> = props => {
replacedProductsValue
} = amountData;
const selectedRefundAmount =
const isRefundAutomatic =
type === OrderRefundType.PRODUCTS &&
data.amountCalculationMode === OrderRefundAmountCalculationMode.AUTOMATIC
data.amountCalculationMode === OrderRefundAmountCalculationMode.AUTOMATIC;
const selectedRefundAmount = isRefundAutomatic
? refundTotalAmount?.amount
: data.amount;
const isAmountTooSmall = selectedRefundAmount && selectedRefundAmount <= 0;
const isAmountTooBig = selectedRefundAmount > maxRefund?.amount;
const disableRefundButton = isReturn
? disableSubmitButton || isAmountTooSmall || isAmountTooBig
: !selectedRefundAmount || isAmountTooBig || isAmountTooSmall;
const parsedRefundTotalAmount = isAmountTooBig
? maxRefund
: 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 (
<Card>
@ -199,7 +223,7 @@ const OrderRefundAmount: React.FC<OrderRefundAmountProps> = props => {
previouslyRefunded={previouslyRefunded}
maxRefund={maxRefund}
selectedProductsValue={selectedProductsValue}
refundTotalAmount={refundTotalAmount}
refundTotalAmount={parsedRefundTotalAmount}
shipmentCost={data.refundShipmentCosts && shipmentCost}
replacedProductsValue={replacedProductsValue}
/>
@ -285,7 +309,9 @@ const OrderRefundAmount: React.FC<OrderRefundAmountProps> = props => {
defaultMessage="Refund {currency} {amount}"
description="order refund amount, input button"
values={{
amount: Number(selectedRefundAmount).toFixed(2),
amount: isRefundAutomatic
? parsedRefundTotalAmount.amount.toFixed(2)
: Number(selectedRefundAmount).toFixed(2),
currency: amountCurrency
}}
/>