feat(web): add auction and admin workflows
This commit is contained in:
1 parent
a1a77f3338
commit
7989da96d0
4 files changed
+1816
No files matched your search
@@ -0,0 +1,802 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Link, useParams } from 'react-router';
|
||||
import { useAuction, useDdragonManifest, useMatch, useMe } from '../api/hooks';
|
||||
import {
|
||||
formatTierLabel,
|
||||
getTierColorToken,
|
||||
mapApiAuctionToAuctionState,
|
||||
type AuctionStateView,
|
||||
} from '../api/mappers';
|
||||
import { useAuctionSocket } from '../api/useAuctionSocket';
|
||||
import {
|
||||
DEFAULT_COMMUNITY_ID,
|
||||
setDevCaptainSide,
|
||||
useDevCaptainSide,
|
||||
} from '../config';
|
||||
import { ApiError } from '../lib/api';
|
||||
import {
|
||||
championDisplayName,
|
||||
championIconUrl,
|
||||
profileIconUrl,
|
||||
} from '../lib/ddragon';
|
||||
import { positionIcon, positionLabel } from '../lib/league';
|
||||
import type { ApiRiotLaneStats, Position } from '../api/types';
|
||||
|
||||
function formatPoints(value: number) {
|
||||
return value.toLocaleString();
|
||||
}
|
||||
|
||||
const AUCTION_MAX_TEAM_SIZE = 5;
|
||||
const LANE_ROWS: Position[] = ['TOP', 'JGL', 'MID', 'ADC', 'SUP'];
|
||||
const POSITION_TO_RIOT_LANE = {
|
||||
TOP: 'TOP',
|
||||
JGL: 'JUNGLE',
|
||||
MID: 'MIDDLE',
|
||||
ADC: 'BOTTOM',
|
||||
SUP: 'UTILITY',
|
||||
} as const;
|
||||
|
||||
function PosBadge({ pos }: { pos: Position }) {
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1.5 text-[11px] font-medium px-1.5 py-0.5 border border-primary/20 text-primary bg-primary/5">
|
||||
<img src={positionIcon[pos]} alt="" className="w-3.5 h-3.5 object-contain" />
|
||||
<span>{positionLabel[pos]}</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function TimerBar({ timer, maxTimer }: { timer: number; maxTimer: number }) {
|
||||
const pct = maxTimer > 0 ? (timer / maxTimer) * 100 : 0;
|
||||
const urgent = timer <= 5;
|
||||
|
||||
return (
|
||||
<div className="w-full h-1.5 bg-base-content/5">
|
||||
<div
|
||||
className={`h-full transition-all duration-1000 linear ${urgent ? 'bg-red-500' : 'bg-primary'}`}
|
||||
style={{ width: `${pct}%` }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function getWinRate(stats: ApiRiotLaneStats) {
|
||||
return stats.games > 0 ? Math.round((stats.wins / stats.games) * 100) : 0;
|
||||
}
|
||||
|
||||
function getWinRateClass(winRate: number) {
|
||||
if (winRate >= 55) return 'text-blue-400';
|
||||
if (winRate >= 50) return 'text-base-content';
|
||||
return 'text-red-400';
|
||||
}
|
||||
|
||||
function formatKdaRatio(stats: ApiRiotLaneStats) {
|
||||
if (stats.avgDeaths === 0) return 'Perfect';
|
||||
return ((stats.avgKills + stats.avgAssists) / stats.avgDeaths).toFixed(2);
|
||||
}
|
||||
|
||||
function RecentSoloStats({
|
||||
player,
|
||||
}: {
|
||||
player: NonNullable<AuctionStateView['currentPlayer']>;
|
||||
}) {
|
||||
const primaryStats = player.recentStats.primary;
|
||||
|
||||
if (!primaryStats) {
|
||||
return (
|
||||
<div className="p-4">
|
||||
<h4 className="text-[10px] font-bold uppercase tracking-wider text-base-content/30 mb-2.5">
|
||||
최근 솔로랭크
|
||||
</h4>
|
||||
<div className="rounded border border-dashed border-base-content/10 px-3 py-6 text-center text-[11px] text-base-content/25">
|
||||
최근 솔로랭크 기록이 없습니다
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const primaryWinRate = getWinRate(primaryStats);
|
||||
const primaryKdaRatio = formatKdaRatio(primaryStats);
|
||||
|
||||
return (
|
||||
<div className="p-4">
|
||||
<div className="flex items-start justify-between gap-3 mb-3">
|
||||
<div>
|
||||
<h4 className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
|
||||
최근 솔로랭크
|
||||
</h4>
|
||||
<div className="mt-1 flex items-center gap-2">
|
||||
<span className="text-[12px] font-semibold text-base-content">
|
||||
{positionLabel[player.mainPosition]}
|
||||
</span>
|
||||
{player.recentStats.primarySource === 'overall' ? (
|
||||
<span className="text-[10px] text-base-content/35">
|
||||
전체 기준
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={`text-sm font-bold tabular-nums ${getWinRateClass(primaryWinRate)}`}
|
||||
>
|
||||
{primaryWinRate}%
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-baseline justify-between">
|
||||
<span className="text-[11px] text-base-content/40">전적</span>
|
||||
<span className="text-[12px] text-base-content/60 tabular-nums">
|
||||
<span className="text-blue-400">{primaryStats.wins}W</span>{' '}
|
||||
<span className="text-red-400">{primaryStats.losses}L</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-baseline justify-between">
|
||||
<span className="text-[11px] text-base-content/40">KDA</span>
|
||||
<span className="text-[12px] text-base-content/60 tabular-nums">
|
||||
{primaryStats.avgKills}/{primaryStats.avgDeaths}/{primaryStats.avgAssists}
|
||||
<span
|
||||
className={`ml-1 font-bold ${Number(primaryKdaRatio) >= 3 ? 'text-emerald-400' : 'text-base-content/50'}`}
|
||||
>
|
||||
({primaryKdaRatio})
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-baseline justify-between">
|
||||
<span className="text-[11px] text-base-content/40">분당 CS</span>
|
||||
<span className="text-[12px] text-base-content/60 tabular-nums">
|
||||
{primaryStats.avgCsPerMin}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 border-t border-base-content/8 pt-3 space-y-1.5">
|
||||
{LANE_ROWS.map((position) => {
|
||||
const laneStats =
|
||||
player.recentStats.byLane[POSITION_TO_RIOT_LANE[position]];
|
||||
const isMainLane = position === player.mainPosition;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={position}
|
||||
className={`flex items-center justify-between gap-3 text-[11px] ${isMainLane ? 'font-semibold text-base-content' : 'text-base-content/65'}`}
|
||||
>
|
||||
<span className={isMainLane ? 'text-base-content' : 'text-base-content/35'}>
|
||||
{positionLabel[position]}
|
||||
</span>
|
||||
{laneStats && laneStats.games > 0 ? (
|
||||
<span className="tabular-nums text-right">
|
||||
{laneStats.wins}W {laneStats.losses}L · {laneStats.avgKills}/
|
||||
{laneStats.avgDeaths}/{laneStats.avgAssists} ·{' '}
|
||||
{laneStats.avgCsPerMin} CS/min
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-base-content/20">—</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TeamPanel({
|
||||
team,
|
||||
isActive,
|
||||
isLeft,
|
||||
}: {
|
||||
team: AuctionStateView['teams'][number];
|
||||
isActive: boolean;
|
||||
isLeft: boolean;
|
||||
}) {
|
||||
const { data: ddragon } = useDdragonManifest();
|
||||
const borderColor =
|
||||
team.side === 'blue' ? 'border-blue-500/25' : 'border-red-500/25';
|
||||
const accentBar = team.side === 'blue' ? 'bg-blue-500' : 'bg-red-500';
|
||||
const sideColor = team.side === 'blue' ? 'text-blue-400' : 'text-red-400';
|
||||
const headerBg = team.side === 'blue' ? 'bg-blue-500/8' : 'bg-red-500/8';
|
||||
const teamSize = team.members.length + 1;
|
||||
const isFull = teamSize >= AUCTION_MAX_TEAM_SIZE;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`border ${borderColor} bg-base-100 relative ${isActive ? 'ring-1 ring-primary/30' : ''}`}
|
||||
>
|
||||
<div
|
||||
className={`absolute ${isLeft ? 'left-0' : 'right-0'} top-0 bottom-0 w-0.5 ${accentBar}`}
|
||||
/>
|
||||
<div className={`${headerBg} px-3 py-2 border-b ${borderColor}`}>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className={`text-[11px] font-bold uppercase tracking-wide ${sideColor}`}>
|
||||
{team.side === 'blue' ? '블루팀' : '레드팀'}
|
||||
</span>
|
||||
<span className="text-[10px] text-base-content/30">
|
||||
팀장: {team.captainName}
|
||||
</span>
|
||||
</div>
|
||||
<span className="text-xs font-bold text-amber-400 tabular-nums">
|
||||
{formatPoints(team.points)}P
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-1 flex items-center justify-between text-[10px]">
|
||||
<span className="text-base-content/25">
|
||||
팀장 포함 {teamSize}/{AUCTION_MAX_TEAM_SIZE}
|
||||
</span>
|
||||
{isFull && <span className="font-bold text-amber-400">정원 완료</span>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="divide-y divide-base-content/5">
|
||||
{team.members.length === 0 ? (
|
||||
<div className="px-3 py-6 text-center text-[11px] text-base-content/20">
|
||||
아직 멤버가 없습니다
|
||||
</div>
|
||||
) : (
|
||||
team.members.map((member) => (
|
||||
<div key={`${member.userId}-${member.assignedPosition}`} className="px-3 py-1.5 flex items-center gap-2">
|
||||
<Link
|
||||
to={`/users/${member.userId}/history`}
|
||||
className="flex flex-1 min-w-0 items-center gap-2 group"
|
||||
>
|
||||
<div className="w-6 h-6 bg-base-content/10 overflow-hidden shrink-0">
|
||||
<img
|
||||
src={profileIconUrl(ddragon, member.profileIconId)}
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<span className="text-[12px] font-medium text-base-content truncate block leading-tight group-hover:text-primary transition-colors">
|
||||
{member.summonerName}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
<PosBadge pos={member.assignedPosition} />
|
||||
<span className="text-[10px] text-amber-400/60 tabular-nums w-8 text-right">
|
||||
{member.cost}
|
||||
</span>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
|
||||
{Array.from({
|
||||
length: Math.max(0, AUCTION_MAX_TEAM_SIZE - 1 - team.members.length),
|
||||
}).map((_, index) => (
|
||||
<div
|
||||
key={`empty-${team.side}-${index}`}
|
||||
className="px-3 py-1.5 h-[34px] flex items-center"
|
||||
>
|
||||
<div className="w-6 h-6 border border-dashed border-base-content/8 shrink-0" />
|
||||
<span className="ml-2 text-[10px] text-base-content/10">—</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PlayerSpotlight({
|
||||
state,
|
||||
}: {
|
||||
state: AuctionStateView;
|
||||
}) {
|
||||
const { data: ddragon } = useDdragonManifest();
|
||||
const player = state.currentPlayer;
|
||||
if (!player) return null;
|
||||
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100">
|
||||
<div className="p-5 border-b border-base-content/8">
|
||||
<div className="flex items-start gap-4">
|
||||
<Link
|
||||
to={`/users/${player.userId}/history`}
|
||||
className="w-16 h-16 bg-base-content/10 overflow-hidden shrink-0"
|
||||
>
|
||||
<img
|
||||
src={profileIconUrl(ddragon, player.profileIconId)}
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
</Link>
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<Link
|
||||
to={`/users/${player.userId}/history`}
|
||||
className="text-lg font-bold text-base-content leading-tight hover:text-primary transition-colors"
|
||||
>
|
||||
{player.summonerName}
|
||||
</Link>
|
||||
<span className="text-[10px] text-base-content/25">
|
||||
#{player.tag}
|
||||
</span>
|
||||
</div>
|
||||
<div className={`text-[11px] mb-2 font-bold ${getTierColorToken(player.tier)}`}>
|
||||
{formatTierLabel(player.tier)}
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<PosBadge pos={player.mainPosition} />
|
||||
<span className="inline-flex items-center gap-0.5 text-[11px] px-1.5 py-0.5 border border-base-content/8 text-base-content/35">
|
||||
<img
|
||||
src={positionIcon[player.subPosition]}
|
||||
alt=""
|
||||
className="w-3.5 h-3.5 object-contain inline"
|
||||
/>{' '}
|
||||
{positionLabel[player.subPosition]}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 divide-x divide-base-content/5">
|
||||
<div className="p-4">
|
||||
<h4 className="text-[10px] font-bold uppercase tracking-wider text-base-content/30 mb-2.5">
|
||||
숙련도 높은 챔피언
|
||||
</h4>
|
||||
<div className="space-y-2">
|
||||
{player.masteries.length > 0 ? (
|
||||
player.masteries.map((mastery) => {
|
||||
const iconUrl = championIconUrl(ddragon, mastery.championId);
|
||||
const displayName =
|
||||
championDisplayName(ddragon, mastery.championId) ??
|
||||
String(mastery.championId);
|
||||
return (
|
||||
<div key={mastery.championId} className="flex items-center gap-2">
|
||||
<div className="w-7 h-7 bg-base-content/10 overflow-hidden shrink-0">
|
||||
{iconUrl ? (
|
||||
<img
|
||||
src={iconUrl}
|
||||
alt={displayName}
|
||||
className="w-full h-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="text-[12px] font-medium text-base-content truncate">
|
||||
{displayName}
|
||||
</div>
|
||||
<div className="text-[10px] text-base-content/25">
|
||||
Lv.{mastery.level} · {(mastery.points / 1000).toFixed(0)}K
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<div className="text-[11px] text-base-content/25">
|
||||
숙련도 데이터가 없습니다.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<RecentSoloStats player={player} />
|
||||
</div>
|
||||
|
||||
{(state.phase === 'bidding' || state.phase === 'sold') && (
|
||||
<div className="border-t border-base-content/8 px-4 py-3 bg-base-content/[0.02]">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-[11px] text-base-content/30 uppercase tracking-wider font-semibold">
|
||||
{state.phase === 'sold' ? '낙찰가' : '현재 입찰가'}
|
||||
</span>
|
||||
<div className="flex items-center gap-2">
|
||||
{state.currentBidder && (
|
||||
<span
|
||||
className={`text-[10px] font-bold uppercase ${state.currentBidder === 'blue' ? 'text-blue-400' : 'text-red-400'}`}
|
||||
>
|
||||
{state.currentBidder === 'blue' ? '블루' : '레드'}
|
||||
</span>
|
||||
)}
|
||||
<span className="text-lg font-black text-amber-400 tabular-nums">
|
||||
{state.currentBid > 0 ? formatPoints(state.currentBid) : '—'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function BidControls({
|
||||
state,
|
||||
captainSide,
|
||||
onBid,
|
||||
}: {
|
||||
state: AuctionStateView;
|
||||
captainSide: 'spectator' | 'blue' | 'red';
|
||||
onBid: (side: 'blue' | 'red', amount: number) => void;
|
||||
}) {
|
||||
const [bidAmount, setBidAmount] = useState(100);
|
||||
const minBid = state.currentBid + 10;
|
||||
const activeTeam =
|
||||
captainSide === 'blue'
|
||||
? state.teams[0]
|
||||
: captainSide === 'red'
|
||||
? state.teams[1]
|
||||
: null;
|
||||
const activeTeamSize = activeTeam ? activeTeam.members.length + 1 : 0;
|
||||
const isActiveTeamFull = activeTeamSize >= AUCTION_MAX_TEAM_SIZE;
|
||||
|
||||
useEffect(() => {
|
||||
setBidAmount(Math.max(minBid, Math.ceil(minBid / 10) * 10));
|
||||
}, [state.currentBid, minBid]);
|
||||
|
||||
if (state.phase !== 'bidding') return null;
|
||||
|
||||
if (!activeTeam) {
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100 px-4 py-3 text-sm text-base-content/40">
|
||||
관전자 모드입니다. 우측 상단에서 조작자 역할을 선택하면 입찰할 수 있습니다.
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const presets = [50, 100, 150, 200, 300, 500];
|
||||
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100 p-4">
|
||||
<div className="flex items-center gap-2 mb-3 flex-wrap">
|
||||
{presets.map((preset) => (
|
||||
<button
|
||||
key={preset}
|
||||
onClick={() => setBidAmount(Math.max(minBid, preset))}
|
||||
disabled={isActiveTeamFull}
|
||||
className={`text-[11px] px-2.5 py-1 border transition-colors ${
|
||||
bidAmount === preset
|
||||
? 'border-primary/40 bg-primary/10 text-primary'
|
||||
: 'border-base-content/10 text-base-content/40 hover:border-base-content/20'
|
||||
}`}
|
||||
>
|
||||
{preset}P
|
||||
</button>
|
||||
))}
|
||||
<input
|
||||
type="number"
|
||||
value={bidAmount}
|
||||
onChange={(event) =>
|
||||
setBidAmount(Math.max(minBid, Number(event.target.value)))
|
||||
}
|
||||
min={minBid}
|
||||
disabled={isActiveTeamFull}
|
||||
className="w-24 text-xs px-2 py-1 border border-base-content/10 bg-transparent text-base-content tabular-nums text-right focus:outline-none focus:border-primary/30"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => onBid(activeTeam.side, bidAmount)}
|
||||
disabled={
|
||||
isActiveTeamFull ||
|
||||
bidAmount > activeTeam.points ||
|
||||
bidAmount <= state.currentBid
|
||||
}
|
||||
className={`w-full py-2 text-xs font-bold uppercase tracking-wide border transition-colors disabled:opacity-30 disabled:cursor-not-allowed ${
|
||||
activeTeam.side === 'blue'
|
||||
? 'border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20'
|
||||
: 'border-red-500/30 bg-red-500/10 text-red-400 hover:bg-red-500/20'
|
||||
}`}
|
||||
>
|
||||
{isActiveTeamFull
|
||||
? `${activeTeam.side === 'blue' ? '블루팀' : '레드팀'} 정원 완료 (${activeTeamSize}/${AUCTION_MAX_TEAM_SIZE})`
|
||||
: `${activeTeam.side === 'blue' ? '블루팀' : '레드팀'} 입찰 (${formatPoints(bidAmount)}P)`}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function BidLog({ bids }: { bids: AuctionStateView['bids'] }) {
|
||||
const endRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
endRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||
}, [bids.length]);
|
||||
|
||||
if (bids.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100 overflow-hidden">
|
||||
<div className="px-3 py-1.5 border-b border-base-content/8 bg-base-200/40">
|
||||
<span className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
|
||||
입찰 기록
|
||||
</span>
|
||||
</div>
|
||||
<div className="max-h-28 overflow-y-auto p-2 space-y-0.5">
|
||||
{bids.map((bid, index) => (
|
||||
<div key={`${bid.side}-${bid.timestamp}-${index}`} className="flex items-center gap-2 text-[11px]">
|
||||
<span
|
||||
className={`font-bold uppercase ${bid.side === 'blue' ? 'text-blue-400' : 'text-red-400'}`}
|
||||
>
|
||||
{bid.side === 'blue' ? '블루' : '레드'}
|
||||
</span>
|
||||
<span className="text-base-content/30">→</span>
|
||||
<span className="text-amber-400 tabular-nums font-semibold">
|
||||
{formatPoints(bid.amount)}P
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
<div ref={endRef} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function AuctionPage() {
|
||||
const { id } = useParams();
|
||||
const meQuery = useMe();
|
||||
const currentUser =
|
||||
meQuery.data?.memberships.find(
|
||||
(membership) => membership.community?._id === DEFAULT_COMMUNITY_ID,
|
||||
)?.user ?? null;
|
||||
const matchQuery = useMatch(id, DEFAULT_COMMUNITY_ID);
|
||||
const auctionQuery = useAuction(id, DEFAULT_COMMUNITY_ID);
|
||||
const socket = useAuctionSocket(id);
|
||||
const captainSide = useDevCaptainSide();
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
const [assignedPosition, setAssignedPosition] = useState<Position>('MID');
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setInterval(() => setNow(Date.now()), 1000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
const liveAuction = socket.auction ?? auctionQuery.data ?? null;
|
||||
const auctionState =
|
||||
liveAuction && matchQuery.data
|
||||
? mapApiAuctionToAuctionState(liveAuction, matchQuery.data, new Date(now))
|
||||
: null;
|
||||
|
||||
useEffect(() => {
|
||||
if (auctionState?.currentPlayer) {
|
||||
setAssignedPosition(auctionState.currentPlayer.mainPosition);
|
||||
}
|
||||
}, [auctionState?.currentPlayer?.id]);
|
||||
|
||||
if (!DEFAULT_COMMUNITY_ID) {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||
<span className="text-sm text-amber-600">
|
||||
`VITE_DEFAULT_COMMUNITY_ID` 설정이 필요합니다.
|
||||
</span>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (matchQuery.isLoading || (auctionQuery.isLoading && !socket.auction)) {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||
<span className="text-sm text-base-content/40">경매를 연결하는 중...</span>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (auctionQuery.error instanceof ApiError && auctionQuery.error.status === 404 && !socket.auction) {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||
<h2 className="text-lg font-bold mb-2">경매가 아직 시작되지 않았습니다</h2>
|
||||
<Link to={`/match/${id}`} className="btn btn-primary btn-sm mt-4 px-5 text-xs">
|
||||
내전 상세로 돌아가기
|
||||
</Link>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (!auctionState || !matchQuery.data) {
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||
<span className="text-sm text-red-500">
|
||||
경매 상태를 불러오지 못했습니다.
|
||||
</span>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
const canManageAuction =
|
||||
import.meta.env.DEV ||
|
||||
currentUser?.role === 'owner' ||
|
||||
currentUser?.role === 'admin';
|
||||
const phaseLabel: Record<AuctionStateView['phase'], string> = {
|
||||
waiting: '경매 준비 중...',
|
||||
presenting: '다음 선수 등장',
|
||||
bidding: '입찰 진행 중',
|
||||
sold: '낙찰!',
|
||||
complete: '경매 완료',
|
||||
};
|
||||
const errorMessage =
|
||||
socket.error ??
|
||||
(auctionQuery.error instanceof Error ? auctionQuery.error.message : null);
|
||||
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-6">
|
||||
<Link
|
||||
to={`/match/${id}`}
|
||||
className="inline-flex items-center gap-1 text-xs text-base-content/40 hover:text-base-content transition-colors mb-4"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="h-3.5 w-3.5"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M15 19l-7-7 7-7"
|
||||
/>
|
||||
</svg>
|
||||
내전 상세로
|
||||
</Link>
|
||||
|
||||
{errorMessage && (
|
||||
<div className="mb-4 border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-500">
|
||||
{errorMessage}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mb-5 flex items-start justify-between flex-wrap gap-3">
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-base-content leading-tight">
|
||||
경매 팀빌딩
|
||||
</h1>
|
||||
<p className="text-[11px] text-base-content/30 mt-0.5">
|
||||
{Math.min(auctionState.currentPlayerIndex + 1, Math.max(auctionState.totalPlayers, 1))} /{' '}
|
||||
{auctionState.totalPlayers} 선수
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col items-end gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className={`inline-flex items-center text-[11px] font-semibold px-2 py-1 border ${
|
||||
auctionState.phase === 'bidding'
|
||||
? 'border-green-500/20 bg-green-500/10 text-green-400'
|
||||
: auctionState.phase === 'sold'
|
||||
? 'border-amber-500/20 bg-amber-500/10 text-amber-400'
|
||||
: 'border-base-content/10 bg-base-content/5 text-base-content/40'
|
||||
}`}
|
||||
>
|
||||
{phaseLabel[auctionState.phase]}
|
||||
</span>
|
||||
{auctionState.phase === 'bidding' && (
|
||||
<span
|
||||
className={`text-lg font-black tabular-nums ${auctionState.timer <= 5 ? 'text-red-500' : 'text-base-content'}`}
|
||||
>
|
||||
{auctionState.timer}s
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-xs text-base-content/40">
|
||||
<span>소켓: {socket.connectionStatus}</span>
|
||||
{/* 임시 운영용: 로그인/권한 확인 없이 조작자 역할을 선택할 수 있게 열어둔다. */}
|
||||
<select
|
||||
value={captainSide}
|
||||
onChange={(event) =>
|
||||
setDevCaptainSide(event.target.value as 'spectator' | 'blue' | 'red')
|
||||
}
|
||||
className="border border-base-content/10 bg-transparent px-2 py-1 text-xs"
|
||||
>
|
||||
<option value="spectator">관전자</option>
|
||||
<option value="blue">블루팀장</option>
|
||||
<option value="red">레드팀장</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{auctionState.phase === 'bidding' && (
|
||||
<TimerBar timer={auctionState.timer} maxTimer={auctionState.maxTimer} />
|
||||
)}
|
||||
|
||||
<div className="flex flex-col lg:flex-row gap-4 mt-4">
|
||||
<div className="w-full lg:w-56 shrink-0">
|
||||
<TeamPanel
|
||||
team={auctionState.teams[0]}
|
||||
isActive={auctionState.currentBidder === 'blue'}
|
||||
isLeft
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-w-0 space-y-4">
|
||||
{auctionState.phase === 'complete' ? (
|
||||
<div className="border border-base-content/10 bg-base-100 p-8 text-center">
|
||||
<div className="text-lg font-bold text-base-content mb-2">
|
||||
경매 완료
|
||||
</div>
|
||||
<div className="text-xs text-base-content/40">
|
||||
모든 선수가 팀에 배정되었습니다.
|
||||
</div>
|
||||
<Link
|
||||
to={`/match/${id}`}
|
||||
className="btn btn-primary btn-sm mt-4 px-6 text-[11px]"
|
||||
>
|
||||
결과 확인
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<PlayerSpotlight state={auctionState} />
|
||||
|
||||
{auctionState.phase === 'sold' && auctionState.currentBidder && (
|
||||
<div
|
||||
className={`text-center py-3 border text-sm font-bold ${
|
||||
auctionState.currentBidder === 'blue'
|
||||
? 'border-blue-500/20 bg-blue-500/8 text-blue-400'
|
||||
: 'border-red-500/20 bg-red-500/8 text-red-400'
|
||||
}`}
|
||||
>
|
||||
{auctionState.currentBidder === 'blue' ? '블루팀' : '레드팀'} 낙찰
|
||||
{' '}— {formatPoints(auctionState.currentBid)}P
|
||||
</div>
|
||||
)}
|
||||
|
||||
<BidControls
|
||||
state={auctionState}
|
||||
captainSide={captainSide}
|
||||
onBid={(side, amount) => socket.placeBid({ side, amount })}
|
||||
/>
|
||||
<BidLog bids={auctionState.bids} />
|
||||
|
||||
{canManageAuction && (
|
||||
<div className="border border-base-content/10 bg-base-100 p-4 space-y-3">
|
||||
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
|
||||
Auction Controls
|
||||
</div>
|
||||
{auctionState.phase === 'presenting' && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm px-5 text-xs"
|
||||
onClick={() => socket.openBidding()}
|
||||
>
|
||||
입찰 열기
|
||||
</button>
|
||||
)}
|
||||
{auctionState.phase === 'bidding' && (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<select
|
||||
value={assignedPosition}
|
||||
onChange={(event) => setAssignedPosition(event.target.value as Position)}
|
||||
className="border border-base-content/10 bg-transparent px-2 py-2 text-xs"
|
||||
>
|
||||
<option value="TOP">탑</option>
|
||||
<option value="JGL">정글</option>
|
||||
<option value="MID">미드</option>
|
||||
<option value="ADC">원딜</option>
|
||||
<option value="SUP">서폿</option>
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm px-5 text-xs"
|
||||
onClick={() => socket.markSold(assignedPosition)}
|
||||
>
|
||||
낙찰 처리
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{auctionState.phase === 'sold' && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm px-5 text-xs"
|
||||
onClick={() => socket.next()}
|
||||
>
|
||||
다음 선수
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="w-full lg:w-56 shrink-0">
|
||||
<TeamPanel
|
||||
team={auctionState.teams[1]}
|
||||
isActive={auctionState.currentBidder === 'red'}
|
||||
isLeft={false}
|
||||
/>
|
||||
</div>
|
||||
</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,252 @@
|
||||
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';
|
||||
|
||||
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.winnerSide) return '-';
|
||||
return match.winnerSide === 'blue'
|
||||
? `블루 ${match.blueScore}:${match.redScore}`
|
||||
: `레드 ${match.redScore}:${match.blueScore}`;
|
||||
}
|
||||
|
||||
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,355 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { Link, useParams } from 'react-router';
|
||||
import {
|
||||
useBulkUploadTournamentCodes,
|
||||
useDeleteTournamentCode,
|
||||
useMe,
|
||||
useRestoreTournamentCode,
|
||||
useTournamentCodes,
|
||||
useTournamentCodeStats,
|
||||
} from '../../api/hooks';
|
||||
import type {
|
||||
TournamentCodeState,
|
||||
TournamentCodeUploadItem,
|
||||
} from '../../api/types';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../../config';
|
||||
|
||||
const STATES: TournamentCodeState[] = [
|
||||
'available',
|
||||
'reserved',
|
||||
'released',
|
||||
'used',
|
||||
'expired',
|
||||
];
|
||||
|
||||
function formatDate(value: string | undefined) {
|
||||
if (!value) return '-';
|
||||
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 parseCsv(text: string): TournamentCodeUploadItem[] {
|
||||
return text
|
||||
.split(/\r?\n/u)
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean)
|
||||
.map((line) => {
|
||||
const [code, expiresAt, notes] = line.split(',').map((part) => part.trim());
|
||||
return { code, expiresAt, notes };
|
||||
});
|
||||
}
|
||||
|
||||
function parseJson(text: string): TournamentCodeUploadItem[] {
|
||||
const parsed = JSON.parse(text) as unknown;
|
||||
if (Array.isArray(parsed)) return parsed as TournamentCodeUploadItem[];
|
||||
if (
|
||||
typeof parsed === 'object' &&
|
||||
parsed !== null &&
|
||||
'codes' in parsed &&
|
||||
Array.isArray((parsed as { codes: unknown }).codes)
|
||||
) {
|
||||
return (parsed as { codes: TournamentCodeUploadItem[] }).codes;
|
||||
}
|
||||
throw new Error('JSON은 배열 또는 { codes: [...] } 형태여야 합니다.');
|
||||
}
|
||||
|
||||
export default function TournamentCodesPage() {
|
||||
const { cid } = useParams();
|
||||
const communityId = cid ?? DEFAULT_COMMUNITY_ID;
|
||||
const queryClient = useQueryClient();
|
||||
const meQuery = useMe();
|
||||
const [stateFilter, setStateFilter] = useState<TournamentCodeState | ''>('');
|
||||
const [mode, setMode] = useState<'csv' | 'json'>('csv');
|
||||
const [text, setText] = useState('');
|
||||
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 manageableMemberships =
|
||||
meQuery.data?.memberships.filter((membership) => {
|
||||
const role = membership.user.role;
|
||||
return Boolean(
|
||||
membership.community && (role === 'owner' || role === 'admin'),
|
||||
);
|
||||
}) ?? [];
|
||||
const statsQuery = useTournamentCodeStats(communityId, canManage);
|
||||
const listQuery = useTournamentCodes(
|
||||
{ state: stateFilter || undefined, limit: 200 },
|
||||
communityId,
|
||||
canManage,
|
||||
);
|
||||
const uploadMutation = useBulkUploadTournamentCodes(communityId);
|
||||
const restoreMutation = useRestoreTournamentCode(communityId);
|
||||
const deleteMutation = useDeleteTournamentCode(communityId);
|
||||
|
||||
const counts = statsQuery.data?.byState;
|
||||
const codes = useMemo(
|
||||
() => listQuery.data?.codes ?? [],
|
||||
[listQuery.data?.codes],
|
||||
);
|
||||
|
||||
async function invalidate() {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['tournament-code-stats', communityId],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['tournament-codes', communityId],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['matches', communityId],
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
function handleUpload() {
|
||||
setMessage(null);
|
||||
let payload: TournamentCodeUploadItem[];
|
||||
try {
|
||||
payload = mode === 'csv' ? parseCsv(text) : parseJson(text);
|
||||
} catch (error) {
|
||||
setMessage(error instanceof Error ? error.message : '입력 파싱 실패');
|
||||
return;
|
||||
}
|
||||
|
||||
uploadMutation.mutate(payload, {
|
||||
onSuccess: async (result) => {
|
||||
await invalidate();
|
||||
setMessage(
|
||||
`업로드 완료: ${result.inserted}개 추가, 중복 ${result.duplicates.length}개, invalid ${result.invalid.length}개`,
|
||||
);
|
||||
},
|
||||
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>
|
||||
<p className="mt-2 text-sm text-base-content/40">
|
||||
`VITE_DEFAULT_COMMUNITY_ID`를 설정하거나 올바른 커뮤니티 경로로
|
||||
접속해주세요.
|
||||
</p>
|
||||
</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>
|
||||
<p className="mt-2 text-sm text-base-content/40">
|
||||
로그인한 계정의 커뮤니티 권한을 확인하고 있습니다.
|
||||
</p>
|
||||
</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">
|
||||
토너먼트 코드 풀은 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}/tournament-codes`}
|
||||
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">
|
||||
<h1 className="text-2xl font-black text-base-content">
|
||||
토너먼트 코드 풀
|
||||
</h1>
|
||||
<p className="mt-1 text-sm text-base-content/45">
|
||||
외부에서 생성한 코드를 업로드하고, 매치에 자동 할당되는 풀을 관리합니다.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<section className="grid sm:grid-cols-5 gap-3 mb-6">
|
||||
{STATES.map((state) => (
|
||||
<div key={state} className="border border-base-content/10 bg-base-100 p-4">
|
||||
<div className="text-[10px] uppercase tracking-wider text-base-content/30">
|
||||
{state}
|
||||
</div>
|
||||
<div className="mt-2 text-2xl font-black tabular-nums">
|
||||
{counts?.[state] ?? 0}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
|
||||
<section className="border border-base-content/10 bg-base-100 p-4 mb-6">
|
||||
<div className="flex items-center justify-between gap-3 mb-3">
|
||||
<h2 className="text-sm font-bold">Bulk 업로드</h2>
|
||||
<div className="flex gap-1">
|
||||
<button
|
||||
type="button"
|
||||
className={`px-3 py-1 text-xs border ${mode === 'csv' ? 'border-primary/40 text-primary bg-primary/5' : 'border-base-content/10 text-base-content/40'}`}
|
||||
onClick={() => setMode('csv')}
|
||||
>
|
||||
간단 CSV
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`px-3 py-1 text-xs border ${mode === 'json' ? 'border-primary/40 text-primary bg-primary/5' : 'border-base-content/10 text-base-content/40'}`}
|
||||
onClick={() => setMode('json')}
|
||||
>
|
||||
확장 JSON
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<textarea
|
||||
value={text}
|
||||
onChange={(event) => setText(event.target.value)}
|
||||
rows={7}
|
||||
placeholder={
|
||||
mode === 'csv'
|
||||
? 'KR-ABCD-1234,2026-05-30T18:00:00Z,메모'
|
||||
: '[{"code":"KR-ABCD-1234","expiresAt":"2026-05-30T18:00:00Z","source":"external"}]'
|
||||
}
|
||||
className="w-full border border-base-content/10 bg-transparent p-3 text-xs font-mono focus:outline-none focus:border-primary/30"
|
||||
/>
|
||||
<div className="mt-3 flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm px-5 text-xs"
|
||||
disabled={uploadMutation.isPending || !text.trim()}
|
||||
onClick={handleUpload}
|
||||
>
|
||||
{uploadMutation.isPending ? '업로드 중...' : '업로드'}
|
||||
</button>
|
||||
{message && <span className="text-xs text-base-content/45">{message}</span>}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="border border-base-content/10 bg-base-100 overflow-hidden">
|
||||
<div className="px-4 py-3 border-b border-base-content/10 flex items-center justify-between gap-3">
|
||||
<h2 className="text-sm font-bold">코드 목록</h2>
|
||||
<select
|
||||
value={stateFilter}
|
||||
onChange={(event) => setStateFilter(event.target.value as TournamentCodeState | '')}
|
||||
className="border border-base-content/10 bg-transparent px-2 py-1 text-xs"
|
||||
>
|
||||
<option value="">전체</option>
|
||||
{STATES.map((state) => (
|
||||
<option key={state} value={state}>
|
||||
{state}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</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">상태</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>
|
||||
{codes.map((code) => (
|
||||
<tr key={code._id} className="border-b border-base-content/5">
|
||||
<td className="px-3 py-2 font-mono text-xs font-bold">
|
||||
{code.code}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-xs">{code.state}</td>
|
||||
<td className="px-3 py-2 text-xs text-base-content/50">
|
||||
{formatDate(code.expiresAt)}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-xs text-base-content/50">
|
||||
{code.matchId ? (
|
||||
<Link to={`/match/${code.matchId}`} className="text-primary">
|
||||
{code.matchId.slice(-6)} · {code.gameNumber}경기
|
||||
</Link>
|
||||
) : (
|
||||
'-'
|
||||
)}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-xs text-base-content/50">
|
||||
{code.source ?? '-'}
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
<div className="flex justify-end gap-2">
|
||||
{(code.state === 'released' || code.state === 'reserved') && (
|
||||
<button
|
||||
type="button"
|
||||
className="text-[11px] px-2 py-1 border border-base-content/10 text-base-content/50 hover:text-primary"
|
||||
onClick={() =>
|
||||
restoreMutation.mutate(code._id, {
|
||||
onSuccess: invalidate,
|
||||
})
|
||||
}
|
||||
>
|
||||
available 환원
|
||||
</button>
|
||||
)}
|
||||
{code.state === 'available' && (
|
||||
<button
|
||||
type="button"
|
||||
className="text-[11px] px-2 py-1 border border-red-500/20 text-red-400"
|
||||
onClick={() =>
|
||||
deleteMutation.mutate(code._id, {
|
||||
onSuccess: invalidate,
|
||||
})
|
||||
}
|
||||
>
|
||||
폐기
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{codes.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