import React, { useState, useEffect } from 'react'; import { Card } from '../ui/card'; import { Button } from '../ui/button'; import { Plus, TrendingUp, DollarSign, Package, Users, Eye, MoreHorizontal, Zap, Loader2, } from 'lucide-react'; import { FlashSaleModal } from './modals/FlashSaleModal'; import { useToast } from '../../context/ToastContext'; import { Product } from '../../types'; import { marketplaceService } from '../../services/marketplaceService'; import { commerceService } from '../../services/commerceService'; import { logger } from '@/utils/logger'; interface SellerDashboardProps { onCreateProduct: () => void; } export const SellerDashboardView: React.FC = ({ onCreateProduct, }) => { const { addToast } = useToast(); const [showFlashSale, setShowFlashSale] = useState(false); const [products, setProducts] = useState([]); const [sales, setSales] = useState([]); const [stats, setStats] = useState({}); const [loading, setLoading] = useState(true); useEffect(() => { const fetchData = async () => { setLoading(true); try { const [prods, salesData, statsData] = await Promise.all([ marketplaceService.listProducts({ seller_id: 'me' }), commerceService.getSales(), commerceService.getSellerStats(), ]); setProducts(prods.products || []); setSales(salesData); setStats(statsData); } catch (e) { logger.error('Error loading seller dashboard data', { error: e instanceof Error ? e.message : String(e), stack: e instanceof Error ? e.stack : undefined, }); } finally { setLoading(false); } }; fetchData(); }, []); if (loading) return (
); return (
{/* Header */}

SELLER DASHBOARD

Manage your products, sales, and analytics.

{/* Stats Grid */}
Total Revenue
${stats.revenue?.toLocaleString()}
+12.5% this month
Total Sales
{stats.sales}
+5.0% this month
Page Views
{stats.views > 1000 ? `${(stats.views / 1000).toFixed(1)}K` : stats.views}
-2.4% this month
Conversion Rate
{stats.conversion}%
+0.8% this month
{/* Top Products */}

Top Products

{products.map((product, i) => (
{i + 1}
{product.title}
{product.reviewCount} reviews • {product.rating} stars
${product.price}
{Math.floor(Math.random() * 100)} sales
))}
{/* Recent Sales */}

Recent Sales

{sales.map((sale) => (
{sale.product}
{sale.buyer} ${sale.amount}
{sale.date}
))}
{showFlashSale && ( setShowFlashSale(false)} onStart={(config) => addToast( `Flash Sale started for ${config.productIds.length} products!`, 'success', ) } /> )}
); };