| 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 }) { |
| |
| 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; |
| } |
|
|