feat: allow tournament code replacement

This commit is contained in:
dahyeon committed 2026-06-19 03:43:53 -07:00
1 parent 1272c81fa9
commit 303886ed53
5 files changed
+537 -37

No files matched your search

+11
View File
@@ -41,6 +41,7 @@ import type {
RebuildLegacyMatchesResponse,
TournamentCodeBulkUploadResponse,
TournamentCodeListResponse,
TournamentCodeSlotView,
TournamentCodeState,
TournamentCodeStatsResponse,
TournamentCodeUploadItem,
@@ -632,6 +633,16 @@ export function useDeleteTournamentCode(communityId = DEFAULT_COMMUNITY_ID) {
});
}
export function useReplaceTournamentCode(communityId = DEFAULT_COMMUNITY_ID) {
return useMutation({
mutationFn: (params: { matchId: string; gameNumber: number }) =>
apiFetch<TournamentCodeSlotView>(
`/communities/${communityId}/tournament-codes/matches/${params.matchId}/games/${params.gameNumber}/replace`,
{ method: 'POST' },
),
});
}
export function usePollTournamentResult(communityId = DEFAULT_COMMUNITY_ID) {
return useMutation({
mutationFn: (matchId: string) =>
+212 -37
View File
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { Search, X } from "lucide-react";
import { AlertTriangle, Search, X } from "lucide-react";
import { Link, useLocation, useNavigate, useParams } from "react-router";
import {
useAuction,
@@ -11,6 +11,7 @@ import {
useMatch,
useMe,
usePollTournamentResult,
useReplaceTournamentCode,
useTournamentCodeStats,
useUserHistoryProfile,
} from "../api/hooks";
@@ -1393,12 +1394,11 @@ 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));
const date = new Date(value);
if (Number.isNaN(date.getTime())) return null;
return `${date.getMonth() + 1}/${date.getDate()} ${String(
date.getHours(),
).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
}
function isExpiringSoon(value: string | null) {
@@ -1407,11 +1407,23 @@ function isExpiringSoon(value: string | null) {
return expiresAt - Date.now() <= 24 * 60 * 60 * 1000;
}
function TournamentCodeDisplay({ slot }: { slot: TournamentCodeSlotView }) {
function TournamentCodeDisplay({
slot,
canReplace,
replacing,
onReplace,
}: {
slot: TournamentCodeSlotView;
canReplace?: boolean;
replacing?: boolean;
onReplace?: (slot: TournamentCodeSlotView) => void;
}) {
const [copied, setCopied] = useState(false);
const expired = slot.state === "expired";
const used = slot.state === "used";
const expiringSoon = isExpiringSoon(slot.expiresAt);
const replaceable = Boolean(canReplace && slot.code && !used);
const expiryText = formatTournamentCodeExpiry(slot.expiresAt);
async function copyCode() {
if (!slot.code) return;
@@ -1421,9 +1433,9 @@ function TournamentCodeDisplay({ slot }: { slot: TournamentCodeSlotView }) {
}
return (
<div className="flex-1 min-w-0">
<div className="min-w-0 space-y-1.5">
<div
className={`flex items-center gap-2 border px-2 py-1.5 ${
className={`border px-2 py-2 ${
expired
? "border-red-500/20 bg-red-500/8 text-red-400"
: used
@@ -1431,29 +1443,45 @@ function TournamentCodeDisplay({ slot }: { slot: TournamentCodeSlotView }) {
: "border-primary/20 bg-primary/5 text-base-content"
}`}
>
<code className="font-mono text-xs font-bold truncate">
<code className="block min-w-0 truncate font-mono text-[11px] font-bold leading-4">
{expired ? "코드 만료" : slot.code}
</code>
{slot.code && !expired && (
<button
type="button"
className="ml-auto text-xs 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-xs ${
expired || expiringSoon ? "text-amber-500" : "text-base-content/30"
}`}
>
{used
? "사용됨"
: expired
? "운영자에게 새 코드를 요청해주세요."
: `만료: ${formatTournamentCodeExpiry(slot.expiresAt)}`}
<div className="flex items-center justify-between gap-2">
<div
className={`min-w-0 truncate text-xs ${
expired || expiringSoon ? "text-amber-500" : "text-base-content/30"
}`}
>
{used
? "사용됨"
: expired
? "운영자에게 새 코드를 요청해주세요."
: expiryText
? `만료 ${expiryText}`
: "만료 정보 없음"}
</div>
<div className="flex shrink-0 items-center gap-1">
{slot.code && !expired && (
<button
type="button"
className="whitespace-nowrap border border-base-content/10 px-1.5 py-0.5 text-xs text-base-content/45 hover:text-primary"
onClick={copyCode}
>
{copied ? "복사됨" : "복사"}
</button>
)}
{replaceable && (
<button
type="button"
className="whitespace-nowrap border border-base-content/10 px-1.5 py-0.5 text-xs text-base-content/45 hover:text-primary disabled:cursor-not-allowed disabled:opacity-45"
disabled={replacing}
onClick={() => onReplace?.(slot)}
>
{replacing ? "교체 중" : "교체"}
</button>
)}
</div>
</div>
</div>
);
@@ -1462,9 +1490,15 @@ function TournamentCodeDisplay({ slot }: { slot: TournamentCodeSlotView }) {
function TournamentCodeList({
slots,
gameMode,
canReplace,
replacingGameNumber,
onReplace,
}: {
slots: TournamentCodeSlotView[];
gameMode: MatchGameMode;
canReplace?: boolean;
replacingGameNumber?: number | null;
onReplace?: (slot: TournamentCodeSlotView) => void;
}) {
if (slots.length === 0) {
return (
@@ -1479,20 +1513,30 @@ function TournamentCodeList({
gameMode === "round-robin" || slot.teamAIndex > 1 || slot.teamBIndex > 2;
return (
<div key={slot.gameNumber} className="flex items-start gap-2">
<span className="text-xs font-bold text-base-content/40 w-20 shrink-0 pt-1.5">
{slot.gameNumber}경기
<div
key={slot.gameNumber}
className="border-b border-base-content/8 pb-2 last:border-b-0 last:pb-0"
>
<div className="mb-1.5 flex items-center justify-between gap-2">
<span className="shrink-0 text-xs font-bold text-base-content/45">
{slot.gameNumber}경기
</span>
{shouldShowTeamLabel && (
<span className="block text-xs font-normal text-base-content/25">
<span className="min-w-0 truncate text-xs text-base-content/30">
{teamIndexLabel(slot.teamAIndex)} vs{" "}
{teamIndexLabel(slot.teamBIndex)}
</span>
)}
</span>
</div>
{slot.code ? (
<TournamentCodeDisplay slot={slot} />
<TournamentCodeDisplay
slot={slot}
canReplace={canReplace}
replacing={replacingGameNumber === slot.gameNumber}
onReplace={onReplace}
/>
) : (
<span className="text-xs text-base-content/30 border border-dashed border-base-content/10 px-2 py-2 flex-1">
<span className="block border border-dashed border-base-content/10 px-2 py-2 text-xs text-base-content/30">
발급 대기 중... 운영자가 코드를 채우면 자동으로 붙습니다.
</span>
)}
@@ -1986,8 +2030,13 @@ export default function MatchDetailPage() {
const [manualResultEndTime, setManualResultEndTime] = useState("");
const [manualRiotMatchId, setManualRiotMatchId] = useState("");
const [addParticipantOpen, setAddParticipantOpen] = useState(false);
const [replaceCodeSlot, setReplaceCodeSlot] =
useState<TournamentCodeSlotView | null>(null);
const [replaceCodeConfirmText, setReplaceCodeConfirmText] = useState("");
const pollTournamentResultMutation =
usePollTournamentResult(DEFAULT_COMMUNITY_ID);
const replaceTournamentCodeMutation =
useReplaceTournamentCode(DEFAULT_COMMUNITY_ID);
const collectResultByWindowMutation =
useCollectTournamentResultByWindow(DEFAULT_COMMUNITY_ID);
const collectResultByRiotMatchMutation =
@@ -2177,6 +2226,36 @@ export default function MatchDetailPage() {
});
}
function handleReplaceTournamentCode(slot: TournamentCodeSlotView) {
if (!slot.code) return;
setReplaceCodeConfirmText("");
setReplaceCodeSlot(slot);
}
function handleConfirmReplaceTournamentCode() {
if (!id || !replaceCodeSlot || replaceCodeConfirmText.trim() !== "예") {
return;
}
replaceTournamentCodeMutation.mutate(
{ matchId: id, gameNumber: replaceCodeSlot.gameNumber },
{
onSuccess: async () => {
await Promise.all([
invalidateCurrentMatch(),
queryClient.invalidateQueries({
queryKey: ["tournament-code-stats", DEFAULT_COMMUNITY_ID],
}),
queryClient.invalidateQueries({
queryKey: ["tournament-codes", DEFAULT_COMMUNITY_ID],
}),
]);
setReplaceCodeSlot(null);
setReplaceCodeConfirmText("");
},
},
);
}
async function invalidateCurrentMatch() {
await queryClient.invalidateQueries({
queryKey: ["match", DEFAULT_COMMUNITY_ID, id ?? null],
@@ -2839,7 +2918,19 @@ export default function MatchDetailPage() {
<TournamentCodeList
slots={match.tournamentCodes}
gameMode={match.gameMode}
canReplace={canManageAuction}
replacingGameNumber={
replaceTournamentCodeMutation.isPending
? replaceTournamentCodeMutation.variables?.gameNumber ?? null
: null
}
onReplace={handleReplaceTournamentCode}
/>
{replaceTournamentCodeMutation.error instanceof Error && (
<div className="mt-3 border border-red-500/20 bg-red-500/8 px-3 py-2 text-xs text-red-300">
{replaceTournamentCodeMutation.error.message}
</div>
)}
<PoolStatsHint enabled={canManageAuction} />
</SideCard>
)}
@@ -2995,6 +3086,90 @@ export default function MatchDetailPage() {
)}
</div>
</div>
{replaceCodeSlot && (
<div
className="fixed inset-0 z-50 flex items-center justify-center bg-black/55 px-4"
role="dialog"
aria-modal="true"
aria-labelledby="tournament-code-replace-title"
>
<div className="w-full max-w-md border border-amber-500/25 bg-base-100 p-5 shadow-2xl">
<div className="flex items-start gap-3">
<span className="inline-flex h-9 w-9 shrink-0 items-center justify-center border border-amber-500/25 bg-amber-500/10 text-amber-400">
<AlertTriangle className="h-4 w-4" />
</span>
<div className="min-w-0">
<h2
id="tournament-code-replace-title"
className="text-base font-bold text-base-content"
>
토너먼트 코드 교체
</h2>
<p className="mt-2 text-sm leading-6 text-base-content/60">
정상적인 경기 진행이 불가한 경우 우리팀과 상대팀에
상황을 알린 뒤 {replaceCodeSlot.gameNumber}경기 코드를
교체하세요.
</p>
</div>
</div>
<label
htmlFor="tournament-code-replace-confirm"
className="mt-5 block text-xs font-bold uppercase tracking-wider text-base-content/40"
>
계속하려면 예 입력
</label>
<input
id="tournament-code-replace-confirm"
value={replaceCodeConfirmText}
onChange={(event) => setReplaceCodeConfirmText(event.target.value)}
onKeyDown={(event) => {
if (event.key === "Escape") {
setReplaceCodeSlot(null);
setReplaceCodeConfirmText("");
}
if (
event.key === "Enter" &&
replaceCodeConfirmText.trim() === "예" &&
!replaceTournamentCodeMutation.isPending
) {
handleConfirmReplaceTournamentCode();
}
}}
className="mt-2 h-10 w-full border border-base-content/15 bg-base-100 px-3 text-sm text-base-content outline-none transition-colors focus:border-amber-400/60"
placeholder="예"
/>
<div className="mt-5 flex flex-wrap justify-end gap-2">
<button
type="button"
className="btn btn-ghost btn-sm px-4 text-xs"
onClick={() => {
setReplaceCodeSlot(null);
setReplaceCodeConfirmText("");
}}
disabled={replaceTournamentCodeMutation.isPending}
>
닫기
</button>
<button
type="button"
className="btn btn-warning btn-sm px-4 text-xs"
onClick={handleConfirmReplaceTournamentCode}
disabled={
replaceCodeConfirmText.trim() !== "예" ||
replaceTournamentCodeMutation.isPending
}
>
{replaceTournamentCodeMutation.isPending
? "교체 중..."
: "코드 교체 진행"}
</button>
</div>
</div>
</div>
)}
</main>
);
}