I'll create a sophisticated modal/dialog component for your AI-powered SaaS with stunning dark/light themes and comprehensive user account management features. This will be a production-ready component with smooth animations and a modern design.
// components/ui/account-modal.tsx
'use client'
import React, { useState, useEffect, Fragment } from 'react'
import { Dialog, Transition } from '@headlessui/react'
import { motion, AnimatePresence } from 'framer-motion'
import {
X,
CreditCard,
Zap,
TrendingUp,
Calendar,
Mail,
User,
Shield,
Sparkles,
ChevronRight,
Download,
Settings,
HelpCircle,
Activity,
Award,
Clock,
AlertCircle,
Check,
Copy,
ExternalLink
} from 'lucide-react'
import { useTheme } from 'next-themes'
import { format } from 'date-fns'
interface AccountModalProps {
isOpen: boolean
onClose: () => void
user?: {
name: string
email: string
avatar?: string
id: string
joinedDate: Date
}
}
export default function AccountModal({ isOpen, onClose, user }: AccountModalProps) {
const { theme, setTheme } = useTheme()
const [activeTab, setActiveTab] = useState('overview')
const [copied, setCopied] = useState(false)
const [mounted, setMounted] = useState(false)
useEffect(() => {
setMounted(true)
}, [])
const handleCopyUserId = () => {
if (user?.id) {
navigator.clipboard.writeText(user.id)
setCopied(true)
setTimeout(() => setCopied(false), 2000)
}
}
// Mock data - replace with real data
const accountData = {
plan: 'Pro',
credits: {
used: 7250,
total: 10000,
bonus: 500
},
subscription: {
status: 'active',
renewalDate: new Date('2025-08-19'),
price: 49.99,
interval: 'monthly'
},
usage: {
apiCalls: 145320,
storage: '2.4 GB',
models: ['GPT-4', 'Claude 3', 'DALL-E 3']
},
achievements: [
{ name: 'Early Adopter', icon: Award, unlocked: true },
{ name: 'Power User', icon: Zap, unlocked: true },
{ name: 'API Master', icon: Activity, unlocked: false }
]
}
const tabs = [
{ id: 'overview', label: 'Overview', icon: TrendingUp },
{ id: 'subscription', label: 'Subscription', icon: CreditCard },
{ id: 'usage', label: 'Usage & Stats', icon: Activity },
{ id: 'settings', label: 'Settings', icon: Settings }
]
const creditPercentage = (accountData.credits.used / accountData.credits.total) * 100
if (!mounted) return null
return (
<Transition appear show={isOpen} as={Fragment}>
<Dialog as="div" className="relative z-50" onClose={onClose}>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="ease-in duration-200"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm" />
</Transition.Child>
<div className="fixed inset-0 overflow-y-auto">
<div className="flex min-h-full items-center justify-center p-4">
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0 scale-95"
enterTo="opacity-100 scale-100"
leave="ease-in duration-200"
leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-95"
>
<Dialog.Panel className="w-full max-w-4xl transform overflow-hidden rounded-2xl bg-white dark:bg-gray-900 shadow-2xl transition-all">
{/* Header */}
<div className="relative bg-gradient-to-br from-blue-600 via-purple-600 to-pink-600 p-8 text-white">
<div className="absolute inset-0 bg-black/20" />
<button
onClick={onClose}
className="absolute right-4 top-4 rounded-lg bg-white/10 p-2 backdrop-blur-sm transition-colors hover:bg-white/20"
>
<X className="h-5 w-5" />
</button>
<div className="relative">
<div className="flex items-center gap-6">
<div className="relative">
<div className="h-20 w-20 rounded-full bg-white/20 backdrop-blur-sm flex items-center justify-center">
{user?.avatar ? (
<img src={user.avatar} alt={user.name} className="h-full w-full rounded-full object-cover" />
) : (
<User className="h-10 w-10" />
)}
</div>
<div className="absolute -bottom-1 -right-1 rounded-full bg-green-500 p-1.5">
<Check className="h-3 w-3 text-white" />
</div>
</div>
<div className="flex-1">
<h2 className="text-2xl font-bold">{user?.name || 'User'}</h2>
<p className="text-white/80">{user?.email}</p>
<div className="mt-2 flex items-center gap-4 text-sm">
<span className="inline-flex items-center gap-1 rounded-full bg-white/20 px-3 py-1 backdrop-blur-sm">
<Sparkles className="h-3 w-3" />
{accountData.plan} Plan
</span>
<span className="text-white/60">
Member since {user?.joinedDate ? format(user.joinedDate, 'MMM yyyy') : 'Jan 2025'}
</span>
</div>
</div>
</div>
</div>
</div>
{/* Tabs */}
<div className="border-b border-gray-200 dark:border-gray-800">
<nav className="flex gap-1 px-6" aria-label="Tabs">
{tabs.map((tab) => (
<button
key={tab.id}
onClick={() => setActiveTab(tab.id)}
className={`
flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors
${activeTab === tab.id
? 'border-b-2 border-blue-600 text-blue-600 dark:border-blue-400 dark:text-blue-400'
: 'text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100'
}
`}
>
<tab.icon className="h-4 w-4" />
{tab.label}
</button>
))}
</nav>
</div>
{/* Content */}
<div className="p-6">
<AnimatePresence mode="wait">
{activeTab === 'overview' && (
<motion.div
key="overview"
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -10 }}
className="space-y-6"
>
{/* Credits Card */}
<div className="rounded-xl bg-gradient-to-br from-blue-50 to-purple-50 dark:from-blue-950/30 dark:to-purple-950/30 p-6">
<div className="flex items-center justify-between mb-4">
<h3 className="text-lg font-semibold text-gray-900 dark:text-white">AI Credits</h3>
<button className="text-sm text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 flex items-center gap-1">
Get more credits
<ChevronRight className="h-4 w-4" />
</button>
</div>
<div className="space-y-3">
<div className="flex justify-between text-sm">
<span className="text-gray-600 dark:text-gray-400">Credits used</span>
<span className="font-medium text-gray-900 dark:text-white">
{accountData.credits.used.toLocaleString()} / {accountData.credits.total.toLocaleString()}
</span>
</div>
<div className="relative h-3 overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700">
<motion.div
initial={{ width: 0 }}
animate={{ width: `${creditPercentage}%` }}
transition={{ duration: 1, ease: "easeOut" }}
className="absolute inset-y-0 left-0 bg-gradient-to-r from-blue-500 to-purple-500"
/>
</div>
{accountData.credits.bonus > 0 && (
<div className="flex items-center gap-2 text-sm text-green-600 dark:text-green-400">
<Sparkles className="h-4 w-4" />
+{accountData.credits.bonus} bonus credits available
</div>
)}
</div>
</div>
{/* Quick Stats */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div className="rounded-lg border border-gray-200 dark:border-gray-800 p-4">
<div className="flex items-center gap-3">
<div className="rounded-lg bg-blue-100 dark:bg-blue-900/30 p-2">
<Activity className="h-5 w-5 text-blue-600 dark:text-blue-400" />
</div>
<div>
<p className="text-sm text-gray-600 dark:text-gray-400">API Calls</p>
<p className="text-xl font-semibold text-gray-900 dark:text-white">
{accountData.usage.apiCalls.toLocaleString()}
</p>
</div>
</div>
</div>
<div className="rounded-lg border border-gray-200 dark:border-gray-800 p-4">
<div className="flex items-center gap-3">
<div className="rounded-lg bg-purple-100 dark:bg-purple-900/30 p-2">
<Shield className="h-5 w-5 text-purple-600 dark:text-purple-400" />
</div>
<div>
<p className="text-sm text-gray-600 dark:text-gray-400">Storage Used</p>
<p className="text-xl font-semibold text-gray-900 dark:text-white">
{accountData.usage.storage}
</p>
</div>
</div>
</div>
<div className="rounded-lg border border-gray-200 dark:border-gray-800 p-4">
<div className="flex items-center gap-3">
<div className="rounded-lg bg-green-100 dark:bg-green-900/30 p-2">
<Clock className="h-5 w-5 text-green-600 dark:text-green-400" />
</div>
<div>
<p className="text-sm text-gray-600 dark:text-gray-400">Renewal</p>
<p className="text-xl font-semibold text-gray-900 dark:text-white">
{format(accountData.subscription.renewalDate, 'MMM d')}
</p>
</div>
</div>
</div>
</div>
{/* Achievements */}
<div>
<h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">Achievements</h3>
<div className="grid grid-cols-3 gap-4">
{accountData.achievements.map((achievement) => (
<div
key={achievement.name}
className={`
rounded-lg border p-4 text-center transition-all
${achievement.unlocked
? 'border-yellow-400 bg-yellow-50 dark:border-yellow-600 dark:bg-yellow-900/20'
: 'border-gray-200 bg-gray-50 dark:border-gray-800 dark:bg-gray-900/50 opacity-50'
}
`}
>
<achievement.icon className={`
mx-auto h-8 w-8 mb-2
${achievement.unlocked
? 'text-yellow-600 dark:text-yellow-400'
: 'text-gray-400 dark:text-gray-600'
}
`} />
<p className="text-sm font-medium text-gray-900 dark:text-white">
{achievement.name}
</p>
</div>
))}
</div>
</div>
</motion.div>
)}
{activeTab === 'subscription' && (
<motion.div
key="subscription"
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -10 }}
className="space-y-6"
>
{/* Current Plan */}
<div className="rounded-xl border border-gray-200 dark:border-gray-800 p-6">
<div className="flex items-center justify-between mb-6">
<div>
<h3 className="text-lg font-semibold text-gray-900 dark:text-white">Current Plan</h3>
<p className="text-sm text-gray-600 dark:text-gray-400">
You're currently on the {accountData.plan} plan
</p>
</div>
<span className="inline-flex items-center gap-1 rounded-full bg-green-100 dark:bg-green-900/30 px-3 py-1 text-sm