implment send amount gift api
This commit is contained in:
@@ -10,14 +10,17 @@ import { EqualltyChoiceBottomSheet } from "pages/pay/components/splitBill/Equall
|
|||||||
import { SplitBillChoiceBottomSheet } from "pages/pay/components/splitBill/SplitBillChoiceBottomSheet";
|
import { SplitBillChoiceBottomSheet } from "pages/pay/components/splitBill/SplitBillChoiceBottomSheet";
|
||||||
import { CustomAmountChoiceBottomSheet } from "pages/pay/components/splitBill/CustomAmountChoiceBottomSheet";
|
import { CustomAmountChoiceBottomSheet } from "pages/pay/components/splitBill/CustomAmountChoiceBottomSheet";
|
||||||
import { PayForYourItemsChoiceBottomSheet } from "pages/pay/components/splitBill/PayForYourItemsChoiceBottomSheet";
|
import { PayForYourItemsChoiceBottomSheet } from "pages/pay/components/splitBill/PayForYourItemsChoiceBottomSheet";
|
||||||
|
import useGidtAmount from "../hooks/useGidtAmount";
|
||||||
|
import { GiftType } from "components/CustomBottomSheet/GiftTypeBottomSheet";
|
||||||
|
|
||||||
type SplitWay = "customAmount" | "equality" | "payForItems" | null;
|
type SplitWay = "customAmount" | "equality" | "payForItems" | null;
|
||||||
|
|
||||||
export default function CheckoutButton({ form }: { form: FormInstance }) {
|
export default function CheckoutButton({ form }: { form: FormInstance }) {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { orderType } = useAppSelector(selectCart);
|
const { orderType, giftDetails } = useAppSelector(selectCart);
|
||||||
const { handleCreateOrder } = useOrder();
|
const { handleCreateOrder } = useOrder();
|
||||||
|
const { handleCreateGiftAmount } = useGidtAmount();
|
||||||
const [selectedSplitWay, setSelectedSplitWay] = useState<SplitWay>(null);
|
const [selectedSplitWay, setSelectedSplitWay] = useState<SplitWay>(null);
|
||||||
const [
|
const [
|
||||||
isSplitBillChoiceBottomSheetOpen,
|
isSplitBillChoiceBottomSheetOpen,
|
||||||
@@ -47,11 +50,18 @@ export default function CheckoutButton({ form }: { form: FormInstance }) {
|
|||||||
const handlePlaceOrderClick = useCallback(async () => {
|
const handlePlaceOrderClick = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
await form.validateFields();
|
await form.validateFields();
|
||||||
|
if (
|
||||||
|
orderType === OrderType.Gift &&
|
||||||
|
giftDetails?.giftType === GiftType.Vouchers
|
||||||
|
) {
|
||||||
|
handleCreateGiftAmount();
|
||||||
|
} else {
|
||||||
handleCreateOrder();
|
handleCreateOrder();
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
}, [handleCreateOrder, form]);
|
}, [handleCreateOrder, handleCreateGiftAmount, form, orderType, giftDetails]);
|
||||||
|
|
||||||
const shouldShowSplitBill = useMemo(
|
const shouldShowSplitBill = useMemo(
|
||||||
() => orderType === OrderType.DineIn,
|
() => orderType === OrderType.DineIn,
|
||||||
|
|||||||
82
src/pages/checkout/hooks/useGidtAmount.ts
Normal file
82
src/pages/checkout/hooks/useGidtAmount.ts
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
import { message } from "antd";
|
||||||
|
import {
|
||||||
|
clearCart,
|
||||||
|
selectCart,
|
||||||
|
selectGrandTotal,
|
||||||
|
} from "features/order/orderSlice";
|
||||||
|
import { useCallback } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
|
import { useCreateGiftAmountMutation } from "redux/api/others";
|
||||||
|
import { useAppDispatch, useAppSelector } from "redux/hooks";
|
||||||
|
import { PAYMENT_CONFIRMATION_URL } from "utils/constants";
|
||||||
|
|
||||||
|
export default function useGidtAmount() {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { subdomain } = useParams();
|
||||||
|
const restaurantID = localStorage.getItem("restaurantID");
|
||||||
|
const { giftDetails } = useAppSelector(selectCart);
|
||||||
|
|
||||||
|
const orderPrice = useAppSelector(selectGrandTotal);
|
||||||
|
|
||||||
|
const [createGiftAmount] = useCreateGiftAmountMutation();
|
||||||
|
|
||||||
|
const handleCreateGiftAmount = useCallback(() => {
|
||||||
|
const loadingMessageKey = "create-order-loader";
|
||||||
|
message.loading({
|
||||||
|
content: t("order.creatingOrder", {
|
||||||
|
defaultValue: "Creating order...",
|
||||||
|
}),
|
||||||
|
key: loadingMessageKey,
|
||||||
|
duration: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
createGiftAmount({
|
||||||
|
sender_name: giftDetails?.senderName,
|
||||||
|
sender_phone: giftDetails?.senderPhone,
|
||||||
|
sender_email: giftDetails?.senderEmail,
|
||||||
|
receiver_name: giftDetails?.receiverName,
|
||||||
|
receiver_phone: giftDetails?.receiverPhone,
|
||||||
|
special_message: giftDetails?.message,
|
||||||
|
keep_name_secret: giftDetails?.isSecret,
|
||||||
|
restaurant_id: restaurantID,
|
||||||
|
order_amount: orderPrice,
|
||||||
|
gift_card_id: giftDetails?.cardId,
|
||||||
|
}).then((res: unknown) => {
|
||||||
|
message.destroy(loadingMessageKey);
|
||||||
|
const mutationResult = res as {
|
||||||
|
data?: { result?: { orderID?: string } };
|
||||||
|
error?: { data?: { message?: string } };
|
||||||
|
};
|
||||||
|
if (mutationResult.error)
|
||||||
|
message.error(
|
||||||
|
mutationResult.error.data?.message || t("order.createOrderFailed"),
|
||||||
|
);
|
||||||
|
else {
|
||||||
|
const redirectMessageKey = "order-redirect-loader";
|
||||||
|
|
||||||
|
message.loading({
|
||||||
|
content: t("order.redirectingToPayment", {
|
||||||
|
defaultValue: "Redirecting to payment...",
|
||||||
|
}),
|
||||||
|
key: redirectMessageKey,
|
||||||
|
duration: 0,
|
||||||
|
});
|
||||||
|
window.location.href = `${PAYMENT_CONFIRMATION_URL}/${mutationResult.data?.result?.orderID}`;
|
||||||
|
dispatch(clearCart());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [
|
||||||
|
createGiftAmount,
|
||||||
|
orderPrice,
|
||||||
|
giftDetails,
|
||||||
|
restaurantID,
|
||||||
|
t,
|
||||||
|
navigate,
|
||||||
|
subdomain,
|
||||||
|
dispatch,
|
||||||
|
]);
|
||||||
|
return { handleCreateGiftAmount };
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
EGIFT_CARDS_URL,
|
EGIFT_CARDS_URL,
|
||||||
REDEEM_DETAILS_URL,
|
REDEEM_DETAILS_URL,
|
||||||
LOYALTY_HISTORY_URL,
|
LOYALTY_HISTORY_URL,
|
||||||
|
CREATE_GIFT_AMOUNT_URL,
|
||||||
} from "utils/constants";
|
} from "utils/constants";
|
||||||
|
|
||||||
import { OrderDetails } from "pages/checkout/hooks/types";
|
import { OrderDetails } from "pages/checkout/hooks/types";
|
||||||
@@ -202,6 +203,13 @@ export const branchApi = baseApi.injectEndpoints({
|
|||||||
return response.result.data.orders;
|
return response.result.data.orders;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
createGiftAmount: builder.mutation({
|
||||||
|
query: (body: any) => ({
|
||||||
|
url: CREATE_GIFT_AMOUNT_URL,
|
||||||
|
method: "POST",
|
||||||
|
body,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
export const {
|
export const {
|
||||||
@@ -218,4 +226,5 @@ export const {
|
|||||||
useGetEGiftCardsQuery,
|
useGetEGiftCardsQuery,
|
||||||
useGetRedeemDetailsQuery,
|
useGetRedeemDetailsQuery,
|
||||||
useGetLoyaltyHistoryQuery,
|
useGetLoyaltyHistoryQuery,
|
||||||
|
useCreateGiftAmountMutation,
|
||||||
} = branchApi;
|
} = branchApi;
|
||||||
|
|||||||
@@ -111,3 +111,4 @@ export const DISCOUNT_URL = `${BASE_URL}getDiscount`;
|
|||||||
export const EGIFT_CARDS_URL = `${BASE_URL}gift/cards`;
|
export const EGIFT_CARDS_URL = `${BASE_URL}gift/cards`;
|
||||||
export const REDEEM_DETAILS_URL = `${BASE_URL}gift/getGiftOrderByVoucherCode`;
|
export const REDEEM_DETAILS_URL = `${BASE_URL}gift/getGiftOrderByVoucherCode`;
|
||||||
export const LOYALTY_HISTORY_URL = `${BASE_URL}loyaltyHistory`;
|
export const LOYALTY_HISTORY_URL = `${BASE_URL}loyaltyHistory`;
|
||||||
|
export const CREATE_GIFT_AMOUNT_URL = `${BASE_URL}gift/addGiftAmount`;
|
||||||
Reference in New Issue
Block a user