.
This commit is contained in:
1 parent
7a43a667f1
commit
c00545f281
21 files changed
+1920
-5
No files matched your search
@@ -10,6 +10,7 @@ import LoginPage from './pages/Login';
|
||||
import MatchDetailPage from './pages/MatchDetailPage';
|
||||
import AuctionPage from './pages/AuctionPage';
|
||||
import UserHistoryPage from './pages/UserHistoryPage';
|
||||
import TournamentCodesPage from './pages/admin/TournamentCodesPage';
|
||||
|
||||
function MsalHeaderActions() {
|
||||
const { accounts, instance } = useMsal();
|
||||
@@ -71,6 +72,10 @@ function App() {
|
||||
<Route path="/match/:id" element={<MatchDetailPage />} />
|
||||
<Route path="/match/:id/auction" element={<AuctionPage />} />
|
||||
<Route path="/users/:userId/history" element={<UserHistoryPage />} />
|
||||
<Route
|
||||
path="/admin/communities/:cid/tournament-codes"
|
||||
element={<TournamentCodesPage />}
|
||||
/>
|
||||
</Routes>
|
||||
<DevAuthSwitcher />
|
||||
</div>
|
||||
|
||||
@@ -16,6 +16,7 @@ import type {
|
||||
ApiMatch,
|
||||
ApiRecentMatchesResponse,
|
||||
ApiRecentSummaryResponse,
|
||||
ApiTournamentCode,
|
||||
ApiUserHistoryProfile,
|
||||
DdragonManifest,
|
||||
MatchStatus,
|
||||
@@ -23,6 +24,11 @@ import type {
|
||||
MeResponse,
|
||||
RiotQueueGroup,
|
||||
RiotRankFilter,
|
||||
TournamentCodeBulkUploadResponse,
|
||||
TournamentCodeListResponse,
|
||||
TournamentCodeState,
|
||||
TournamentCodeStatsResponse,
|
||||
TournamentCodeUploadItem,
|
||||
} from './types';
|
||||
|
||||
const DDRAGON_MANIFEST_STALE_MS = 24 * 60 * 60 * 1000;
|
||||
@@ -253,6 +259,79 @@ export function useDdragonManifest(locale = 'ko_KR') {
|
||||
});
|
||||
}
|
||||
|
||||
export function useTournamentCodeStats(
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
enabled = true,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ['tournament-code-stats', communityId],
|
||||
queryFn: () =>
|
||||
apiFetch<TournamentCodeStatsResponse>(
|
||||
`/communities/${communityId}/tournament-codes/stats`,
|
||||
),
|
||||
enabled: Boolean(communityId && enabled),
|
||||
refetchInterval: enabled ? 30_000 : false,
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTournamentCodes(
|
||||
options: { state?: TournamentCodeState; limit?: number },
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: [
|
||||
'tournament-codes',
|
||||
communityId,
|
||||
options.state ?? null,
|
||||
options.limit ?? null,
|
||||
],
|
||||
queryFn: () => {
|
||||
const searchParams = new URLSearchParams();
|
||||
if (options.state) searchParams.set('state', options.state);
|
||||
if (options.limit) searchParams.set('limit', String(options.limit));
|
||||
const queryString = searchParams.toString();
|
||||
return apiFetch<TournamentCodeListResponse>(
|
||||
`/communities/${communityId}/tournament-codes${queryString ? `?${queryString}` : ''}`,
|
||||
);
|
||||
},
|
||||
enabled: Boolean(communityId),
|
||||
refetchInterval: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useBulkUploadTournamentCodes(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useMutation({
|
||||
mutationFn: (codes: TournamentCodeUploadItem[]) =>
|
||||
apiFetch<TournamentCodeBulkUploadResponse>(
|
||||
`/communities/${communityId}/tournament-codes`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ codes }),
|
||||
},
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useRestoreTournamentCode(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useMutation({
|
||||
mutationFn: (codeId: string) =>
|
||||
apiFetch<ApiTournamentCode>(
|
||||
`/communities/${communityId}/tournament-codes/${codeId}/release`,
|
||||
{ method: 'POST' },
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteTournamentCode(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useMutation({
|
||||
mutationFn: (codeId: string) =>
|
||||
apiFetch<void>(`/communities/${communityId}/tournament-codes/${codeId}`, {
|
||||
method: 'DELETE',
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export function useMe() {
|
||||
const authUserId = useAuthUserId();
|
||||
const { accounts, inProgress, instance } = useMsal();
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
Position,
|
||||
RiotLane,
|
||||
TeamSide,
|
||||
TournamentCodeSlotView,
|
||||
} from "./types";
|
||||
import { POSITION_ORDER, sideLabel } from "../lib/league";
|
||||
|
||||
@@ -46,6 +47,8 @@ export interface MatchDetailView {
|
||||
description: string;
|
||||
map: string;
|
||||
maxParticipants: number;
|
||||
gameCount: number;
|
||||
tournamentCodes: TournamentCodeSlotView[];
|
||||
joined: boolean;
|
||||
participants: ParticipantView[];
|
||||
teams: TeamView[];
|
||||
@@ -402,6 +405,8 @@ export function mapApiMatchToMatchDetail(match: ApiMatch): MatchDetailView {
|
||||
description: match.description,
|
||||
map: mapIdToLabel(match.mapId),
|
||||
maxParticipants: match.maxParticipants,
|
||||
gameCount: match.gameCount ?? 3,
|
||||
tournamentCodes: match.tournamentCodes ?? [],
|
||||
joined: Boolean(match.joined),
|
||||
participants,
|
||||
teams,
|
||||
|
||||
@@ -100,10 +100,28 @@ export interface ApiCommunity {
|
||||
name: string;
|
||||
description: string;
|
||||
ownerUserId: string;
|
||||
matchGameCount?: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export type TournamentCodeState =
|
||||
| 'available'
|
||||
| 'reserved'
|
||||
| 'used'
|
||||
| 'expired'
|
||||
| 'released';
|
||||
|
||||
export type TournamentCodeSlotState = TournamentCodeState | 'pending';
|
||||
|
||||
export interface TournamentCodeSlotView {
|
||||
gameNumber: number;
|
||||
code: string | null;
|
||||
expiresAt: string | null;
|
||||
state: TournamentCodeSlotState;
|
||||
riotMatchId: string | null;
|
||||
}
|
||||
|
||||
export interface ApiMatchParticipant {
|
||||
userId: string;
|
||||
puuid?: string;
|
||||
@@ -150,6 +168,8 @@ export interface ApiMatch {
|
||||
status: MatchStatus;
|
||||
scheduledAt: string;
|
||||
maxParticipants: number;
|
||||
gameCount: number;
|
||||
tournamentCodes?: TournamentCodeSlotView[];
|
||||
hostUserId?: string;
|
||||
participants: ApiMatchParticipant[];
|
||||
teams: ApiMatchTeam[];
|
||||
@@ -248,6 +268,57 @@ export interface DdragonManifest {
|
||||
fetchedAt: string;
|
||||
}
|
||||
|
||||
export type TournamentSpectatorType = 'NONE' | 'LOBBYONLY' | 'ALL';
|
||||
|
||||
export interface ApiTournamentCode {
|
||||
_id: string;
|
||||
code: string;
|
||||
region: string;
|
||||
mapType: 'SUMMONERS_RIFT';
|
||||
teamSize: number;
|
||||
spectatorType: TournamentSpectatorType;
|
||||
metadata?: Record<string, unknown>;
|
||||
expiresAt: string;
|
||||
state: TournamentCodeState;
|
||||
matchId?: string;
|
||||
gameNumber?: number;
|
||||
reservedAt?: string;
|
||||
usedAt?: string;
|
||||
releasedAt?: string;
|
||||
riotMatchId?: string;
|
||||
uploadedBy: string;
|
||||
uploadedAt: string;
|
||||
source?: string;
|
||||
notes?: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface TournamentCodeStatsResponse {
|
||||
byState: Record<TournamentCodeState, number>;
|
||||
expiringSoon: number;
|
||||
available: number;
|
||||
}
|
||||
|
||||
export interface TournamentCodeListResponse {
|
||||
codes: ApiTournamentCode[];
|
||||
}
|
||||
|
||||
export interface TournamentCodeUploadItem {
|
||||
code: string;
|
||||
expiresAt: string;
|
||||
spectatorType?: TournamentSpectatorType;
|
||||
metadata?: Record<string, unknown>;
|
||||
source?: string;
|
||||
notes?: string;
|
||||
}
|
||||
|
||||
export interface TournamentCodeBulkUploadResponse {
|
||||
inserted: number;
|
||||
duplicates: string[];
|
||||
invalid: Array<{ code: string; reason: string }>;
|
||||
}
|
||||
|
||||
export type RiotQueueGroup =
|
||||
| 'all'
|
||||
| 'summoners-rift'
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { Link, useNavigate, useParams } from 'react-router';
|
||||
import { useAuction, useDdragonManifest, useMatch, useMe } from '../api/hooks';
|
||||
import {
|
||||
useAuction,
|
||||
useDdragonManifest,
|
||||
useMatch,
|
||||
useMe,
|
||||
useTournamentCodeStats,
|
||||
} from '../api/hooks';
|
||||
import {
|
||||
buildDefaultPreferredPositions,
|
||||
formatTierLabel,
|
||||
@@ -15,7 +21,7 @@ import { DEFAULT_COMMUNITY_ID, useAuthUserId } from '../config';
|
||||
import { apiFetch, ApiError } from '../lib/api';
|
||||
import { profileIconUrl } from '../lib/ddragon';
|
||||
import { positionIcon, positionLabel } from '../lib/league';
|
||||
import type { Position } from '../api/types';
|
||||
import type { Position, TournamentCodeSlotView } from '../api/types';
|
||||
|
||||
function PosBadge({ pos, sub }: { pos: Position; sub?: boolean }) {
|
||||
return (
|
||||
@@ -279,6 +285,117 @@ function SideCard({
|
||||
);
|
||||
}
|
||||
|
||||
function formatTournamentCodeExpiry(value: string | null) {
|
||||
if (!value) return null;
|
||||
return new Intl.DateTimeFormat('ko-KR', {
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(new Date(value));
|
||||
}
|
||||
|
||||
function isExpiringSoon(value: string | null) {
|
||||
if (!value) return false;
|
||||
const expiresAt = new Date(value).getTime();
|
||||
return expiresAt - Date.now() <= 24 * 60 * 60 * 1000;
|
||||
}
|
||||
|
||||
function TournamentCodeDisplay({ slot }: { slot: TournamentCodeSlotView }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const expired = slot.state === 'expired';
|
||||
const used = slot.state === 'used';
|
||||
const expiringSoon = isExpiringSoon(slot.expiresAt);
|
||||
|
||||
async function copyCode() {
|
||||
if (!slot.code) return;
|
||||
await navigator.clipboard.writeText(slot.code);
|
||||
setCopied(true);
|
||||
window.setTimeout(() => setCopied(false), 1600);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex-1 min-w-0">
|
||||
<div
|
||||
className={`flex items-center gap-2 border px-2 py-1.5 ${
|
||||
expired
|
||||
? 'border-red-500/20 bg-red-500/8 text-red-400'
|
||||
: used
|
||||
? 'border-base-content/8 bg-base-content/5 text-base-content/35'
|
||||
: 'border-primary/20 bg-primary/5 text-base-content'
|
||||
}`}
|
||||
>
|
||||
<code className="font-mono text-[12px] font-bold truncate">
|
||||
{expired ? '코드 만료' : slot.code}
|
||||
</code>
|
||||
{slot.code && !expired && (
|
||||
<button
|
||||
type="button"
|
||||
className="ml-auto text-[10px] px-1.5 py-0.5 border border-base-content/10 text-base-content/45 hover:text-primary"
|
||||
onClick={copyCode}
|
||||
>
|
||||
{copied ? '복사됨' : '복사'}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className={`mt-1 text-[10px] ${
|
||||
expired || expiringSoon ? 'text-amber-500' : 'text-base-content/30'
|
||||
}`}
|
||||
>
|
||||
{used
|
||||
? '사용됨'
|
||||
: expired
|
||||
? '운영자에게 새 코드를 요청해주세요.'
|
||||
: `만료: ${formatTournamentCodeExpiry(slot.expiresAt)}`}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TournamentCodeList({ slots }: { slots: TournamentCodeSlotView[] }) {
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{slots.map((slot) => (
|
||||
<div key={slot.gameNumber} className="flex items-start gap-2">
|
||||
<span className="text-[11px] font-bold text-base-content/40 w-11 shrink-0 pt-1.5">
|
||||
{slot.gameNumber}경기
|
||||
</span>
|
||||
{slot.code ? (
|
||||
<TournamentCodeDisplay slot={slot} />
|
||||
) : (
|
||||
<span className="text-[11px] text-base-content/30 border border-dashed border-base-content/10 px-2 py-2 flex-1">
|
||||
발급 대기 중... 운영자가 코드를 채우면 자동으로 붙습니다.
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PoolStatsHint({ enabled }: { enabled: boolean }) {
|
||||
const statsQuery = useTournamentCodeStats(DEFAULT_COMMUNITY_ID, enabled);
|
||||
if (!enabled) return null;
|
||||
const available = statsQuery.data?.available ?? 0;
|
||||
const expiringSoon = statsQuery.data?.expiringSoon ?? 0;
|
||||
|
||||
return (
|
||||
<div className="mt-3 border-t border-base-content/8 pt-3 text-[11px]">
|
||||
<div className={available < 5 ? 'text-red-400' : 'text-base-content/35'}>
|
||||
풀 잔여 {available}개
|
||||
{expiringSoon > 0 ? ` · 만료 임박 ${expiringSoon}개` : ''}
|
||||
</div>
|
||||
<Link
|
||||
to={`/admin/communities/${DEFAULT_COMMUNITY_ID}/tournament-codes`}
|
||||
className="mt-1 inline-flex text-primary hover:underline"
|
||||
>
|
||||
코드 풀 관리
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function MatchDetailPage() {
|
||||
const { id } = useParams();
|
||||
const navigate = useNavigate();
|
||||
@@ -623,6 +740,13 @@ export default function MatchDetailPage() {
|
||||
</SideCard>
|
||||
)}
|
||||
|
||||
{(match.status === 'team-built' || match.status === 'in-progress') && (
|
||||
<SideCard title="토너먼트 코드">
|
||||
<TournamentCodeList slots={match.tournamentCodes} />
|
||||
<PoolStatsHint enabled={canManageAuction} />
|
||||
</SideCard>
|
||||
)}
|
||||
|
||||
{match.prizes.length > 0 && (
|
||||
<SideCard title="상품">
|
||||
<ul className="space-y-1.5">
|
||||
|
||||
@@ -0,0 +1,311 @@
|
||||
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 statsQuery = useTournamentCodeStats(communityId, canManage);
|
||||
const listQuery = useTournamentCodes(
|
||||
{ state: stateFilter || undefined, limit: 200 },
|
||||
communityId,
|
||||
);
|
||||
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 (!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>
|
||||
</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