add loader while creating order
This commit is contained in:
@@ -60,6 +60,15 @@ export default function useOrder() {
|
||||
}, [orderType]);
|
||||
|
||||
const handleCreateOrder = useCallback(() => {
|
||||
const loadingMessageKey = "create-order-loader";
|
||||
message.loading({
|
||||
content: t("order.creatingOrder", {
|
||||
defaultValue: "Creating order...",
|
||||
}),
|
||||
key: loadingMessageKey,
|
||||
duration: 0,
|
||||
});
|
||||
|
||||
createOrder({
|
||||
phone: mobilenumber || phone || giftDetails?.senderPhone,
|
||||
comment: specialRequest,
|
||||
@@ -114,6 +123,7 @@ export default function useOrder() {
|
||||
: {}),
|
||||
})
|
||||
.then((res: unknown) => {
|
||||
message.destroy(loadingMessageKey);
|
||||
const mutationResult = res as {
|
||||
data?: { result?: { orderID?: string } };
|
||||
error?: { data?: { message?: string } };
|
||||
@@ -124,7 +134,10 @@ export default function useOrder() {
|
||||
);
|
||||
else {
|
||||
const redirectMessageKey = "order-redirect-loader";
|
||||
if (orderType === OrderType.Gift && mutationResult.data?.result?.orderID) {
|
||||
if (
|
||||
orderType === OrderType.Gift &&
|
||||
mutationResult.data?.result?.orderID
|
||||
) {
|
||||
message.loading({
|
||||
content: t("order.redirectingToPayment", {
|
||||
defaultValue: "Redirecting to payment...",
|
||||
@@ -136,17 +149,18 @@ export default function useOrder() {
|
||||
} else {
|
||||
message.destroy(redirectMessageKey);
|
||||
if (mutationResult.data?.result?.orderID) {
|
||||
navigate(`/${subdomain}/order/${mutationResult.data.result.orderID}`);
|
||||
navigate(
|
||||
`/${subdomain}/order/${mutationResult.data.result.orderID}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
dispatch(clearCart());
|
||||
if (mutationResult.data?.result?.orderID) {
|
||||
localStorage.setItem("orderID", mutationResult.data.result.orderID);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
message.destroy(loadingMessageKey);
|
||||
console.error("Create Order failed:", error);
|
||||
message.error(t("order.createOrderFailed"));
|
||||
});
|
||||
}, [
|
||||
createOrder,
|
||||
|
||||
Reference in New Issue
Block a user