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