working on gift flow

This commit is contained in:
2025-10-20 00:57:07 +03:00
parent 6214e2c0f5
commit a131c9147a
19 changed files with 137 additions and 62 deletions

View File

@@ -5,11 +5,12 @@ import { useTranslation } from "react-i18next";
import { useNavigate, useParams } from "react-router-dom";
import { useCreateOrderMutation } from "redux/api/others";
import { useAppDispatch, useAppSelector } from "redux/hooks";
import { PAYMENT_CONFIRMATION_URL } from "utils/constants";
import { Customer } from "../../otp/types";
export default function useOrder() {
const dispatch = useAppDispatch();
const router = useNavigate();
const navigate = useNavigate();
const { t } = useTranslation();
const { id } = useParams();
const restaurantID = localStorage.getItem("restaurantID");
@@ -25,19 +26,22 @@ export default function useOrder() {
phone,
estimateTime,
officeDetails,
orderType,
giftDetails,
} = useAppSelector(selectCart);
const [createOrder] = useCreateOrderMutation();
const handleCreateOrder = useCallback(() => {
createOrder({
phone: mobilenumber || phone,
phone: mobilenumber || phone || giftDetails?.senderPhone,
couponID: coupon,
discountAmount: 0,
comment: specialRequest,
timeslot: "",
table_id: tables,
deliveryType: "table",
deliveryType: orderType,
dineType: orderType,
type: "table-pickup",
user_id: id,
restorant_id: restaurantID,
@@ -61,13 +65,33 @@ export default function useOrder() {
),
useWallet: 0,
tip,
...(orderType === "gift"
? {
receiverName: giftDetails?.receiverName,
receiverPhone: giftDetails?.receiverPhone,
specialMessage: giftDetails?.message,
keepNameSecret: giftDetails?.isSecret,
senderEmail: giftDetails?.senderEmail,
senderPhone: giftDetails?.senderPhone,
senderName: giftDetails?.senderName,
}
: {}),
})
.then((res: any) => {
if (res.error)
message.error(res.error.data.message || t("order.createOrderFailed"));
else {
if (orderType === "gift")
// navigate(`/${PAYMENT_CONFIRMATION_URL}/${res.data.result.orderID}`, {
// replace: false,
// });
window.location.href = `${PAYMENT_CONFIRMATION_URL}/${res.data.result.orderID}`;
// window.open(
// `${PAYMENT_CONFIRMATION_URL}/${res.data.result.orderID}`,
// );
else navigate(`/${id}/order/${res.data.result.orderID}`);
dispatch(clearCart());
router(`/${id}/order/${res.data.result.orderID}`);
localStorage.setItem("orderID", res.data.result.orderID);
}
})
.catch((error: any) => {
@@ -77,9 +101,17 @@ export default function useOrder() {
createOrder,
mobilenumber,
phone,
giftDetails?.senderPhone,
giftDetails?.receiverName,
giftDetails?.receiverPhone,
giftDetails?.message,
giftDetails?.isSecret,
giftDetails?.senderEmail,
giftDetails?.senderName,
coupon,
specialRequest,
tables,
orderType,
id,
restaurantID,
items,
@@ -88,8 +120,8 @@ export default function useOrder() {
estimateTime,
tip,
t,
navigate,
dispatch,
router,
]);
return { handleCreateOrder };
}