diff --git a/src/Redux/services/cards.service.ts b/src/Redux/services/cards.service.ts index 08116c9..fbc43e3 100644 --- a/src/Redux/services/cards.service.ts +++ b/src/Redux/services/cards.service.ts @@ -34,6 +34,13 @@ export const cardsApi = createApi({ body: recipientDetails }), }), + addCardToCart: builder.mutation({ + query: (cardBookingDetails) => ({ // keep the name of the variables being passed here same as when calling the mutation hook + url: `/website/passes/add-to-cart`, + method: "POST", + body: cardBookingDetails + }), + }), }) }); @@ -41,5 +48,6 @@ export const { useGetCardsinCartQuery, useGetCheckoutPageDataQuery, useGetCardBookingDetailsQuery, - useStoreRecipientDetailsMutation + useStoreRecipientDetailsMutation, + useAddCardToCartMutation } = cardsApi; \ No newline at end of file diff --git a/src/pages/CheckoutPage2.tsx b/src/pages/CheckoutPage2.tsx index 4897c2f..4235469 100644 --- a/src/pages/CheckoutPage2.tsx +++ b/src/pages/CheckoutPage2.tsx @@ -7,8 +7,9 @@ import Navbar from '../components/Navbar'; import { Footer } from '../components/Footer'; import { ImageWithFallback } from '../components/figma/ImageWithFallback'; import { useNavigate } from 'react-router-dom'; -import { useGetCheckoutPageDataQuery } from '../Redux/services/cards.service'; +import { useAddCardToCartMutation, useGetCheckoutPageDataQuery } from '../Redux/services/cards.service'; import LoadingSpinner from '../components/LoadingSpinner'; +import { toast } from 'sonner'; /* ─── Types ─── */ export interface CartItem { @@ -202,15 +203,17 @@ function CheckoutConfigCard({ const [noOfDays, setNoOfDays] = useState(item?.minNumber) const cityId = localStorage.getItem("cityId") - + const cityName = localStorage.getItem("cityName") const cardTypeId = item?.cardType?.id const cardId = item?.id const cardMode = item?.cardType?.name === "selective_pass" ? "flexi" : "unlimited" const adultPrice = item?.adultPrice * noOfAdults const childPrice = item?.childPrice * noOfChildren const basePrice = adultPrice + childPrice - const taxAmount = 10 - const strikedPrice = basePrice - 20 + const taxAmount = basePrice * 0.1 + const strikedPrice = basePrice + 20 + + const [addCardToCart] = useAddCardToCartMutation() useEffect(() => { setNoOfAttractions(item?.minNumber) @@ -224,23 +227,35 @@ function CheckoutConfigCard({ const navigate = useNavigate(); const cardBookingDetails = { - cityId, - cardTypeId, - cardId, - noOfAdults, - cardMode, - noOfChildren, + cityXid: cityId, + cardTypeXid: cardTypeId, + cardXid: cardId, + cardMode, // stays as-is + totalAdult: noOfAdults, + baseAmount: basePrice, // static value taxAmount, + totalChild: noOfChildren, noOfAttractions, noOfDays + }; + + const handleProceedToPayment = async () => { + try { + console.log("Adding card to cart", cardBookingDetails); + const response = await addCardToCart(cardBookingDetails); + console.log(response) + const bookingId = response?.data?.id + navigate(`/payment/${bookingId}`) + } catch (error) { + console.error("Error adding card to cart:", error); + toast.error("Failed to move forward. Please try again."); + } } - - return (
-

{item?.city}

+

{cityName}

{item?.cardType?.displayName} @@ -296,12 +311,12 @@ function CheckoutConfigCard({
- navigate(`/payment/390`)} className="w-full py-4 rounded-full bg-[#f95f62] text-white font-poppins text-base font-medium hover:bg-[#e8545a] transition-colors shadow-lg shadow-[#f95f62]/20"> + Proceed to Pay
@@ -414,7 +429,7 @@ export function CheckoutPage2({