From 7bdc6d3d0a879e6a6bb0abf5cba93fa7db415941 Mon Sep 17 00:00:00 2001 From: Michele Date: Sat, 31 Jan 2026 13:41:45 +0100 Subject: [PATCH] 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 --- src/lib/plans.ts | 49 +++++++++++++++++++++++++++++++++++++++++++ src/types/database.ts | 29 +++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/lib/plans.ts create mode 100644 src/types/database.ts diff --git a/src/lib/plans.ts b/src/lib/plans.ts new file mode 100644 index 0000000..df90dd7 --- /dev/null +++ b/src/lib/plans.ts @@ -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 = { + 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' + } +} diff --git a/src/types/database.ts b/src/types/database.ts new file mode 100644 index 0000000..01119ba --- /dev/null +++ b/src/types/database.ts @@ -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 +}