* optional chaining wip * resolve property of undefined error * remove error toast when there is no error * revert makeMutation * apply suggestions from code review * revert newline * code review suggestions * remove unnecessary optional chaining * fix orderRefund undefined errors
This commit is contained in:
parent
a466676858
commit
d0a6e10cec
2 changed files with 10 additions and 5 deletions
|
@ -108,7 +108,7 @@ const OrderRefund: React.FC<OrderRefundProps> = ({ orderId }) => {
|
|||
}
|
||||
});
|
||||
|
||||
return response.errors || [];
|
||||
return response?.errors || [];
|
||||
};
|
||||
|
||||
const handleSubmitProductsRefund = async (
|
||||
|
@ -127,7 +127,7 @@ const OrderRefund: React.FC<OrderRefundProps> = ({ orderId }) => {
|
|||
}
|
||||
});
|
||||
|
||||
return response.errors || [];
|
||||
return response?.errors || [];
|
||||
};
|
||||
|
||||
const handleSubmit = async (formData: OrderRefundSubmitData) =>
|
||||
|
|
|
@ -5,6 +5,7 @@ import OrderReturnPage from "@saleor/orders/components/OrderReturnPage";
|
|||
import { OrderReturnFormData } from "@saleor/orders/components/OrderReturnPage/form";
|
||||
import { useOrderReturnCreateMutation } from "@saleor/orders/mutations";
|
||||
import { useOrderQuery } from "@saleor/orders/queries";
|
||||
import { FulfillmentReturnProducts_orderFulfillmentReturnProducts } from "@saleor/orders/types/FulfillmentReturnProducts";
|
||||
import { orderUrl } from "@saleor/orders/urls";
|
||||
import { OrderErrorCode } from "@saleor/types/globalTypes";
|
||||
import React from "react";
|
||||
|
@ -56,9 +57,11 @@ const OrderReturn: React.FC<OrderReturnProps> = ({ orderId }) => {
|
|||
});
|
||||
|
||||
navigateToOrder(replaceOrder?.id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (errors[0].code === OrderErrorCode.CANNOT_REFUND) {
|
||||
if (errors.some(err => err.code === OrderErrorCode.CANNOT_REFUND)) {
|
||||
notify({
|
||||
autohide: 5000,
|
||||
status: "error",
|
||||
|
@ -90,8 +93,10 @@ const OrderReturn: React.FC<OrderReturnProps> = ({ orderId }) => {
|
|||
});
|
||||
|
||||
const {
|
||||
data: { orderFulfillmentReturnProducts }
|
||||
} = result;
|
||||
data: {
|
||||
orderFulfillmentReturnProducts = {} as FulfillmentReturnProducts_orderFulfillmentReturnProducts
|
||||
} = {}
|
||||
} = result || {};
|
||||
|
||||
return orderFulfillmentReturnProducts.errors;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue