"use client"; import React, { useState, useEffect } from "react"; import Link from "next/link"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Mail, Send, Inbox, FileText, RefreshCw, TrendingUp, Users, Calendar, ArrowRight, Trash2, Edit } from "lucide-react"; import { getMailAccounts, getMailTemplates, getMailStatistics, getTodayReceivedCount } from "@/lib/api/mail"; import MailNotifications from "@/components/mail/MailNotifications"; interface DashboardStats { totalAccounts: number; totalTemplates: number; sentToday: number; receivedToday: number; sentThisMonth: number; successRate: number; } export default function MailDashboardPage() { const [stats, setStats] = useState({ totalAccounts: 0, totalTemplates: 0, sentToday: 0, receivedToday: 0, sentThisMonth: 0, successRate: 0, }); const [loading, setLoading] = useState(false); const loadStats = async () => { setLoading(true); try { const accounts = await getMailAccounts(); const templates = await getMailTemplates(); // 메일 통계 조회 (실패 시 기본값 사용) let mailStats = { todayCount: 0, thisMonthCount: 0, successRate: 0, }; try { const stats = await getMailStatistics(); if (stats && typeof stats === 'object') { mailStats = { todayCount: stats.todayCount || 0, thisMonthCount: stats.thisMonthCount || 0, successRate: stats.successRate || 0, }; } } catch (error) { // console.error('메일 통계 조회 실패:', error); // 기본값 사용 } // 오늘 수신 메일 수 조회 (IMAP 실시간 조회) let receivedTodayCount = 0; try { receivedTodayCount = await getTodayReceivedCount(); } catch (error) { // console.error('수신 메일 수 조회 실패:', error); // 실패 시 0으로 표시 } setStats({ totalAccounts: accounts.length, totalTemplates: templates.length, sentToday: mailStats.todayCount, receivedToday: receivedTodayCount, sentThisMonth: mailStats.thisMonthCount, successRate: mailStats.successRate, }); } catch (error) { // console.error('통계 로드 실패:', error); } finally { setLoading(false); } }; useEffect(() => { loadStats(); }, []); const statCards = [ { title: "등록된 계정", value: stats.totalAccounts, icon: Users, color: "blue", bgColor: "bg-blue-100", iconColor: "text-blue-600", href: "/admin/mail/accounts", }, { title: "템플릿 수", value: stats.totalTemplates, icon: FileText, color: "green", bgColor: "bg-green-100", iconColor: "text-green-600", href: "/admin/mail/templates", }, { title: "오늘 발송", value: stats.sentToday, icon: Send, color: "orange", bgColor: "bg-orange-100", iconColor: "text-orange-600", href: "/admin/mail/sent", }, { title: "오늘 수신", value: stats.receivedToday, icon: Inbox, color: "purple", bgColor: "bg-purple-100", iconColor: "text-purple-600", href: "/admin/mail/receive", }, ]; const quickLinks = [ { title: "계정 관리", description: "메일 계정 설정", href: "/admin/mail/accounts", icon: Users, color: "blue", }, { title: "템플릿 관리", description: "템플릿 편집", href: "/admin/mail/templates", icon: FileText, color: "green", }, { title: "메일 발송", description: "메일 보내기", href: "/admin/mail/send", icon: Send, color: "orange", }, { title: "대량 발송", description: "CSV로 대량 발송", href: "/admin/mail/bulk-send", icon: Users, color: "teal", }, { title: "보낸메일함", description: "발송 이력 확인", href: "/admin/mail/sent", icon: Mail, color: "indigo", }, { title: "수신함", description: "받은 메일 확인", href: "/admin/mail/receive", icon: Inbox, color: "purple", }, { title: "임시 저장", description: "작성 중인 메일", href: "/admin/mail/drafts", icon: Edit, color: "amber", }, { title: "휴지통", description: "삭제된 메일", href: "/admin/mail/trash", icon: Trash2, color: "red", }, ]; return (
{/* 페이지 제목 */}

메일 관리 대시보드

메일 시스템의 전체 현황을 한눈에 확인하세요

{/* 통계 카드 */}
{statCards.map((stat, index) => (

{stat.title}

{stat.value}

{/* 진행 바 */}
))}
{/* 이번 달 통계 */}
이번 달 발송 통계
총 발송 건수 {stats.sentThisMonth} 건
성공률 {stats.successRate}%
{/* 전월 대비 통계는 현재 불필요하여 주석처리
전월 대비
+12%
*/}
시스템 상태
메일 서버
정상 작동
활성 계정
{stats.totalAccounts} 개
사용 가능 템플릿
{stats.totalTemplates} 개
{/* 빠른 액세스 */} 빠른 액세스
{quickLinks.map((link, index) => (

{link.title}

{link.description}

))}
); }