feat(01-06): add plan types and utilities

- Add Plan and PlanFeatures TypeScript interfaces
- Add Profile type with plan relationship
- Create plan utility functions with Italian labels
- Add formatPrice, formatFeatureValue, getPlanBadgeColor helpers
This commit is contained in:
Michele
2026-01-31 13:41:45 +01:00
parent 8319679f7d
commit 7bdc6d3d0a
2 changed files with 78 additions and 0 deletions

49
src/lib/plans.ts Normal file
View File

@@ -0,0 +1,49 @@
import { PlanFeatures } from '@/types/database'
export const PLAN_DISPLAY_ORDER = ['free', 'creator', 'pro'] as const
// Feature display names in Italian
export const FEATURE_LABELS: Record<keyof PlanFeatures, string> = {
posts_per_month: 'Post al mese',
ai_models: 'Modelli AI',
social_accounts: 'Account social',
image_generation: 'Generazione immagini',
automation: 'Automazione',
}
export function formatFeatureValue(
key: keyof PlanFeatures,
value: PlanFeatures[keyof PlanFeatures]
): string {
if (typeof value === 'boolean') {
return value ? 'Incluso' : 'Non incluso'
}
if (Array.isArray(value)) {
return value.length.toString()
}
if (key === 'automation') {
if (value === 'manual') return 'Solo manuale'
if (value === 'full') return 'Completa'
return 'Non inclusa'
}
return value.toString()
}
export function formatPrice(cents: number): string {
if (cents === 0) return 'Gratis'
return `${(cents / 100).toFixed(0)}/mese`
}
export function getPlanBadgeColor(planName: string): string {
switch (planName) {
case 'pro':
return 'bg-purple-100 text-purple-800 border-purple-200'
case 'creator':
return 'bg-blue-100 text-blue-800 border-blue-200'
default:
return 'bg-gray-100 text-gray-800 border-gray-200'
}
}

29
src/types/database.ts Normal file
View File

@@ -0,0 +1,29 @@
export interface Plan {
id: string
name: 'free' | 'creator' | 'pro'
display_name: string
display_name_it: string
price_monthly: number
features: PlanFeatures
created_at: string
}
export interface PlanFeatures {
posts_per_month: number
ai_models: string[]
social_accounts: number
image_generation: boolean
automation: boolean | 'manual' | 'full'
}
export interface Profile {
id: string
tenant_id: string
plan_id: string
email: string
full_name: string | null
avatar_url: string | null
created_at: string
updated_at: string
plans?: Plan
}