select the same card on checkout page which we select on the buy cards page

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
aryabenade
2026-04-26 19:52:31 +05:30
parent 7b3833e5f7
commit 0dbba7f80e
2 changed files with 12 additions and 11 deletions

View File

@@ -6,7 +6,7 @@ import {
import Navbar from '../components/Navbar';
import { Footer } from '../components/Footer';
import { ImageWithFallback } from '../components/figma/ImageWithFallback';
import { useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { useAddCardToCartMutation, useGetCheckoutPageDataQuery } from '../Redux/services/cards.service';
import LoadingSpinner from '../components/LoadingSpinner';
import { toast } from 'sonner';
@@ -189,7 +189,7 @@ function CheckoutConfigCard({
} else {
throw new Error(response?.error?.data?.message)
}
} catch (error:any) {
} catch (error: any) {
toast.error(error.message);
}
}
@@ -307,6 +307,7 @@ export function CheckoutPage({
currentPage,
}: any) {
const navigate = useNavigate();
const location = useLocation()
// Default item (you can pass via props later)
const baseUrl = import.meta.env.VITE_BASE_URL;
@@ -321,10 +322,11 @@ export function CheckoutPage({
const unlimitedCard = checkoutPageData?.cards[1] ?? null
const attractions = checkoutPageData?.attractions ?? [];
const [checkoutItem, setCheckoutItem] = useState(flexiCard);
const selectedCard = location.state?.selectedCard === "selective_pass" ? flexiCard : unlimitedCard
const [checkoutItem, setCheckoutItem] = useState(selectedCard);
useEffect(() => {
setCheckoutItem(flexiCard)
setCheckoutItem(selectedCard)
}, [cards])
if (isLoading) {

View File

@@ -166,11 +166,10 @@ export function PassesPage({
return (<LoadingSpinner />)
}
const handleCheckoutClick = () => {
const handleCheckoutClick = (cardTypeName:string) => {
console.log('Proceeding to checkout for user:', user);
// Add your checkout logic here
navigate('/checkout');
navigate('/checkout', { state: { selectedCard: cardTypeName } });
};
const handleSignInClick = () => {
@@ -283,7 +282,7 @@ export function PassesPage({
? "bg-primary hover:bg-primary/90 text-white hover:shadow-lg"
: "bg-gray-400 hover:bg-gray-400 text-white hover:shadow-md"
}`}
onClick={user ? handleCheckoutClick : handleSignInClick}
onClick={() => user ? handleCheckoutClick(cards[0]?.cardType?.cardTypeName) : handleSignInClick}
disabled={selectedPass !== passTypes[0].id}
>
@@ -373,7 +372,7 @@ export function PassesPage({
}`}
disabled={selectedPass !== passTypes[1].id}
onClick={user ? handleCheckoutClick : handleSignInClick}
onClick={() => user ? handleCheckoutClick(cards[1]?.cardType?.cardTypeName) : handleSignInClick}
>
{user ? 'PURCHASE NOW' : 'LOGIN TO BUY PASS'}