feat: add team page tournament code replacement

This commit is contained in:
dahyeon committed 2026-06-19 04:01:22 -07:00
1 parent b9881fcb6f
commit c6da2013bd
1 file changed
+157 -2
+157 -2
View File
@@ -1,9 +1,11 @@
import { useState } from "react";
import { ChevronDown, ChevronUp } from "lucide-react";
import { useQueryClient } from "@tanstack/react-query";
import { AlertTriangle, ChevronDown, ChevronUp } from "lucide-react";
import { Link, useLocation, useParams } from "react-router";
import {
useDdragonManifest,
useMatch,
useReplaceTournamentCode,
useUserHistoryProfile,
} from "../api/hooks";
import { formatKoreanDate } from "../api/mappers";
@@ -167,8 +169,10 @@ function UpcomingGameCard({
game,
isNext,
onToggle,
onReplaceCode,
participantByUserId,
parsedTeamIndex,
replacingCode,
slot,
teamByIndex,
}: {
@@ -176,8 +180,10 @@ function UpcomingGameCard({
game?: ApiMatchGameResult;
isNext?: boolean;
onToggle: () => void;
onReplaceCode?: (slot: TournamentCodeSlotView) => void;
participantByUserId: Map<string, ApiMatchParticipant>;
parsedTeamIndex: number;
replacingCode?: boolean;
slot: TournamentCodeSlotView;
teamByIndex: Map<number, ApiMatch["teams"][number]>;
}) {
@@ -195,6 +201,7 @@ function UpcomingGameCard({
const won = finished && game?.winnerTeamIndex === parsedTeamIndex;
const ourSide: TeamSide =
slot.teamAIndex === parsedTeamIndex ? "blue" : "red";
const replaceable = Boolean(slot.code && !finished && slot.state !== "used");
async function handleCopy() {
if (!slot.code) return;
@@ -306,11 +313,21 @@ function UpcomingGameCard({
</code>
<button
type="button"
className="border border-base-content/10 px-2 py-1 text-xs font-bold text-base-content/45 hover:text-primary"
className="whitespace-nowrap border border-base-content/10 px-2 py-1 text-xs font-bold text-base-content/45 hover:text-primary"
onClick={handleCopy}
>
{copied ? "복사됨" : "복사"}
</button>
{replaceable && (
<button
type="button"
className="whitespace-nowrap border border-base-content/10 px-2 py-1 text-xs font-bold text-base-content/45 hover:text-primary disabled:cursor-not-allowed disabled:opacity-45"
disabled={replacingCode}
onClick={() => onReplaceCode?.(slot)}
>
{replacingCode ? "교체 중" : "교체"}
</button>
)}
</>
) : (
<span className="text-xs font-semibold text-base-content/30">
@@ -371,9 +388,12 @@ function TeamGameCardsSection({
match,
participantByUserId,
parsedTeamIndex,
replaceError,
replacingGameNumber,
teamByIndex,
slots,
title,
onReplaceCode,
}: {
defaultExpandedGameNumber?: number | null;
emptyMessage: string;
@@ -382,9 +402,12 @@ function TeamGameCardsSection({
match: ApiMatch;
participantByUserId: Map<string, ApiMatchParticipant>;
parsedTeamIndex: number;
replaceError?: string | null;
replacingGameNumber?: number | null;
teamByIndex: Map<number, ApiMatch["teams"][number]>;
slots: TournamentCodeSlotView[];
title: string;
onReplaceCode?: (slot: TournamentCodeSlotView) => void;
}) {
const formatted = formatKoreanDate(match.scheduledAt);
const [expandedGameNumber, setExpandedGameNumber] = useState<number | null>(
@@ -409,6 +432,11 @@ function TeamGameCardsSection({
</div>
<div className="p-4">
{replaceError && (
<div className="mb-3 border border-red-500/20 bg-red-500/8 px-3 py-2 text-xs text-red-300">
{replaceError}
</div>
)}
{isPreTeamBuilt ? (
<div className="border border-dashed border-base-content/10 px-4 py-8 text-center text-xs text-base-content/35">
팀 빌딩이 끝나면 일정이 표시됩니다.
@@ -430,8 +458,10 @@ function TeamGameCardsSection({
current === slot.gameNumber ? null : slot.gameNumber,
)
}
onReplaceCode={onReplaceCode}
participantByUserId={participantByUserId}
parsedTeamIndex={parsedTeamIndex}
replacingCode={replacingGameNumber === slot.gameNumber}
slot={slot}
teamByIndex={teamByIndex}
/>
@@ -463,7 +493,41 @@ function buildFinishedSlot(
export default function MatchTeamProgressPage() {
const { id, teamIndex } = useParams();
const parsedTeamIndex = Number(teamIndex);
const queryClient = useQueryClient();
const matchQuery = useMatch(id, DEFAULT_COMMUNITY_ID);
const replaceTournamentCodeMutation =
useReplaceTournamentCode(DEFAULT_COMMUNITY_ID);
const [replaceCodeSlot, setReplaceCodeSlot] =
useState<TournamentCodeSlotView | null>(null);
const [replaceCodeConfirmText, setReplaceCodeConfirmText] = useState("");
function handleReplaceTournamentCode(slot: TournamentCodeSlotView) {
if (!slot.code) return;
setReplaceCodeConfirmText("");
setReplaceCodeSlot(slot);
}
function closeReplaceTournamentCodeDialog() {
setReplaceCodeSlot(null);
setReplaceCodeConfirmText("");
}
function handleConfirmReplaceTournamentCode() {
if (!id || !replaceCodeSlot || replaceCodeConfirmText.trim() !== "예") {
return;
}
replaceTournamentCodeMutation.mutate(
{ matchId: id, gameNumber: replaceCodeSlot.gameNumber },
{
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: ["match", DEFAULT_COMMUNITY_ID, id ?? null],
});
closeReplaceTournamentCodeDialog();
},
},
);
}
if (!DEFAULT_COMMUNITY_ID) {
return (
@@ -577,8 +641,19 @@ export default function MatchTeamProgressPage() {
gameByNumber={gameByNumber}
isPreTeamBuilt={isPreTeamBuilt}
match={match}
onReplaceCode={handleReplaceTournamentCode}
participantByUserId={participantByUserId}
parsedTeamIndex={parsedTeamIndex}
replaceError={
replaceTournamentCodeMutation.error instanceof Error
? replaceTournamentCodeMutation.error.message
: null
}
replacingGameNumber={
replaceTournamentCodeMutation.isPending
? replaceTournamentCodeMutation.variables?.gameNumber ?? null
: null
}
teamByIndex={teamByIndex}
slots={activeSlots}
title="다가오는 경기"
@@ -618,6 +693,86 @@ export default function MatchTeamProgressPage() {
/>
))}
</section>
{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="team-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="team-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="team-tournament-code-replace-confirm"
className="mt-5 block text-xs font-bold uppercase tracking-wider text-base-content/40"
>
계속하려면 예 입력
</label>
<input
id="team-tournament-code-replace-confirm"
value={replaceCodeConfirmText}
onChange={(event) => setReplaceCodeConfirmText(event.target.value)}
onKeyDown={(event) => {
if (event.key === "Escape") {
closeReplaceTournamentCodeDialog();
}
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={closeReplaceTournamentCodeDialog}
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>
);
}