STripe Paymen and PK payemtns and many othe rbacekd and froentened issues
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import PageMeta from '../../components/common/PageMeta';
|
||||
import { useToast } from '../../components/ui/toast/ToastContainer';
|
||||
import { fetchAPI } from '../../services/api';
|
||||
import { PricingPlan } from '../../components/ui/pricing-table';
|
||||
import PricingTable1 from '../../components/ui/pricing-table/pricing-table-1';
|
||||
import { usePageLoading } from '../../context/PageLoadingContext';
|
||||
import { useAuthStore } from '../../store/authStore';
|
||||
|
||||
interface Plan {
|
||||
id: number;
|
||||
@@ -105,6 +107,45 @@ export default function Plans() {
|
||||
const toast = useToast();
|
||||
const { startLoading, stopLoading } = usePageLoading();
|
||||
const [plans, setPlans] = useState<Plan[]>([]);
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const { refreshUser } = useAuthStore();
|
||||
|
||||
// Handle payment success redirect from Stripe
|
||||
useEffect(() => {
|
||||
const success = searchParams.get('success');
|
||||
const sessionId = searchParams.get('session_id');
|
||||
|
||||
if (success === 'true') {
|
||||
// Clear the query params to avoid re-triggering
|
||||
setSearchParams({});
|
||||
|
||||
// Refresh user data to get updated account status
|
||||
refreshUser().then(() => {
|
||||
toast.success('Payment successful! Your subscription is now active.');
|
||||
}).catch((err) => {
|
||||
console.error('Failed to refresh user after payment:', err);
|
||||
// Still show success message since payment was processed
|
||||
toast.success('Payment successful! Please refresh the page to see updates.');
|
||||
});
|
||||
}
|
||||
}, [searchParams, setSearchParams, refreshUser, toast]);
|
||||
|
||||
// Handle PayPal success redirect
|
||||
useEffect(() => {
|
||||
const paypal = searchParams.get('paypal');
|
||||
|
||||
if (paypal === 'success') {
|
||||
setSearchParams({});
|
||||
refreshUser().then(() => {
|
||||
toast.success('PayPal payment successful! Your subscription is now active.');
|
||||
}).catch(() => {
|
||||
toast.success('PayPal payment successful! Please refresh the page to see updates.');
|
||||
});
|
||||
} else if (paypal === 'cancel') {
|
||||
setSearchParams({});
|
||||
toast.info('Payment was cancelled.');
|
||||
}
|
||||
}, [searchParams, setSearchParams, refreshUser, toast]);
|
||||
|
||||
useEffect(() => {
|
||||
loadPlans();
|
||||
|
||||
Reference in New Issue
Block a user