feat: improve tournament workflows and prune outdated docs
This commit is contained in:
1 parent
da7b502936
commit
38a89b5374
53 files changed
+3308
-3276
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import type {
|
||||
MatchDetailResponse,
|
||||
MatchGameMode,
|
||||
MatchLifecycleStatus,
|
||||
MatchScheduleItemView,
|
||||
} from '@lolympus/contracts';
|
||||
import { Link, useParams } from 'react-router';
|
||||
@@ -16,7 +17,7 @@ import {
|
||||
import type { MatchMutationRequest } from '../../api/types';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../../config';
|
||||
|
||||
import { Btn } from "../../ui/Btn";
|
||||
import { Btn, Chip, ErrorNote, LoadingNote, Pill, type PillTone } from '../../ui';
|
||||
import { AdminNotice, AdminPage } from '../../components/AdminPage';
|
||||
const DEFAULT_FORM: MatchMutationRequest = {
|
||||
title: '',
|
||||
@@ -38,6 +39,24 @@ const GAME_MODE_LABEL: Record<MatchGameMode, string> = {
|
||||
'double-elimination': '더블 엘리미네이션',
|
||||
};
|
||||
|
||||
const MATCH_STATES = {
|
||||
recruiting: { label: '모집 중', tone: 'live' },
|
||||
'team-built': { label: '팀빌딩 완료', tone: 'gold' },
|
||||
'in-progress': { label: '진행 중', tone: 'accent' },
|
||||
finished: { label: '종료', tone: 'neutral' },
|
||||
} satisfies Record<MatchLifecycleStatus, { label: string; tone: PillTone }>;
|
||||
|
||||
const matchStatusFilters = Object.keys(MATCH_STATES) as MatchLifecycleStatus[];
|
||||
|
||||
function matchModeDetail(match: MatchDetailResponse) {
|
||||
if (match.gameMode === 'round-robin' && match.roundRobinMaxRounds) {
|
||||
return `최대 ${match.roundRobinMaxRounds}라운드`;
|
||||
}
|
||||
if (match.gameMode === 'double-elimination') {
|
||||
return match.doubleEliminationResetFinalEnabled ? '결승 리셋 허용' : '결승 리셋 없음';
|
||||
}
|
||||
}
|
||||
|
||||
function resolveRoundRobinFullRoundCount(maxParticipants?: number) {
|
||||
const teamCount = Math.floor(Number(maxParticipants ?? 10) / 5);
|
||||
if (teamCount < 2) return 0;
|
||||
@@ -147,7 +166,8 @@ export default function MatchAdminPage() {
|
||||
const communityId = cid ?? DEFAULT_COMMUNITY_ID;
|
||||
const queryClient = useQueryClient();
|
||||
const meQuery = useMe();
|
||||
const matchesQuery = useMatches({ limit: 200 }, communityId);
|
||||
const [statusFilter, setStatusFilter] = useState<MatchLifecycleStatus>();
|
||||
const matchesQuery = useMatches({ limit: 200, status: statusFilter }, communityId);
|
||||
const createMutation = useCreateMatch(communityId);
|
||||
const updateMutation = useUpdateMatch(communityId);
|
||||
const deleteMutation = useDeleteMatch(communityId);
|
||||
@@ -155,6 +175,11 @@ export default function MatchAdminPage() {
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [form, setForm] = useState(makeForm());
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
const formHeading = useRef<HTMLHeadingElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (showForm) formHeading.current?.focus();
|
||||
}, [showForm, editing]);
|
||||
|
||||
const currentUser =
|
||||
meQuery.data?.memberships.find(
|
||||
@@ -246,7 +271,34 @@ export default function MatchAdminPage() {
|
||||
createMutation.mutate(payload, callbacks);
|
||||
}
|
||||
|
||||
if (!canManage && !meQuery.isPending) {
|
||||
function matchActions(match: MatchDetailResponse) {
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Btn onClick={() => openEdit(match)} variant="secondary">수정</Btn>
|
||||
{match.status === 'recruiting' && (
|
||||
<Btn
|
||||
variant="destructive"
|
||||
disabled={deleteMutation.isPending}
|
||||
onClick={() => {
|
||||
if (!window.confirm('이 내전을 삭제할까요?')) return;
|
||||
deleteMutation.mutate(match._id, {
|
||||
onSuccess: invalidate,
|
||||
onError: (error) => setMessage(error instanceof Error ? error.message : '삭제 실패'),
|
||||
});
|
||||
}}
|
||||
>
|
||||
삭제
|
||||
</Btn>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (meQuery.isLoading) {
|
||||
return <AdminNotice title="권한 확인 중" />;
|
||||
}
|
||||
|
||||
if (!canManage) {
|
||||
return (
|
||||
<AdminNotice title="권한이 필요합니다">
|
||||
<p className="mt-2 text-sm text-base-content/40">
|
||||
@@ -262,8 +314,16 @@ export default function MatchAdminPage() {
|
||||
title="내전 관리"
|
||||
description="내전 생성, 모집 정원, 게임 모드와 공지 내용을 관리합니다."
|
||||
>
|
||||
<div className="mb-4 flex flex-wrap items-center justify-end gap-2">
|
||||
<Btn variant="primary" onClick={openCreate}>
|
||||
<div className="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex flex-wrap gap-2" role="group" aria-label="내전 상태 필터">
|
||||
<Chip selected={!statusFilter} onClick={() => setStatusFilter(undefined)}>전체</Chip>
|
||||
{matchStatusFilters.map((status) => (
|
||||
<Chip key={status} selected={statusFilter === status} onClick={() => setStatusFilter(status)}>
|
||||
{MATCH_STATES[status].label}
|
||||
</Chip>
|
||||
))}
|
||||
</div>
|
||||
<Btn variant="primary" onClick={openCreate}>
|
||||
새 내전 만들기
|
||||
</Btn>
|
||||
</div>
|
||||
@@ -277,7 +337,7 @@ export default function MatchAdminPage() {
|
||||
{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">
|
||||
<h2 ref={formHeading} tabIndex={-1} className="scroll-mt-28 text-sm font-bold">
|
||||
{editing ? '내전 수정' : '새 내전'}
|
||||
</h2>
|
||||
<button
|
||||
@@ -484,9 +544,42 @@ export default function MatchAdminPage() {
|
||||
</section>
|
||||
)}
|
||||
|
||||
<section className="lts-panel overflow-hidden">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="lts-table min-w-[900px]">
|
||||
{matchesQuery.isLoading ? (
|
||||
<LoadingNote label="내전 목록을 불러오는 중" />
|
||||
) : matchesQuery.isError ? (
|
||||
<ErrorNote title="내전 목록을 불러오지 못했습니다" action={<Btn onClick={() => void matchesQuery.refetch()}>다시 시도</Btn>} />
|
||||
) : matches.length === 0 ? (
|
||||
<p role="status" className="lts-panel p-6 text-center text-sm text-content-muted">
|
||||
{statusFilter ? '이 상태의 내전이 없습니다.' : '등록된 내전이 없습니다.'}
|
||||
</p>
|
||||
) : (
|
||||
<section className="lts-panel overflow-hidden" aria-label="내전 목록">
|
||||
<ul className="divide-y divide-line lg:hidden">
|
||||
{matches.map((match) => (
|
||||
<li key={match._id} className="space-y-2 px-4 py-3">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<Link to={`/match/${match._id}`} className="min-w-0 break-words text-sm font-bold hover:text-primary">
|
||||
{match.title}
|
||||
</Link>
|
||||
<Pill tone={MATCH_STATES[match.status].tone}>{MATCH_STATES[match.status].label}</Pill>
|
||||
</div>
|
||||
<p className="text-xs text-content-muted">
|
||||
{formatDate(match.scheduledAt)} · {match.participants.length}/{match.maxParticipants}명
|
||||
</p>
|
||||
<details className="text-sm">
|
||||
<summary className="cursor-pointer py-2 font-semibold">상세·관리</summary>
|
||||
<p className="mb-2 text-xs text-content-muted">
|
||||
{GAME_MODE_LABEL[match.gameMode ?? 'pair']}
|
||||
{matchModeDetail(match) && ` · ${matchModeDetail(match)}`}
|
||||
</p>
|
||||
{match.description && <p className="mb-3 break-words text-sm text-content-muted">{match.description}</p>}
|
||||
{matchActions(match)}
|
||||
</details>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<div className="hidden overflow-x-auto lg:block">
|
||||
<table className="lts-table">
|
||||
<thead>
|
||||
<tr className="bg-base-200/40 border-b border-base-content/10 text-xs uppercase tracking-wider text-base-content/35">
|
||||
<th className="px-3 py-2">시간</th>
|
||||
@@ -511,74 +604,24 @@ export default function MatchAdminPage() {
|
||||
{match.description || '-'}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-3 py-2 text-xs">{match.status}</td>
|
||||
<td className="px-3 py-2 text-xs"><Pill tone={MATCH_STATES[match.status].tone}>{MATCH_STATES[match.status].label}</Pill></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']}
|
||||
{match.gameMode === 'round-robin' &&
|
||||
match.roundRobinMaxRounds && (
|
||||
<span className="block text-xs text-base-content/30">
|
||||
최대 {match.roundRobinMaxRounds}R
|
||||
</span>
|
||||
)}
|
||||
{match.gameMode === 'double-elimination' && (
|
||||
<span className="block text-xs text-base-content/30">
|
||||
GF 리셋{' '}
|
||||
{match.doubleEliminationResetFinalEnabled
|
||||
? '허용'
|
||||
: '없음'}
|
||||
</span>
|
||||
)}
|
||||
<span className="block text-xs text-content-muted">{matchModeDetail(match)}</span>
|
||||
</td>
|
||||
<td className="px-3 py-2 text-right">
|
||||
<div className="inline-flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="text-xs 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-xs px-2 py-1 border border-loss-line text-loss hover:bg-loss-tint"
|
||||
disabled={
|
||||
deleteMutation.isPending ||
|
||||
match.status !== 'recruiting'
|
||||
}
|
||||
title={
|
||||
match.status === 'recruiting'
|
||||
? '내전 삭제'
|
||||
: '팀 구성이 확정된 내전 기록은 삭제할 수 없습니다.'
|
||||
}
|
||||
onClick={() => {
|
||||
if (!window.confirm('이 내전을 삭제할까요?')) return;
|
||||
deleteMutation.mutate(match._id, {
|
||||
onSuccess: invalidate,
|
||||
onError: (error) =>
|
||||
setMessage(error instanceof Error ? error.message : '삭제 실패'),
|
||||
});
|
||||
}}
|
||||
>
|
||||
삭제
|
||||
</button>
|
||||
</div>
|
||||
<div className="inline-block">{matchActions(match)}</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>
|
||||
)}
|
||||
</AdminPage>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user