Subscription implementation complete, Renewal system implemented
This commit is contained in:
39
frontend/src/hooks/useSubscriptionErrorHandler.ts
Normal file
39
frontend/src/hooks/useSubscriptionErrorHandler.ts
Normal 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
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user