'use client'; import { useEffect, useState } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faCopy, faArrowUpRightFromSquare, faWallet, faCalendarDay, faCalendar, faClock } from '@fortawesome/free-solid-svg-icons'; import { fetchApi } from '@/lib/utils/client'; import type { DashboardResponse, DashboardWidgetUrls } from '@/types/response/studio/dashboard'; import './style.scss'; const WIDGET_LABELS: { key: keyof Omit; label: string; description: string }[] = [ { key: 'alert', label: '후원 알림', description: 'OBS에 후원 알림 표시' }, { key: 'goal', label: '후원 목표', description: '목표 금액 진행률 표시' }, { key: 'rank', label: '후원 순위', description: '후원자 순위 표시' }, { key: 'crew', label: '크루 리더보드', description: '크루 순위 표시' }, { key: 'remote', label: '리모콘', description: '후원 알림 제어' }, ]; export default function DashboardPage() { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [copiedKey, setCopiedKey] = useState(null); useEffect(() => { loadDashboard(); }, []); const loadDashboard = async () => { try { const res = await fetchApi('/api/studio/dashboard', { silent: true }); if (res.data) { setData(res.data); } } catch {} finally { setLoading(false); } }; const getWidgetFullUrl = (path: string) => { if (typeof window === 'undefined') { return path; } return `${window.location.origin}${path}`; }; const handleCopy = async (key: string, path: string) => { try { await navigator.clipboard.writeText(getWidgetFullUrl(path)); setCopiedKey(key); setTimeout(() => setCopiedKey(null), 2000); } catch {} }; const handleOpen = (path: string) => { window.open(getWidgetFullUrl(path), '_blank'); }; if (loading) { return (

대시보드

준비 중...

); } const financial = data?.financial; const widgets = data?.widgets; const recentDonations = data?.recentDonations ?? []; return (

대시보드

{/* 재무 요약 카드 */}
출금 가능 잔액 {(financial?.availableBalance ?? 0).toLocaleString()}원
오늘 후원 {(financial?.todayDonations ?? 0).toLocaleString()}원
이번 달 후원 {(financial?.monthDonations ?? 0).toLocaleString()}원
출금 대기 {(financial?.pendingWithdrawal ?? 0).toLocaleString()}원
{/* 위젯 URL */} {widgets && (

위젯 URL

OBS 브라우저 소스에 아래 URL을 등록하세요.

{WIDGET_LABELS.map(({ key, label, description }) => { const path = widgets[key]; const isCopied = copiedKey === key; return (
{label} {description}
{getWidgetFullUrl(path)}
); })}
)} {/* 최근 후원 */}

최근 후원

{recentDonations.length === 0 ? (
아직 후원 내역이 없습니다.
) : (
{recentDonations.map(d => (
{d.sendName} {d.amount.toLocaleString()}원
{d.message && (
{d.message}
)}
{new Date(d.createdAt).toLocaleString('ko-KR')}
))}
)}
); }