feat(app): add stats and admin tools
This commit is contained in:
1 parent
efa133a1a2
commit
c8cca3fc43
35 files changed
+6875
No files matched your search
@@ -0,0 +1,406 @@
|
||||
import { Link, useLocation, useSearchParams } from 'react-router';
|
||||
import {
|
||||
useCommunity,
|
||||
useCommunityInternalStatsMatches,
|
||||
useCommunityLeaderboard,
|
||||
useDdragonManifest,
|
||||
useTeamInsights,
|
||||
} from '../api/hooks';
|
||||
import type {
|
||||
ApiInternalMatchCard,
|
||||
ApiLeaderHighlight,
|
||||
ApiLeaderboardRow,
|
||||
TeamSide,
|
||||
} from '../api/types';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../config';
|
||||
import { championDisplayName, championIconUrl, profileIconUrl } from '../lib/ddragon';
|
||||
import { sideShortLabel, teamIndexColorClasses, teamIndexLabel } from '../lib/league';
|
||||
|
||||
function formatDateTime(value: string) {
|
||||
return new Intl.DateTimeFormat('ko-KR', {
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(new Date(value));
|
||||
}
|
||||
|
||||
function formatDuration(seconds: number) {
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const rest = seconds % 60;
|
||||
return `${minutes}:${String(rest).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function sideLabel(side: TeamSide) {
|
||||
return sideShortLabel(side);
|
||||
}
|
||||
|
||||
function sideText(side: TeamSide) {
|
||||
return side === 'blue' ? 'text-blue-400' : 'text-red-400';
|
||||
}
|
||||
|
||||
function ratioClass(value: number) {
|
||||
if (value >= 55) return 'text-blue-400';
|
||||
if (value >= 50) return 'text-amber-400';
|
||||
return 'text-base-content/45';
|
||||
}
|
||||
|
||||
function ChampionChip({
|
||||
championId,
|
||||
manifest,
|
||||
}: {
|
||||
championId: number;
|
||||
manifest: ReturnType<typeof useDdragonManifest>['data'];
|
||||
}) {
|
||||
const icon = championIconUrl(manifest, championId);
|
||||
const name = championDisplayName(manifest, championId) ?? String(championId);
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<span className="w-5 h-5 bg-base-content/10 overflow-hidden">
|
||||
{icon ? <img src={icon} alt="" className="w-full h-full object-cover" /> : null}
|
||||
</span>
|
||||
<span>{name}</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function MatchCard({
|
||||
match,
|
||||
manifest,
|
||||
}: {
|
||||
match: ApiInternalMatchCard;
|
||||
manifest: ReturnType<typeof useDdragonManifest>['data'];
|
||||
}) {
|
||||
const primarySeries = match.seriesResults[0];
|
||||
const teamName = (teamIndex: number) =>
|
||||
teamIndexLabel(
|
||||
teamIndex,
|
||||
match.teams.find((team) => team.teamIndex === teamIndex)?.name,
|
||||
);
|
||||
|
||||
return (
|
||||
<Link
|
||||
to={`/communities/${DEFAULT_COMMUNITY_ID}/internal-stats/match/${match.matchId}`}
|
||||
className="block group"
|
||||
>
|
||||
<article className="border border-base-content/10 bg-base-100 hover:border-primary/25 transition-colors">
|
||||
<div className="p-4 grid lg:grid-cols-[1fr_auto_1fr] gap-4 items-center">
|
||||
<div className="min-w-0">
|
||||
<div className="text-[11px] text-base-content/35">
|
||||
{formatDateTime(match.scheduledAt)}
|
||||
</div>
|
||||
<h3 className="mt-1 text-base font-black text-base-content truncate group-hover:text-primary">
|
||||
{match.title}
|
||||
</h3>
|
||||
<div className="mt-2 flex flex-wrap gap-1.5">
|
||||
{match.games.map((game) => (
|
||||
<span
|
||||
key={game.gameNumber}
|
||||
className="inline-flex items-center gap-1 border border-base-content/10 px-2 py-1 text-[10px] text-base-content/45"
|
||||
>
|
||||
{game.gameNumber}경기
|
||||
{game.winnerSide && game.winnerTeamIndex ? (
|
||||
<span className={sideText(game.winnerSide)}>
|
||||
{teamName(game.winnerTeamIndex)} 승 ({sideLabel(game.winnerSide)})
|
||||
</span>
|
||||
) : (
|
||||
'대기'
|
||||
)}
|
||||
<span>{formatDuration(game.gameDuration)}</span>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="text-center px-8">
|
||||
{primarySeries && (
|
||||
<div className="flex items-center justify-center gap-5">
|
||||
<div className={primarySeries.winnerTeamIndex === primarySeries.teamAIndex ? teamIndexColorClasses(primarySeries.teamAIndex).text : 'text-base-content/30'}>
|
||||
<div className="text-4xl font-black tabular-nums">{primarySeries.teamAWins}</div>
|
||||
<div className="text-[10px] font-bold uppercase tracking-wider">
|
||||
{teamName(primarySeries.teamAIndex)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-base-content/15 text-xs font-black">VS</div>
|
||||
<div className={primarySeries.winnerTeamIndex === primarySeries.teamBIndex ? teamIndexColorClasses(primarySeries.teamBIndex).text : 'text-base-content/30'}>
|
||||
<div className="text-4xl font-black tabular-nums">{primarySeries.teamBWins}</div>
|
||||
<div className="text-[10px] font-bold uppercase tracking-wider">
|
||||
{teamName(primarySeries.teamBIndex)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="grid sm:grid-cols-2 gap-2">
|
||||
{match.teams.map((team) => (
|
||||
<div
|
||||
key={team.teamIndex}
|
||||
className={`border ${teamIndexColorClasses(team.teamIndex).border} p-2`}
|
||||
>
|
||||
<div className={`text-[10px] font-black uppercase tracking-wider ${teamIndexColorClasses(team.teamIndex).text}`}>
|
||||
{team.name}
|
||||
</div>
|
||||
<div className="mt-2 space-y-1">
|
||||
{team.members.slice(0, 5).map((member) => (
|
||||
<div key={member.userId} className="flex items-center gap-1.5 min-w-0">
|
||||
<span className="w-5 h-5 bg-base-content/10 overflow-hidden shrink-0">
|
||||
<img
|
||||
src={profileIconUrl(manifest, member.profileIconId)}
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
</span>
|
||||
<span className="text-[11px] truncate text-base-content/65">
|
||||
{member.summonerName}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
function HighlightCard({
|
||||
title,
|
||||
highlight,
|
||||
suffix = '',
|
||||
}: {
|
||||
title: string;
|
||||
highlight: ApiLeaderHighlight | null | undefined;
|
||||
suffix?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100 p-4">
|
||||
<div className="text-[10px] font-black uppercase tracking-wider text-base-content/30">
|
||||
{title}
|
||||
</div>
|
||||
<div className="mt-2 text-xl font-black text-base-content tabular-nums">
|
||||
{highlight ? `${highlight.metric}${suffix}` : '-'}
|
||||
</div>
|
||||
<div className="mt-1 text-[12px] text-base-content/45">
|
||||
{highlight?.summonerName ?? '기록 없음'}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LeaderboardTable({
|
||||
rows,
|
||||
manifest,
|
||||
}: {
|
||||
rows: ApiLeaderboardRow[];
|
||||
manifest: ReturnType<typeof useDdragonManifest>['data'];
|
||||
}) {
|
||||
const location = useLocation();
|
||||
const historyBackTo = `${location.pathname}${location.search}${location.hash}`;
|
||||
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100 overflow-hidden">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left min-w-[920px]">
|
||||
<thead>
|
||||
<tr className="border-b border-base-content/10 bg-base-200/50 text-[11px] uppercase tracking-wider text-base-content/35">
|
||||
<th className="px-3 py-2.5">#</th>
|
||||
<th className="px-3 py-2.5">소환사</th>
|
||||
<th className="px-3 py-2.5 text-center">승률</th>
|
||||
<th className="px-3 py-2.5 text-center">게임</th>
|
||||
<th className="px-3 py-2.5 text-center">KDA</th>
|
||||
<th className="px-3 py-2.5 text-center">GPM</th>
|
||||
<th className="px-3 py-2.5 text-center">킬관여</th>
|
||||
<th className="px-3 py-2.5 text-center">분당 CS</th>
|
||||
<th className="px-3 py-2.5">주 챔피언</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((row, index) => (
|
||||
<tr key={row.userId} className="border-b border-base-content/5 last:border-b-0">
|
||||
<td className="px-3 py-2.5 text-[11px] text-base-content/30">
|
||||
{index + 1}
|
||||
</td>
|
||||
<td className="px-3 py-2.5">
|
||||
<Link
|
||||
to={`/users/${row.userId}/history?queueGroup=internal`}
|
||||
state={{ backTo: historyBackTo }}
|
||||
className="flex items-center gap-2 group"
|
||||
>
|
||||
<span className="w-7 h-7 bg-base-content/10 overflow-hidden">
|
||||
<img
|
||||
src={profileIconUrl(manifest, row.profileIconId)}
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
</span>
|
||||
<span className="font-bold text-[13px] group-hover:text-primary">
|
||||
{row.summonerName}
|
||||
</span>
|
||||
</Link>
|
||||
</td>
|
||||
<td className={`px-3 py-2.5 text-center text-[13px] font-black ${ratioClass(row.winRate)}`}>
|
||||
{row.winRate}%
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
|
||||
{row.games}
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-center text-[12px] font-bold tabular-nums">
|
||||
{row.kda}
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
|
||||
{row.avgGoldPerMin}
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
|
||||
{row.avgKillParticipation}%
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
|
||||
{row.avgCsPerMin}
|
||||
</td>
|
||||
<td className="px-3 py-2.5">
|
||||
<div className="flex flex-wrap gap-2 text-[11px] text-base-content/55">
|
||||
{row.topChampions.map((champion) => (
|
||||
<ChampionChip
|
||||
key={champion.championId}
|
||||
championId={champion.championId}
|
||||
manifest={manifest}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{rows.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={9} className="py-10 text-center text-sm text-base-content/35">
|
||||
아직 집계할 내전 기록이 없습니다.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function CommunityInternalStatsPage() {
|
||||
const [searchParams] = useSearchParams();
|
||||
const championIdParam = Number(searchParams.get('championId'));
|
||||
const championId =
|
||||
Number.isFinite(championIdParam) && championIdParam > 0
|
||||
? championIdParam
|
||||
: undefined;
|
||||
const filters = {
|
||||
seasonId: searchParams.get('seasonId') ?? undefined,
|
||||
championId,
|
||||
limit: 12,
|
||||
};
|
||||
const communityQuery = useCommunity(DEFAULT_COMMUNITY_ID);
|
||||
const matchesQuery = useCommunityInternalStatsMatches(filters);
|
||||
const leaderboardQuery = useCommunityLeaderboard(filters);
|
||||
const insightsQuery = useTeamInsights(filters);
|
||||
const { data: ddragon } = useDdragonManifest();
|
||||
const matches = matchesQuery.data?.pages.flatMap((page) => page.matches) ?? [];
|
||||
const season =
|
||||
leaderboardQuery.data?.season ?? matchesQuery.data?.pages[0]?.season ?? null;
|
||||
|
||||
if (!DEFAULT_COMMUNITY_ID) {
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 py-20 text-center text-sm text-amber-600">
|
||||
`VITE_DEFAULT_COMMUNITY_ID` 설정이 필요합니다.
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 sm:px-6 py-6">
|
||||
<Link to="/" className="text-xs text-base-content/40 hover:text-base-content">
|
||||
← 홈으로
|
||||
</Link>
|
||||
|
||||
<section className="mt-5 mb-6 border border-base-content/10 bg-base-100 p-5">
|
||||
<div className="flex flex-col sm:flex-row sm:items-end sm:justify-between gap-4">
|
||||
<div>
|
||||
<p className="text-[11px] font-black uppercase tracking-[0.24em] text-primary">
|
||||
Community Records
|
||||
</p>
|
||||
<h1 className="mt-2 text-3xl font-black text-base-content">
|
||||
{communityQuery.data?.name ?? '커뮤니티'} 내전 전적
|
||||
</h1>
|
||||
<p className="mt-2 text-sm text-base-content/45">
|
||||
토너먼트 코드로 수집된 결과를 기준으로 매치, 선수 순위, 팀 인사이트를 보여줍니다.
|
||||
</p>
|
||||
</div>
|
||||
<div className="border border-base-content/10 px-4 py-3 text-sm text-base-content/55">
|
||||
<div className="text-[10px] uppercase tracking-wider text-base-content/30">
|
||||
시즌
|
||||
</div>
|
||||
<div className="mt-1 font-bold">{season?.label ?? '현재 시즌'}</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="grid sm:grid-cols-2 lg:grid-cols-5 gap-3 mb-6">
|
||||
<HighlightCard title="최고 KDA" highlight={insightsQuery.data?.topKda} />
|
||||
<HighlightCard title="누적 킬 1위" highlight={insightsQuery.data?.mostKills} />
|
||||
<HighlightCard title="단일 경기 GPM" highlight={insightsQuery.data?.topTeamGpm} />
|
||||
<HighlightCard title="킬 관여율" highlight={insightsQuery.data?.topKillParticipation} suffix="%" />
|
||||
<HighlightCard title="분당 CS" highlight={insightsQuery.data?.bestFarm} />
|
||||
</section>
|
||||
|
||||
<section className="mb-8">
|
||||
<div className="flex items-center justify-between gap-3 mb-3">
|
||||
<h2 className="text-sm font-black text-base-content">최근 내전</h2>
|
||||
<div className="text-[11px] text-base-content/35">
|
||||
블루 승률 {insightsQuery.data?.sideWinRate.blue ?? 0}% · 레드 승률{' '}
|
||||
{insightsQuery.data?.sideWinRate.red ?? 0}%
|
||||
</div>
|
||||
</div>
|
||||
{matchesQuery.isLoading ? (
|
||||
<div className="border border-base-content/10 bg-base-100 px-4 py-12 text-center text-sm text-base-content/35">
|
||||
내전 기록을 불러오는 중...
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{matches.map((match) => (
|
||||
<MatchCard key={match.matchId} match={match} manifest={ddragon} />
|
||||
))}
|
||||
{matches.length === 0 && (
|
||||
<div className="border border-base-content/10 bg-base-100 px-4 py-12 text-center text-sm text-base-content/35">
|
||||
아직 수집된 내전 결과가 없습니다.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{matchesQuery.hasNextPage && (
|
||||
<button
|
||||
type="button"
|
||||
className="mt-3 w-full border border-base-content/15 bg-base-100 py-3 text-sm font-bold text-base-content/60 hover:text-primary hover:border-primary/30 disabled:opacity-40"
|
||||
disabled={matchesQuery.isFetchingNextPage}
|
||||
onClick={() => matchesQuery.fetchNextPage()}
|
||||
>
|
||||
{matchesQuery.isFetchingNextPage ? '불러오는 중...' : '+ 더 보기'}
|
||||
</button>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<div className="flex items-center justify-between gap-3 mb-3">
|
||||
<h2 className="text-sm font-black text-base-content">선수 순위</h2>
|
||||
<div className="text-[11px] text-base-content/35">
|
||||
포지션은 Riot Match의 라인 정보를 기준으로 합니다.
|
||||
</div>
|
||||
</div>
|
||||
<LeaderboardTable
|
||||
rows={leaderboardQuery.data?.rows ?? []}
|
||||
manifest={ddragon}
|
||||
/>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
import { Link, useLocation, useParams } from 'react-router';
|
||||
import { useDdragonManifest, useInternalMatchDetail } from '../api/hooks';
|
||||
import type { ApiInternalMatchDetailResponse, TeamSide } from '../api/types';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../config';
|
||||
import { championDisplayName, championIconUrl, itemIconUrl } from '../lib/ddragon';
|
||||
import { sideShortLabel, teamIndexColorClasses, teamIndexLabel } from '../lib/league';
|
||||
import { LANE_LABELS } from '../lib/riot-history';
|
||||
|
||||
function formatDateTime(value: string | number) {
|
||||
return new Intl.DateTimeFormat('ko-KR', {
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(new Date(value));
|
||||
}
|
||||
|
||||
function formatDuration(seconds: number) {
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const rest = seconds % 60;
|
||||
return `${minutes}:${String(rest).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function sideLabel(side: TeamSide) {
|
||||
return sideShortLabel(side);
|
||||
}
|
||||
|
||||
function sideClass(side: TeamSide) {
|
||||
return side === 'blue' ? 'text-blue-400 border-blue-500/20' : 'text-red-400 border-red-500/20';
|
||||
}
|
||||
|
||||
function ChampionCell({
|
||||
championId,
|
||||
manifest,
|
||||
}: {
|
||||
championId: number;
|
||||
manifest: ReturnType<typeof useDdragonManifest>['data'];
|
||||
}) {
|
||||
const icon = championIconUrl(manifest, championId);
|
||||
const name = championDisplayName(manifest, championId) ?? String(championId);
|
||||
return (
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
<span className="w-8 h-8 bg-base-content/10 overflow-hidden shrink-0">
|
||||
{icon ? <img src={icon} alt="" className="w-full h-full object-cover" /> : null}
|
||||
</span>
|
||||
<span className="font-bold text-[13px] truncate">{name}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ItemStrip({
|
||||
items,
|
||||
trinket,
|
||||
manifest,
|
||||
}: {
|
||||
items: number[];
|
||||
trinket: number;
|
||||
manifest: ReturnType<typeof useDdragonManifest>['data'];
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{[...items, trinket].map((itemId, index) => {
|
||||
const icon = itemIconUrl(manifest, itemId);
|
||||
return (
|
||||
<span
|
||||
key={`${itemId}-${index}`}
|
||||
className="w-5 h-5 bg-base-content/10 border border-base-content/5 overflow-hidden"
|
||||
>
|
||||
{icon ? <img src={icon} alt="" className="w-full h-full object-cover" /> : null}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function GamePanel({
|
||||
game,
|
||||
manifest,
|
||||
}: {
|
||||
game: ApiInternalMatchDetailResponse['games'][number];
|
||||
manifest: ReturnType<typeof useDdragonManifest>['data'];
|
||||
}) {
|
||||
const location = useLocation();
|
||||
const historyBackTo = `${location.pathname}${location.search}${location.hash}`;
|
||||
|
||||
return (
|
||||
<section className="border border-base-content/10 bg-base-100 overflow-hidden">
|
||||
<div className="px-4 py-3 border-b border-base-content/10 bg-base-200/40 flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h2 className="text-sm font-black text-base-content">
|
||||
{game.gameNumber}경기
|
||||
</h2>
|
||||
<p className="mt-1 text-[11px] text-base-content/35">
|
||||
{formatDateTime(game.gameCreation)} · {formatDuration(game.gameDuration)} ·{' '}
|
||||
<span className="font-mono">{game.riotMatchId}</span>
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
{game.teams.map((team) => (
|
||||
<span
|
||||
key={team.side}
|
||||
className={`border px-2 py-1 text-[11px] font-black ${sideClass(team.side)} ${
|
||||
team.win ? 'bg-base-content/5' : 'opacity-40'
|
||||
}`}
|
||||
>
|
||||
{teamIndexLabel(team.teamIndex)} ({sideLabel(team.side)}){' '}
|
||||
{team.win ? '승' : '패'}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{game.teams.map((team) => (
|
||||
<div key={team.side} className="border-b border-base-content/8 last:border-b-0">
|
||||
<div className={`px-4 py-2 text-[11px] font-black uppercase tracking-wider ${sideClass(team.side)}`}>
|
||||
{teamIndexLabel(team.teamIndex)} ({sideLabel(team.side)}) · 바론 {team.objectives.baron} · 드래곤{' '}
|
||||
{team.objectives.dragon} · 타워 {team.objectives.tower}
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left min-w-[980px]">
|
||||
<thead>
|
||||
<tr className="bg-base-content/[0.02] text-[11px] text-base-content/35 uppercase tracking-wider">
|
||||
<th className="px-3 py-2">소환사</th>
|
||||
<th className="px-3 py-2">챔피언</th>
|
||||
<th className="px-3 py-2 text-center">포지션</th>
|
||||
<th className="px-3 py-2 text-center">K/D/A</th>
|
||||
<th className="px-3 py-2 text-center">CS</th>
|
||||
<th className="px-3 py-2 text-center">GPM</th>
|
||||
<th className="px-3 py-2 text-center">킬관여</th>
|
||||
<th className="px-3 py-2 text-center">피해비중</th>
|
||||
<th className="px-3 py-2">아이템</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{team.participants.map((participant) => (
|
||||
<tr
|
||||
key={`${team.side}-${participant.userId}-${participant.championId}`}
|
||||
className="border-t border-base-content/5"
|
||||
>
|
||||
<td className="px-3 py-2">
|
||||
{participant.userId ? (
|
||||
<Link
|
||||
to={`/users/${participant.userId}/history?queueGroup=internal`}
|
||||
state={{ backTo: historyBackTo }}
|
||||
className="font-bold text-[13px] hover:text-primary"
|
||||
>
|
||||
{participant.summonerName}
|
||||
</Link>
|
||||
) : (
|
||||
<span className="font-bold text-[13px]">
|
||||
{participant.summonerName}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
<ChampionCell championId={participant.championId} manifest={manifest} />
|
||||
</td>
|
||||
<td className="px-3 py-2 text-center text-[12px]">
|
||||
{LANE_LABELS[participant.teamPosition] ?? participant.teamPosition ?? '-'}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-center text-[13px] font-black tabular-nums">
|
||||
{participant.kills}
|
||||
<span className="text-base-content/25"> / </span>
|
||||
<span className="text-red-400">{participant.deaths}</span>
|
||||
<span className="text-base-content/25"> / </span>
|
||||
{participant.assists}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-center text-[12px] tabular-nums">
|
||||
{participant.cs} ({participant.csPerMin}/m)
|
||||
</td>
|
||||
<td className="px-3 py-2 text-center text-[12px] tabular-nums">
|
||||
{participant.gpm}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-center text-[12px] tabular-nums">
|
||||
{participant.killParticipation}%
|
||||
</td>
|
||||
<td className="px-3 py-2 text-center text-[12px] tabular-nums">
|
||||
{participant.damageShare}%
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
<ItemStrip
|
||||
items={participant.items}
|
||||
trinket={participant.trinket}
|
||||
manifest={manifest}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default function InternalMatchDetailPage() {
|
||||
const { cid, matchId } = useParams();
|
||||
const communityId = cid ?? DEFAULT_COMMUNITY_ID;
|
||||
const detailQuery = useInternalMatchDetail(matchId, communityId);
|
||||
const { data: ddragon } = useDdragonManifest();
|
||||
const detail = detailQuery.data;
|
||||
|
||||
if (detailQuery.isLoading) {
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 py-20 text-center text-sm text-base-content/40">
|
||||
내전 상세 기록을 불러오는 중...
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (detailQuery.error || !detail) {
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 py-20 text-center">
|
||||
<h1 className="text-lg font-bold">내전 기록을 찾을 수 없습니다</h1>
|
||||
<Link
|
||||
to={`/communities/${communityId}/internal-stats`}
|
||||
className="btn btn-ghost btn-sm mt-4"
|
||||
>
|
||||
내전 전적으로 돌아가기
|
||||
</Link>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
const primarySeries = detail.match.seriesResults[0];
|
||||
const teamName = (teamIndex: number) =>
|
||||
teamIndexLabel(
|
||||
teamIndex,
|
||||
detail.match.teams.find((team) => team.teamIndex === teamIndex)?.name,
|
||||
);
|
||||
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 sm:px-6 py-6">
|
||||
<Link
|
||||
to={`/communities/${communityId}/internal-stats`}
|
||||
className="text-xs text-base-content/40 hover:text-base-content"
|
||||
>
|
||||
← 내전 전적
|
||||
</Link>
|
||||
|
||||
<section className="mt-5 mb-6 border border-base-content/10 bg-base-100 p-5">
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-black text-base-content">
|
||||
{detail.match.title}
|
||||
</h1>
|
||||
<p className="mt-2 text-sm text-base-content/45">
|
||||
{formatDateTime(detail.match.scheduledAt)} · {detail.match.gameCount}전제
|
||||
</p>
|
||||
</div>
|
||||
{primarySeries && (
|
||||
<div className="flex items-center gap-6">
|
||||
<div className={primarySeries.winnerTeamIndex === primarySeries.teamAIndex ? teamIndexColorClasses(primarySeries.teamAIndex).text : 'text-base-content/30'}>
|
||||
<div className="text-4xl font-black tabular-nums">{primarySeries.teamAWins}</div>
|
||||
<div className="text-[10px] font-bold uppercase tracking-wider">
|
||||
{teamName(primarySeries.teamAIndex)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-base-content/15 text-xs font-black">VS</div>
|
||||
<div className={primarySeries.winnerTeamIndex === primarySeries.teamBIndex ? teamIndexColorClasses(primarySeries.teamBIndex).text : 'text-base-content/30'}>
|
||||
<div className="text-4xl font-black tabular-nums">{primarySeries.teamBWins}</div>
|
||||
<div className="text-[10px] font-bold uppercase tracking-wider">
|
||||
{teamName(primarySeries.teamBIndex)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div className="space-y-4">
|
||||
{detail.games.map((game) => (
|
||||
<GamePanel key={game.riotMatchId} game={game} manifest={ddragon} />
|
||||
))}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { Link, useParams } from 'react-router';
|
||||
import {
|
||||
useCancelLegacyImport,
|
||||
useLegacyImportJobs,
|
||||
useLegacyImportMembers,
|
||||
useMe,
|
||||
useStartLegacyImport,
|
||||
} from '../../api/hooks';
|
||||
import type { LegacyImportJob, StartLegacyImportRequest } from '../../api/types';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../../config';
|
||||
|
||||
const DEFAULT_START = '2024-05-01T00:00:00.000Z';
|
||||
|
||||
function toInputValue(value: string) {
|
||||
const date = new Date(value);
|
||||
const local = new Date(date.getTime() - date.getTimezoneOffset() * 60_000);
|
||||
return local.toISOString().slice(0, 16);
|
||||
}
|
||||
|
||||
function fromInputValue(value: string) {
|
||||
return value ? new Date(value).toISOString() : undefined;
|
||||
}
|
||||
|
||||
function formatDate(value: string | undefined) {
|
||||
if (!value) return '-';
|
||||
return new Intl.DateTimeFormat('ko-KR', {
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(new Date(value));
|
||||
}
|
||||
|
||||
function formatEta(seconds: number) {
|
||||
if (seconds < 60) return `${Math.max(1, Math.ceil(seconds))}초`;
|
||||
if (seconds < 3600) return `${Math.ceil(seconds / 60)}분`;
|
||||
return `${Math.ceil(seconds / 3600)}시간`;
|
||||
}
|
||||
|
||||
function progress(job: LegacyImportJob) {
|
||||
if (job.totalMembers === 0) return 100;
|
||||
return Math.round((job.processedMembers / job.totalMembers) * 100);
|
||||
}
|
||||
|
||||
function JobCard({
|
||||
job,
|
||||
onCancel,
|
||||
cancelling,
|
||||
}: {
|
||||
job: LegacyImportJob;
|
||||
onCancel: (jobId: string) => void;
|
||||
cancelling: boolean;
|
||||
}) {
|
||||
const running = job.state === 'pending' || job.state === 'running';
|
||||
const remaining = Math.max(0, job.totalMembers - job.processedMembers);
|
||||
const eta = remaining * (job.averageMemberSeconds ?? 60);
|
||||
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100 p-4">
|
||||
<div className="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3">
|
||||
<div>
|
||||
<div className="text-[11px] font-mono text-base-content/35">
|
||||
{job.jobId}
|
||||
</div>
|
||||
<div className="mt-1 flex flex-wrap items-center gap-2">
|
||||
<span className="text-sm font-black text-base-content">
|
||||
{job.state}
|
||||
</span>
|
||||
<span className="text-xs text-base-content/40">
|
||||
{job.processedMembers}/{job.totalMembers}명 · 발견{' '}
|
||||
{job.totalDiscoveredMatchIds} · import {job.totalImportedMatches} ·
|
||||
중복 {job.totalSkippedDuplicate} · 에러 {job.totalErrors}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{running && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-xs px-3 text-red-400"
|
||||
disabled={cancelling}
|
||||
onClick={() => onCancel(job.jobId)}
|
||||
>
|
||||
취소
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-3 h-2 bg-base-content/8">
|
||||
<div
|
||||
className="h-full bg-primary"
|
||||
style={{ width: `${progress(job)}%` }}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-2 flex flex-wrap justify-between gap-2 text-[11px] text-base-content/35">
|
||||
<span>
|
||||
{formatDate(job.windowStart)} ~ {formatDate(job.windowEnd)}
|
||||
</span>
|
||||
<span>{running ? `예상 남은 시간 ${formatEta(eta)}` : formatDate(job.completedAt)}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function LegacyImportPage() {
|
||||
const { cid } = useParams();
|
||||
const communityId = cid ?? DEFAULT_COMMUNITY_ID;
|
||||
const queryClient = useQueryClient();
|
||||
const meQuery = useMe();
|
||||
const [windowStart, setWindowStart] = useState(toInputValue(DEFAULT_START));
|
||||
const [windowEnd, setWindowEnd] = useState('');
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
const [overrides, setOverrides] = useState<
|
||||
Record<string, { startTime: string; endTime: string }>
|
||||
>({});
|
||||
const currentUser =
|
||||
meQuery.data?.memberships.find(
|
||||
(membership) => membership.community?._id === communityId,
|
||||
)?.user ?? null;
|
||||
const canManage = currentUser?.role === 'owner' || currentUser?.role === 'admin';
|
||||
const membersQuery = useLegacyImportMembers(
|
||||
{
|
||||
windowStart: fromInputValue(windowStart),
|
||||
windowEnd: fromInputValue(windowEnd),
|
||||
},
|
||||
communityId,
|
||||
canManage,
|
||||
);
|
||||
const jobsQuery = useLegacyImportJobs(communityId, canManage);
|
||||
const startMutation = useStartLegacyImport(communityId);
|
||||
const cancelMutation = useCancelLegacyImport(communityId);
|
||||
const members = membersQuery.data?.members ?? [];
|
||||
|
||||
useEffect(() => {
|
||||
setOverrides(
|
||||
Object.fromEntries(
|
||||
members.map((member) => [
|
||||
member.userId,
|
||||
{
|
||||
startTime: toInputValue(member.startTime),
|
||||
endTime: toInputValue(member.endTime),
|
||||
},
|
||||
]),
|
||||
),
|
||||
);
|
||||
}, [members]);
|
||||
|
||||
const manageableMemberships =
|
||||
meQuery.data?.memberships.filter((membership) => {
|
||||
const role = membership.user.role;
|
||||
return Boolean(
|
||||
membership.community && (role === 'owner' || role === 'admin'),
|
||||
);
|
||||
}) ?? [];
|
||||
const runningJob = useMemo(
|
||||
() =>
|
||||
jobsQuery.data?.jobs.find(
|
||||
(job) => job.state === 'pending' || job.state === 'running',
|
||||
),
|
||||
[jobsQuery.data?.jobs],
|
||||
);
|
||||
|
||||
async function invalidate() {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ['legacy-import-jobs', communityId] }),
|
||||
queryClient.invalidateQueries({ queryKey: ['legacy-matches', communityId] }),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['community-internal-stats-matches', communityId],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['community-internal-stats-leaderboard', communityId],
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
function handleStart() {
|
||||
if (!window.confirm('과거 type=tourney 매치 백필을 시작할까요? 야간/유휴 시간대 실행을 권장합니다.')) {
|
||||
return;
|
||||
}
|
||||
const payload: StartLegacyImportRequest = {
|
||||
windowStart: fromInputValue(windowStart),
|
||||
windowEnd: fromInputValue(windowEnd),
|
||||
memberOverrides: members.map((member) => ({
|
||||
userId: member.userId,
|
||||
startTime: fromInputValue(overrides[member.userId]?.startTime ?? ''),
|
||||
endTime: fromInputValue(overrides[member.userId]?.endTime ?? ''),
|
||||
})),
|
||||
};
|
||||
startMutation.mutate(payload, {
|
||||
onSuccess: async (result) => {
|
||||
await invalidate();
|
||||
setMessage(
|
||||
`백필 작업을 시작했습니다. ${result.totalMembers}명, 예상 ${formatEta(result.etaSeconds)}.`,
|
||||
);
|
||||
},
|
||||
onError: (error) => {
|
||||
setMessage(error instanceof Error ? error.message : '백필 시작 실패');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (!communityId) {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||
<h1 className="text-lg font-bold">커뮤니티 설정이 필요합니다</h1>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (meQuery.isPending) {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||
<h1 className="text-lg font-bold">권한 확인 중...</h1>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (!canManage) {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||
<h1 className="text-lg font-bold">권한이 필요합니다</h1>
|
||||
<p className="mt-2 text-sm text-base-content/40">
|
||||
Legacy 백필은 owner/admin만 실행할 수 있습니다.
|
||||
</p>
|
||||
{manageableMemberships.length > 0 && (
|
||||
<div className="mt-5 flex flex-wrap justify-center gap-2">
|
||||
{manageableMemberships.map((membership) => (
|
||||
<Link
|
||||
key={membership.community?._id ?? membership.user._id}
|
||||
to={`/admin/communities/${membership.community?._id}/legacy-import`}
|
||||
className="btn btn-primary btn-sm px-4 text-xs"
|
||||
>
|
||||
{membership.community?.name ?? '관리 가능한 커뮤니티'}로 이동
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 sm:px-6 py-6">
|
||||
<Link to="/" className="inline-flex text-xs text-base-content/40 hover:text-base-content mb-5">
|
||||
← 목록으로
|
||||
</Link>
|
||||
<div className="mb-6 flex flex-col sm:flex-row sm:items-end sm:justify-between gap-3">
|
||||
<div>
|
||||
<h1 className="text-2xl font-black text-base-content">
|
||||
Legacy 내전 백필
|
||||
</h1>
|
||||
<p className="mt-1 text-sm text-base-content/45">
|
||||
커뮤니티 멤버 PUUID로 과거 `type=tourney` 매치를 찾아 내전 기록으로 import합니다.
|
||||
</p>
|
||||
</div>
|
||||
<Link
|
||||
to={`/admin/communities/${communityId}/legacy-matches`}
|
||||
className="btn btn-ghost btn-sm px-4 text-xs"
|
||||
>
|
||||
Legacy 매치 정리
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<section className="border border-base-content/10 bg-base-100 p-4 mb-6">
|
||||
<h2 className="text-sm font-bold mb-3">검색 윈도우</h2>
|
||||
<div className="grid sm:grid-cols-[1fr_1fr_auto] gap-3 items-end">
|
||||
<label className="text-xs text-base-content/45">
|
||||
시작일
|
||||
<input
|
||||
type="datetime-local"
|
||||
value={windowStart}
|
||||
onChange={(event) => setWindowStart(event.target.value)}
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-xs"
|
||||
/>
|
||||
</label>
|
||||
<label className="text-xs text-base-content/45">
|
||||
종료일
|
||||
<input
|
||||
type="datetime-local"
|
||||
value={windowEnd}
|
||||
onChange={(event) => setWindowEnd(event.target.value)}
|
||||
placeholder="비우면 지금"
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-xs"
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm px-5 text-xs"
|
||||
disabled={startMutation.isPending || Boolean(runningJob)}
|
||||
onClick={handleStart}
|
||||
>
|
||||
{runningJob
|
||||
? '작업 진행 중'
|
||||
: startMutation.isPending
|
||||
? '시작 중...'
|
||||
: '백필 시작'}
|
||||
</button>
|
||||
</div>
|
||||
{message && (
|
||||
<div className="mt-3 border border-primary/15 bg-primary/5 px-3 py-2 text-xs text-base-content/55">
|
||||
{message}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="border border-base-content/10 bg-base-100 overflow-hidden mb-6">
|
||||
<div className="px-4 py-3 border-b border-base-content/10">
|
||||
<h2 className="text-sm font-bold">멤버별 윈도우</h2>
|
||||
<p className="mt-1 text-[11px] text-base-content/35">
|
||||
기본 시작일은 2024-05-01이며, 필요하면 멤버별 시작/종료 시간을 조정할 수 있습니다.
|
||||
비활성 멤버는 종료일이 마지막 업데이트 시각으로 잡힙니다.
|
||||
</p>
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full min-w-[900px] text-left">
|
||||
<thead>
|
||||
<tr className="bg-base-200/40 border-b border-base-content/10 text-[11px] uppercase tracking-wider text-base-content/35">
|
||||
<th className="px-3 py-2">멤버</th>
|
||||
<th className="px-3 py-2">Riot ID</th>
|
||||
<th className="px-3 py-2">상태</th>
|
||||
<th className="px-3 py-2">시작</th>
|
||||
<th className="px-3 py-2">종료</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{members.map((member) => (
|
||||
<tr key={member.userId} className="border-b border-base-content/5">
|
||||
<td className="px-3 py-2 text-sm font-bold">
|
||||
{member.displayName}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-xs text-base-content/45">
|
||||
{member.gameName}#{member.tagLine}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-xs">
|
||||
{member.isActivated ? '활성' : '비활성'}
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
<input
|
||||
type="datetime-local"
|
||||
value={overrides[member.userId]?.startTime ?? ''}
|
||||
onChange={(event) =>
|
||||
setOverrides((current) => ({
|
||||
...current,
|
||||
[member.userId]: {
|
||||
...current[member.userId],
|
||||
startTime: event.target.value,
|
||||
endTime: current[member.userId]?.endTime ?? '',
|
||||
},
|
||||
}))
|
||||
}
|
||||
className="border border-base-content/10 bg-transparent px-2 py-1 text-xs"
|
||||
/>
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
<input
|
||||
type="datetime-local"
|
||||
value={overrides[member.userId]?.endTime ?? ''}
|
||||
onChange={(event) =>
|
||||
setOverrides((current) => ({
|
||||
...current,
|
||||
[member.userId]: {
|
||||
...current[member.userId],
|
||||
startTime: current[member.userId]?.startTime ?? '',
|
||||
endTime: event.target.value,
|
||||
},
|
||||
}))
|
||||
}
|
||||
className="border border-base-content/10 bg-transparent px-2 py-1 text-xs"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{members.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={5} className="px-4 py-8 text-center text-sm text-base-content/35">
|
||||
Riot 계정이 있는 멤버가 없습니다.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-sm font-bold">작업 이력</h2>
|
||||
{(jobsQuery.data?.jobs ?? []).map((job) => (
|
||||
<JobCard
|
||||
key={job.jobId}
|
||||
job={job}
|
||||
cancelling={cancelMutation.isPending}
|
||||
onCancel={(jobId) =>
|
||||
cancelMutation.mutate(jobId, {
|
||||
onSuccess: invalidate,
|
||||
})
|
||||
}
|
||||
/>
|
||||
))}
|
||||
{(jobsQuery.data?.jobs ?? []).length === 0 && (
|
||||
<div className="border border-base-content/10 bg-base-100 px-4 py-8 text-center text-sm text-base-content/35">
|
||||
아직 실행한 백필 작업이 없습니다.
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { Link, useParams } from 'react-router';
|
||||
import {
|
||||
useBulkDeleteLegacyMatches,
|
||||
useDeleteMatch,
|
||||
useLegacyMatches,
|
||||
useMe,
|
||||
useRebuildLegacyMatches,
|
||||
} from '../../api/hooks';
|
||||
import type { LegacyMatchListItem } from '../../api/types';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../../config';
|
||||
import { teamIndexLabel } from '../../lib/league';
|
||||
|
||||
function formatDate(value: string) {
|
||||
return new Intl.DateTimeFormat('ko-KR', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(new Date(value));
|
||||
}
|
||||
|
||||
function resultLabel(match: LegacyMatchListItem) {
|
||||
if (!match.winnerTeamIndex) return '-';
|
||||
const winnerScore =
|
||||
match.winnerTeamIndex === match.teamAIndex
|
||||
? match.teamAWins
|
||||
: match.teamBWins;
|
||||
const loserScore =
|
||||
match.winnerTeamIndex === match.teamAIndex
|
||||
? match.teamBWins
|
||||
: match.teamAWins;
|
||||
return `${teamIndexLabel(match.winnerTeamIndex)} ${winnerScore}:${loserScore}`;
|
||||
}
|
||||
|
||||
export default function LegacyMatchesPage() {
|
||||
const { cid } = useParams();
|
||||
const communityId = cid ?? DEFAULT_COMMUNITY_ID;
|
||||
const queryClient = useQueryClient();
|
||||
const meQuery = useMe();
|
||||
const [selected, setSelected] = useState<Record<string, boolean>>({});
|
||||
const currentUser =
|
||||
meQuery.data?.memberships.find(
|
||||
(membership) => membership.community?._id === communityId,
|
||||
)?.user ?? null;
|
||||
const canManage = currentUser?.role === 'owner' || currentUser?.role === 'admin';
|
||||
const matchesQuery = useLegacyMatches(communityId, canManage);
|
||||
const deleteMutation = useDeleteMatch(communityId);
|
||||
const bulkDeleteMutation = useBulkDeleteLegacyMatches(communityId);
|
||||
const rebuildMutation = useRebuildLegacyMatches(communityId);
|
||||
const matches = matchesQuery.data?.pages.flatMap((page) => page.matches) ?? [];
|
||||
const selectedIds = useMemo(
|
||||
() => Object.entries(selected).filter(([, value]) => value).map(([id]) => id),
|
||||
[selected],
|
||||
);
|
||||
|
||||
async function invalidate() {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ['legacy-matches', communityId] }),
|
||||
queryClient.invalidateQueries({ queryKey: ['matches', communityId] }),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['community-internal-stats-matches', communityId],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['community-internal-stats-leaderboard', communityId],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['community-internal-stats-team-insights', communityId],
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
if (!communityId) {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||
<h1 className="text-lg font-bold">커뮤니티 설정이 필요합니다</h1>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (meQuery.isPending) {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||
<h1 className="text-lg font-bold">권한 확인 중...</h1>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (!canManage) {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||
<h1 className="text-lg font-bold">권한이 필요합니다</h1>
|
||||
<p className="mt-2 text-sm text-base-content/40">
|
||||
Legacy 매치 정리는 owner/admin만 사용할 수 있습니다.
|
||||
</p>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 sm:px-6 py-6">
|
||||
<Link
|
||||
to={`/admin/communities/${communityId}/legacy-import`}
|
||||
className="inline-flex text-xs text-base-content/40 hover:text-base-content mb-5"
|
||||
>
|
||||
← Legacy 백필
|
||||
</Link>
|
||||
<div className="mb-6 flex flex-col sm:flex-row sm:items-end sm:justify-between gap-3">
|
||||
<div>
|
||||
<h1 className="text-2xl font-black text-base-content">
|
||||
Legacy 매치 정리
|
||||
</h1>
|
||||
<p className="mt-1 text-sm text-base-content/45">
|
||||
백필로 들어온 매치를 확인하고 외부 토너먼트 기록을 삭제할 수 있습니다.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm px-4 text-xs"
|
||||
disabled={rebuildMutation.isPending}
|
||||
onClick={() => {
|
||||
if (!window.confirm('현재 가입자 기준으로 과거 매치를 재구성할까요?')) {
|
||||
return;
|
||||
}
|
||||
rebuildMutation.mutate(undefined, { onSuccess: invalidate });
|
||||
}}
|
||||
>
|
||||
{rebuildMutation.isPending ? '재구성 중...' : '과거 데이터 재구성'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-sm px-4 text-xs text-red-400"
|
||||
disabled={selectedIds.length === 0 || bulkDeleteMutation.isPending}
|
||||
onClick={() => {
|
||||
if (!window.confirm(`${selectedIds.length}개 매치를 삭제할까요?`)) return;
|
||||
bulkDeleteMutation.mutate(selectedIds, {
|
||||
onSuccess: async () => {
|
||||
setSelected({});
|
||||
await invalidate();
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
선택 삭제 ({selectedIds.length})
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{rebuildMutation.data && (
|
||||
<div className="mb-4 border border-primary/20 bg-primary/5 px-3 py-2 text-xs text-base-content/55">
|
||||
재구성 완료: {rebuildMutation.data.scanned}개 확인 ·{' '}
|
||||
{rebuildMutation.data.rebuilt}개 갱신 · 제목 정리{' '}
|
||||
{rebuildMutation.data.normalizedTitles}개
|
||||
</div>
|
||||
)}
|
||||
|
||||
<section className="border border-base-content/10 bg-base-100 overflow-hidden">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full min-w-[900px] text-left">
|
||||
<thead>
|
||||
<tr className="bg-base-200/40 border-b border-base-content/10 text-[11px] uppercase tracking-wider text-base-content/35">
|
||||
<th className="px-3 py-2 w-8">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={matches.length > 0 && selectedIds.length === matches.length}
|
||||
onChange={(event) => {
|
||||
const checked = event.target.checked;
|
||||
setSelected(
|
||||
Object.fromEntries(matches.map((match) => [match.matchId, checked])),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</th>
|
||||
<th className="px-3 py-2">시간</th>
|
||||
<th className="px-3 py-2">매치</th>
|
||||
<th className="px-3 py-2">Riot matchId</th>
|
||||
<th className="px-3 py-2">우리 멤버</th>
|
||||
<th className="px-3 py-2">외부</th>
|
||||
<th className="px-3 py-2">결과</th>
|
||||
<th className="px-3 py-2 text-right">작업</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{matches.map((match) => (
|
||||
<tr key={match.matchId} className="border-b border-base-content/5">
|
||||
<td className="px-3 py-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={Boolean(selected[match.matchId])}
|
||||
onChange={(event) =>
|
||||
setSelected((current) => ({
|
||||
...current,
|
||||
[match.matchId]: event.target.checked,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-3 py-2 text-xs text-base-content/45">
|
||||
{formatDate(match.scheduledAt)}
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
<Link
|
||||
to={`/communities/${communityId}/internal-stats/match/${match.matchId}`}
|
||||
className="text-sm font-bold hover:text-primary"
|
||||
>
|
||||
{match.title}
|
||||
</Link>
|
||||
</td>
|
||||
<td className="px-3 py-2 text-xs font-mono text-base-content/40">
|
||||
{match.riotMatchId ?? '-'}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-xs">{match.memberCount}명</td>
|
||||
<td className="px-3 py-2 text-xs">{match.externalCount}명</td>
|
||||
<td className="px-3 py-2 text-xs">{resultLabel(match)}</td>
|
||||
<td className="px-3 py-2 text-right">
|
||||
<button
|
||||
type="button"
|
||||
className="text-[11px] px-2 py-1 border border-red-500/20 text-red-400 hover:bg-red-500/10"
|
||||
disabled={deleteMutation.isPending}
|
||||
onClick={() => {
|
||||
if (!window.confirm('이 매치를 삭제할까요?')) return;
|
||||
deleteMutation.mutate(match.matchId, {
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
}}
|
||||
>
|
||||
삭제
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{matches.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={8} className="px-4 py-10 text-center text-sm text-base-content/35">
|
||||
Legacy import 매치가 없습니다.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{matchesQuery.hasNextPage && (
|
||||
<button
|
||||
type="button"
|
||||
className="mt-3 w-full border border-base-content/15 bg-base-100 py-3 text-sm font-bold text-base-content/60 hover:text-primary hover:border-primary/30 disabled:opacity-40"
|
||||
disabled={matchesQuery.isFetchingNextPage}
|
||||
onClick={() => matchesQuery.fetchNextPage()}
|
||||
>
|
||||
{matchesQuery.isFetchingNextPage ? '불러오는 중...' : '+ 더 보기'}
|
||||
</button>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,451 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { Link, useParams } from 'react-router';
|
||||
import {
|
||||
useCreateMatch,
|
||||
useDeleteMatch,
|
||||
useMatches,
|
||||
useMe,
|
||||
useUpdateMatch,
|
||||
} from '../../api/hooks';
|
||||
import type {
|
||||
ApiMatch,
|
||||
ApiMatchScheduleItem,
|
||||
MatchGameMode,
|
||||
MatchMutationRequest,
|
||||
} from '../../api/types';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../../config';
|
||||
|
||||
const DEFAULT_FORM: MatchMutationRequest = {
|
||||
title: '',
|
||||
description: '',
|
||||
mapId: 11,
|
||||
scheduledAt: toInputValue(new Date(Date.now() + 24 * 60 * 60 * 1000)),
|
||||
maxParticipants: 10,
|
||||
gameCount: 3,
|
||||
gameMode: 'pair',
|
||||
prizes: [],
|
||||
notices: [],
|
||||
schedule: [],
|
||||
};
|
||||
|
||||
const GAME_MODE_LABEL: Record<MatchGameMode, string> = {
|
||||
pair: '페어',
|
||||
bracket: '브래킷',
|
||||
'round-robin': '라운드 로빈',
|
||||
};
|
||||
|
||||
function RequiredBadge() {
|
||||
return (
|
||||
<span className="ml-1 inline-flex items-center border border-primary/20 bg-primary/5 px-1.5 py-0.5 text-[10px] font-bold text-primary">
|
||||
필수
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function toInputValue(value: string | Date) {
|
||||
const date = value instanceof Date ? value : new Date(value);
|
||||
const offset = date.getTimezoneOffset();
|
||||
return new Date(date.getTime() - offset * 60_000).toISOString().slice(0, 16);
|
||||
}
|
||||
|
||||
function toIsoFromInput(value: string) {
|
||||
return new Date(value).toISOString();
|
||||
}
|
||||
|
||||
function formatDate(value: string) {
|
||||
return new Intl.DateTimeFormat('ko-KR', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(new Date(value));
|
||||
}
|
||||
|
||||
function parseLines(value: string) {
|
||||
return value
|
||||
.split(/\r?\n/u)
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function parseSchedule(value: string): ApiMatchScheduleItem[] {
|
||||
return parseLines(value).map((line) => {
|
||||
const [time, ...labelParts] = line.split('|').map((part) => part.trim());
|
||||
return {
|
||||
time: time || '00:00',
|
||||
label: labelParts.join('|') || '일정',
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function scheduleToText(schedule: ApiMatchScheduleItem[] = []) {
|
||||
return schedule.map((item) => `${item.time}|${item.label}`).join('\n');
|
||||
}
|
||||
|
||||
function makeForm(match?: ApiMatch): MatchMutationRequest & {
|
||||
prizesText: string;
|
||||
noticesText: string;
|
||||
scheduleText: string;
|
||||
} {
|
||||
if (!match) {
|
||||
return {
|
||||
...DEFAULT_FORM,
|
||||
prizesText: '',
|
||||
noticesText: '',
|
||||
scheduleText: '',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
title: match.title,
|
||||
description: match.description,
|
||||
mapId: match.mapId,
|
||||
scheduledAt: toInputValue(match.scheduledAt),
|
||||
maxParticipants: match.maxParticipants,
|
||||
gameCount: match.gameCount,
|
||||
gameMode: match.gameMode ?? 'pair',
|
||||
prizes: match.prizes,
|
||||
notices: match.notices,
|
||||
schedule: match.schedule,
|
||||
prizesText: match.prizes.join('\n'),
|
||||
noticesText: match.notices.join('\n'),
|
||||
scheduleText: scheduleToText(match.schedule),
|
||||
};
|
||||
}
|
||||
|
||||
export default function MatchAdminPage() {
|
||||
const { cid } = useParams();
|
||||
const communityId = cid ?? DEFAULT_COMMUNITY_ID;
|
||||
const queryClient = useQueryClient();
|
||||
const meQuery = useMe();
|
||||
const matchesQuery = useMatches({ limit: 200 }, communityId);
|
||||
const createMutation = useCreateMatch(communityId);
|
||||
const updateMutation = useUpdateMatch(communityId);
|
||||
const deleteMutation = useDeleteMatch(communityId);
|
||||
const [editing, setEditing] = useState<ApiMatch | null>(null);
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [form, setForm] = useState(makeForm());
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
|
||||
const currentUser =
|
||||
meQuery.data?.memberships.find(
|
||||
(membership) => membership.community?._id === communityId,
|
||||
)?.user ?? null;
|
||||
const canManage = currentUser?.role === 'owner' || currentUser?.role === 'admin';
|
||||
const matches = useMemo(
|
||||
() => [...(matchesQuery.data ?? [])].sort((a, b) => new Date(b.scheduledAt).getTime() - new Date(a.scheduledAt).getTime()),
|
||||
[matchesQuery.data],
|
||||
);
|
||||
|
||||
async function invalidate() {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ['matches', communityId] }),
|
||||
queryClient.invalidateQueries({ queryKey: ['match', communityId] }),
|
||||
]);
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
setEditing(null);
|
||||
setForm(makeForm());
|
||||
setShowForm(true);
|
||||
setMessage(null);
|
||||
}
|
||||
|
||||
function openEdit(match: ApiMatch) {
|
||||
setEditing(match);
|
||||
setForm(makeForm(match));
|
||||
setShowForm(true);
|
||||
setMessage(null);
|
||||
}
|
||||
|
||||
function buildPayload(): MatchMutationRequest {
|
||||
return {
|
||||
title: form.title.trim(),
|
||||
description: form.description?.trim() ?? '',
|
||||
mapId: Number(form.mapId ?? 11),
|
||||
scheduledAt: toIsoFromInput(form.scheduledAt),
|
||||
maxParticipants: Number(form.maxParticipants ?? 10),
|
||||
gameCount: Number(form.gameCount ?? 3),
|
||||
gameMode: form.gameMode,
|
||||
prizes: parseLines(form.prizesText),
|
||||
notices: parseLines(form.noticesText),
|
||||
schedule: parseSchedule(form.scheduleText),
|
||||
};
|
||||
}
|
||||
|
||||
function submit() {
|
||||
setMessage(null);
|
||||
if (!form.title.trim()) {
|
||||
setMessage('제목을 입력해주세요.');
|
||||
return;
|
||||
}
|
||||
if (!form.scheduledAt) {
|
||||
setMessage('시작 시간을 입력해주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = buildPayload();
|
||||
|
||||
const callbacks = {
|
||||
onSuccess: async () => {
|
||||
await invalidate();
|
||||
setShowForm(false);
|
||||
setEditing(null);
|
||||
setMessage(editing ? '내전을 수정했습니다.' : '내전을 만들었습니다.');
|
||||
},
|
||||
onError: (error: Error) => setMessage(error.message),
|
||||
};
|
||||
|
||||
if (editing) {
|
||||
updateMutation.mutate({ matchId: editing._id, body: payload }, callbacks);
|
||||
return;
|
||||
}
|
||||
createMutation.mutate(payload, callbacks);
|
||||
}
|
||||
|
||||
if (!canManage && !meQuery.isPending) {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||
<h1 className="text-lg font-bold">권한이 필요합니다</h1>
|
||||
<p className="mt-2 text-sm text-base-content/40">
|
||||
내전 관리는 owner/admin만 사용할 수 있습니다.
|
||||
</p>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 sm:px-6 py-6">
|
||||
<Link to="/" className="inline-flex text-xs text-base-content/40 hover:text-base-content mb-5">
|
||||
← 목록으로
|
||||
</Link>
|
||||
<div className="mb-6 flex flex-col sm:flex-row sm:items-end sm:justify-between gap-3">
|
||||
<div>
|
||||
<h1 className="text-2xl font-black text-base-content">내전 관리</h1>
|
||||
<p className="mt-1 text-sm text-base-content/45">
|
||||
내전 생성, 모집 정원, 게임 모드와 공지 내용을 관리합니다.
|
||||
</p>
|
||||
</div>
|
||||
<button type="button" className="btn btn-primary btn-sm px-5 text-xs" onClick={openCreate}>
|
||||
새 내전 만들기
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{message && (
|
||||
<div className="mb-4 border border-primary/20 bg-primary/5 px-3 py-2 text-xs text-base-content/60">
|
||||
{message}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showForm && (
|
||||
<section className="mb-6 border border-base-content/10 bg-base-100 p-4">
|
||||
<div className="mb-4 flex items-center justify-between gap-3">
|
||||
<h2 className="text-sm font-bold">
|
||||
{editing ? '내전 수정' : '새 내전'}
|
||||
</h2>
|
||||
<button
|
||||
type="button"
|
||||
className="text-xs text-base-content/35 hover:text-base-content"
|
||||
onClick={() => setShowForm(false)}
|
||||
>
|
||||
닫기
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="grid md:grid-cols-2 gap-3">
|
||||
<label className="text-xs text-base-content/45 md:col-span-2">
|
||||
제목
|
||||
<RequiredBadge />
|
||||
<input
|
||||
required
|
||||
value={form.title}
|
||||
onChange={(event) => setForm((current) => ({ ...current, title: event.target.value }))}
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="text-xs text-base-content/45 md:col-span-2">
|
||||
설명
|
||||
<span className="ml-1 text-[10px] text-base-content/25">선택</span>
|
||||
<textarea
|
||||
value={form.description}
|
||||
onChange={(event) => setForm((current) => ({ ...current, description: event.target.value }))}
|
||||
rows={3}
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="text-xs text-base-content/45">
|
||||
시작 시간
|
||||
<RequiredBadge />
|
||||
<input
|
||||
required
|
||||
type="datetime-local"
|
||||
value={form.scheduledAt}
|
||||
onChange={(event) => setForm((current) => ({ ...current, scheduledAt: event.target.value }))}
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="text-xs text-base-content/45">
|
||||
정원
|
||||
<select
|
||||
value={form.maxParticipants}
|
||||
onChange={(event) => setForm((current) => ({ ...current, maxParticipants: Number(event.target.value) }))}
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
|
||||
>
|
||||
{[10, 20, 30, 40, 50, 60].map((value) => (
|
||||
<option key={value} value={value}>{value}명</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="text-xs text-base-content/45">
|
||||
게임 수
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
value={form.gameCount}
|
||||
onChange={(event) => setForm((current) => ({ ...current, gameCount: Number(event.target.value) }))}
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="text-xs text-base-content/45">
|
||||
게임 모드
|
||||
<select
|
||||
value={form.gameMode}
|
||||
onChange={(event) => setForm((current) => ({ ...current, gameMode: event.target.value as MatchGameMode }))}
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
|
||||
>
|
||||
{Object.entries(GAME_MODE_LABEL).map(([value, label]) => (
|
||||
<option key={value} value={value}>{label}</option>
|
||||
))}
|
||||
</select>
|
||||
<span className="mt-1 block text-[10px] text-amber-500/80">
|
||||
현재 경매/코드 연결은 페어 방식 기준으로 동작합니다.
|
||||
</span>
|
||||
</label>
|
||||
<label className="text-xs text-base-content/45">
|
||||
상품 (줄바꿈 구분)
|
||||
<textarea
|
||||
value={form.prizesText}
|
||||
onChange={(event) => setForm((current) => ({ ...current, prizesText: event.target.value }))}
|
||||
rows={4}
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="text-xs text-base-content/45">
|
||||
공지 (줄바꿈 구분)
|
||||
<textarea
|
||||
value={form.noticesText}
|
||||
onChange={(event) => setForm((current) => ({ ...current, noticesText: event.target.value }))}
|
||||
rows={4}
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm"
|
||||
/>
|
||||
</label>
|
||||
<label className="text-xs text-base-content/45 md:col-span-2">
|
||||
일정 (`시간|라벨`, 줄바꿈 구분)
|
||||
<textarea
|
||||
value={form.scheduleText}
|
||||
onChange={(event) => setForm((current) => ({ ...current, scheduleText: event.target.value }))}
|
||||
rows={3}
|
||||
placeholder="20:50|로비 오픈"
|
||||
className="mt-1 w-full border border-base-content/10 bg-transparent px-3 py-2 text-sm font-mono"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm px-5 text-xs"
|
||||
disabled={createMutation.isPending || updateMutation.isPending}
|
||||
onClick={submit}
|
||||
>
|
||||
{editing ? '수정 저장' : '생성'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-sm px-5 text-xs"
|
||||
onClick={() => setShowForm(false)}
|
||||
>
|
||||
취소
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<section className="border border-base-content/10 bg-base-100 overflow-hidden">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full min-w-[900px] text-left">
|
||||
<thead>
|
||||
<tr className="bg-base-200/40 border-b border-base-content/10 text-[11px] uppercase tracking-wider text-base-content/35">
|
||||
<th className="px-3 py-2">시간</th>
|
||||
<th className="px-3 py-2">내전</th>
|
||||
<th className="px-3 py-2">상태</th>
|
||||
<th className="px-3 py-2">정원</th>
|
||||
<th className="px-3 py-2">모드</th>
|
||||
<th className="px-3 py-2 text-right">작업</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{matches.map((match) => (
|
||||
<tr key={match._id} className="border-b border-base-content/5">
|
||||
<td className="px-3 py-2 text-xs text-base-content/45">
|
||||
{formatDate(match.scheduledAt)}
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
<Link to={`/match/${match._id}`} className="text-sm font-bold hover:text-primary">
|
||||
{match.title}
|
||||
</Link>
|
||||
<div className="mt-0.5 text-[11px] text-base-content/30">
|
||||
{match.description || '-'}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-3 py-2 text-xs">{match.status}</td>
|
||||
<td className="px-3 py-2 text-xs tabular-nums">
|
||||
{match.participants.length}/{match.maxParticipants}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-xs">
|
||||
{GAME_MODE_LABEL[match.gameMode ?? 'pair']}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-right">
|
||||
<div className="inline-flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="text-[11px] px-2 py-1 border border-base-content/10 text-base-content/50 hover:text-primary"
|
||||
onClick={() => openEdit(match)}
|
||||
>
|
||||
수정
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="text-[11px] px-2 py-1 border border-red-500/20 text-red-400 hover:bg-red-500/10"
|
||||
disabled={deleteMutation.isPending}
|
||||
onClick={() => {
|
||||
if (!window.confirm('이 내전을 삭제할까요?')) return;
|
||||
deleteMutation.mutate(match._id, {
|
||||
onSuccess: invalidate,
|
||||
onError: (error) =>
|
||||
setMessage(error instanceof Error ? error.message : '삭제 실패'),
|
||||
});
|
||||
}}
|
||||
>
|
||||
삭제
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{matches.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={6} className="px-4 py-10 text-center text-sm text-base-content/35">
|
||||
등록된 내전이 없습니다.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user