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 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
}} }}
/> />