RYP / src /contexts /SubscriptionContext.tsx
Soumya79's picture
Upload 1361 files
f91a684 verified
import React, { createContext, useContext, useState, ReactNode } from 'react';
type Tier = 'free' | 'pro';
interface SubscriptionContextType {
tier: Tier;
setTier: (tier: Tier) => void;
isPro: boolean;
}
const SubscriptionContext = createContext<SubscriptionContextType | undefined>(undefined);
export function SubscriptionProvider({ children }: { children: ReactNode }) {
// Hardcoded to 'free' by default for testing. In production, this would come from auth/backend.
const [tier, setTier] = useState<Tier>('free');
return (
<SubscriptionContext.Provider value={{ tier, setTier, isPro: tier === 'pro' }}>
{children}
</SubscriptionContext.Provider>
);
}
export function useSubscription() {
const context = useContext(SubscriptionContext);
if (context === undefined) {
throw new Error('useSubscription must be used within a SubscriptionProvider');
}
return context;
}