STripe Paymen and PK payemtns and many othe rbacekd and froentened issues

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-07 05:51:36 +00:00
parent 87d1662a18
commit 0386d4bf33
24 changed files with 1079 additions and 174 deletions

View File

@@ -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();