import React, { useState, useEffect } from 'react'; // Import components and hooks import { useSEO } from '../hooks/useSEO'; import { useNavigate } from 'react-router-dom'; import { useAuthStore } from '../stores/authStore'; // Import custom components import ShareableImage from '../components/ShareableImage'; const Profile: React.FC = () => { const navigate = useNavigate(); const [loading, setLoading] = useState(true); const { user, userData, isAuthenticated } = useAuthStore(); // SEO optimization for Profile page useSEO({ title: 'My Profile - AiFigure | Manage Your AI Action Figure Creations', description: 'View and manage your AI-generated action figures, account settings, and token balance. Track your creative journey with AiFigure\'s AI art generation platform.', keywords: 'AiFigure profile, my AI action figures, account settings, token balance, AI art portfolio, user dashboard, generated images gallery', ogTitle: 'My Profile - AiFigure | Manage Your AI Action Figure Creations', ogDescription: 'View and manage your AI-generated action figures, account settings, and token balance. Track your creative journey with AiFigure.', ogImage: 'https://aifigure.com/profile-og-image.jpg', ogUrl: window.location.href, twitterTitle: 'My Profile - AiFigure | Manage Your AI Action Figure Creations', twitterDescription: 'View and manage your AI-generated action figures, account settings, and token balance. Track your creative journey with AiFigure.', twitterImage: 'https://aifigure.com/profile-og-image.jpg', canonical: window.location.href, type: 'website', }); useEffect(() => { if (!isAuthenticated) { navigate('/auth'); return; } // User data is now managed centrally by the auth store if (userData) { setLoading(false); } }, [isAuthenticated, userData, navigate]); // const getTierInfo = (tier: string) => { // switch (tier) { // case 'free': // return { name: 'Free', color: 'bg-gray-600', monthlyTokens: 25 }; // case 'basic': // return { name: 'Basic', color: 'bg-blue-600', monthlyTokens: 50 }; // case 'pro': // return { name: 'Pro', color: 'bg-purple-600', monthlyTokens: 200 }; // case 'premium': // return { name: 'Premium', color: 'bg-yellow-600', monthlyTokens: 1000 }; // default: // return { name: 'Free', color: 'bg-gray-600', monthlyTokens: 25 }; // } // }; if (loading) { return (
Loading profile...
); } if (!user) { return (

Please sign in

You need to be signed in to view your profile.

); } if (!userData) { return (

Loading your profile...

Fetching your account information.

); } return (
{/* Profile Header */}

{user.email?.split('@')[0]}

{user.email}

{/*
{tierInfo.name} Plan Member since {userData.createdAt.toLocaleDateString()}
*/}
{/* Token Balance Card */}

Token Balance

Available for AI generation

{userData.tokens}
tokens remaining
{/* Subscription Info */} {/*

Subscription Details

{tierInfo.monthlyTokens}
Monthly Tokens
{userData.generatedImages.length}
Images Generated
{userData.generatedImages.length > 0 ? Math.round(userData.generatedImages.length / 30 * 30) : 0}
Avg per Month
*/} {/* Recent Generations */}

My Generations

{userData.generatedImages.length === 0 ? (

No generations yet

Start creating amazing action figures!

navigate('/create')} > + Create your own now
) : (
{userData.generatedImages .sort((a, b) => { const dateA = a.createdAt?.toDate?.() || new Date(a.createdAt); const dateB = b.createdAt?.toDate?.() || new Date(b.createdAt); return dateB.getTime() - dateA.getTime(); // Sort latest first }) .map((image: any, index: number) => { const imageId = image.id || `user-${user.uid}-${index}`; const createdAt = image.createdAt?.toDate?.() || new Date(image.createdAt); console.log(`🔍 Profile image ${index}:`, { hasId: !!image.id, imageId, createdAt: createdAt.toISOString(), imageUrl: image.imageUrl?.substring(0, 50) + '...' }); return ( ); })}
)}
); }; export default Profile;