Subscription implementation complete, Renewal system implemented

This commit is contained in:
ajaysi
2025-10-23 21:47:52 +05:30
parent 2240cefa30
commit a3f25f23c9
21 changed files with 1016 additions and 150 deletions

View File

@@ -0,0 +1,39 @@
import { useCallback } from 'react';
import { useSubscription } from '../contexts/SubscriptionContext';
interface ApiError {
response?: {
status?: number;
data?: any;
};
message?: string;
}
export const useSubscriptionErrorHandler = () => {
const { subscription, showExpiredModal } = useSubscription();
const handleApiError = useCallback((error: ApiError) => {
// Check if it's a subscription-related error
const status = error.response?.status;
if (status === 429 || status === 402) {
console.log('Subscription error detected, letting global handler manage modal');
// Don't show modal directly - let the global API client handler manage it
// This ensures proper subscription state checking and modal spam prevention
return true; // Indicates subscription error was detected
}
return false; // Not a subscription error
}, [subscription]);
const handleSubscriptionExpired = useCallback(() => {
console.log('Manually triggering subscription expired modal');
showExpiredModal();
}, [showExpiredModal]);
return {
handleApiError,
handleSubscriptionExpired
};
};