'use client';
import { useEffect, useState } from 'react';
interface Stats {
totalMembers: number;
totalOrders: number;
totalRevenue: number;
pendingContacts: number;
activeSubscribers: number;
monthlyChart: Array<{ month: string; revenue: number }>;
}
const MONTHLY_GOAL = 1_000_000; // 월 100만원 목표
function StatCard({ label, value, icon, color }: { label: string; value: string; icon: React.ReactNode; color: string }) {
return (
);
}
function MonthlyGoalCard({ currentRevenue }: { currentRevenue: number }) {
const progress = Math.min((currentRevenue / MONTHLY_GOAL) * 100, 100);
const remaining = Math.max(MONTHLY_GOAL - currentRevenue, 0);
const isAchieved = currentRevenue >= MONTHLY_GOAL;
const progressColor = progress >= 100 ? 'from-emerald-400 to-green-500' : progress >= 70 ? 'from-yellow-400 to-orange-400' : 'from-blue-500 to-violet-500';
return (
{/* 프로그레스 바 */}
₩{currentRevenue.toLocaleString()}
/ ₩1,000,000
{isAchieved ? (
🎉 목표 달성!
) : (
₩{remaining.toLocaleString()} 남음
)}
달성률 {progress.toFixed(1)}%
목표 ₩1,000,000
);
}
export default function AdminDashboard() {
const [stats, setStats] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetch('/api/admin/stats')
.then((r) => r.json())
.then((d) => setStats(d))
.catch(console.error)
.finally(() => setLoading(false));
}, []);
const maxRevenue = stats ? Math.max(...stats.monthlyChart.map((m) => m.revenue), 1) : 1;
return (
{/* 헤더 */}
{loading ? (
) : (
<>
{/* 월 목표 추적 */}
{/* 통계 카드 */}
{/* 월별 수익 차트 */}
월별 수익 현황 (최근 6개월)
{stats?.monthlyChart.map((item) => {
const height = maxRevenue > 0 ? Math.max((item.revenue / maxRevenue) * 100, item.revenue > 0 ? 4 : 0) : 0;
const monthLabel = item.month.slice(5); // MM
return (
{item.revenue > 0 ? `₩${(item.revenue / 1000).toFixed(0)}K` : ''}
0 ? '4px' : '0' }}
/>
{monthLabel}월
);
})}
{(stats?.totalRevenue ?? 0) === 0 && (
결제 데이터가 없습니다
)}
>
)}
);
}