Fix type error when returning items (#1525) (#1548)

* 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:
Michał Droń 2021-10-27 11:02:23 +02:00 committed by GitHub
parent a466676858
commit d0a6e10cec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View file

@ -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) =>

View file

@ -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;
};