feat: update frontend for account-based subscriptions
Replace all team_id/team_admin references with account_id/owner across types, store, hooks, API clients, components, and pages. Add new AccountSettingsPage, UpgradePrompt, CheckoutButton, useSubscription hook, and accounts API client. AuthStore now parallel-fetches account and subscription data alongside user profile. Also fix folder sidebar not refreshing after tree deletion by dispatching the folder-changed event in handleDeleteTree. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
45
frontend/src/hooks/useSubscription.ts
Normal file
45
frontend/src/hooks/useSubscription.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { useAuthStore } from '@/store/authStore'
|
||||
|
||||
export function useSubscription() {
|
||||
const subscription = useAuthStore((s) => s.subscription)
|
||||
|
||||
const plan = subscription?.subscription.plan ?? 'free'
|
||||
const limits = subscription?.limits ?? null
|
||||
const usage = subscription?.usage ?? null
|
||||
const isActive = subscription?.subscription.status === 'active' || subscription?.subscription.status === 'trialing'
|
||||
|
||||
const isPaidPlan = plan === 'pro' || plan === 'team'
|
||||
|
||||
const canUseFeature = (feature: 'custom_branding' | 'priority_support'): boolean => {
|
||||
if (!limits) return false
|
||||
return limits[feature]
|
||||
}
|
||||
|
||||
const isAtTreeLimit = (): boolean => {
|
||||
if (!limits || !usage) return false
|
||||
if (limits.max_trees === null) return false // unlimited
|
||||
return usage.tree_count >= limits.max_trees
|
||||
}
|
||||
|
||||
const isAtSessionLimit = (): boolean => {
|
||||
if (!limits || !usage) return false
|
||||
if (limits.max_sessions_per_month === null) return false
|
||||
return usage.session_count_this_month >= limits.max_sessions_per_month
|
||||
}
|
||||
|
||||
const formatLimit = (value: number | null): string => {
|
||||
return value === null ? 'Unlimited' : String(value)
|
||||
}
|
||||
|
||||
return {
|
||||
plan,
|
||||
limits,
|
||||
usage,
|
||||
isActive,
|
||||
isPaidPlan,
|
||||
canUseFeature,
|
||||
isAtTreeLimit,
|
||||
isAtSessionLimit,
|
||||
formatLimit,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user