From c6da2013bd87f62a5d4ca2decd7821180e6682db Mon Sep 17 00:00:00 2001 From: dahyeon Date: Fri, 19 Jun 2026 04:01:22 -0700 Subject: [PATCH] feat: add team page tournament code replacement --- apps/web/src/pages/MatchTeamProgressPage.tsx | 159 ++++++++++++++++++- 1 file changed, 157 insertions(+), 2 deletions(-) diff --git a/apps/web/src/pages/MatchTeamProgressPage.tsx b/apps/web/src/pages/MatchTeamProgressPage.tsx index bbc2211b..f5a17c15 100644 --- a/apps/web/src/pages/MatchTeamProgressPage.tsx +++ b/apps/web/src/pages/MatchTeamProgressPage.tsx @@ -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; parsedTeamIndex: number; + replacingCode?: boolean; slot: TournamentCodeSlotView; teamByIndex: Map; }) { @@ -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({ + {replaceable && ( + + )} ) : ( @@ -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; parsedTeamIndex: number; + replaceError?: string | null; + replacingGameNumber?: number | null; teamByIndex: Map; slots: TournamentCodeSlotView[]; title: string; + onReplaceCode?: (slot: TournamentCodeSlotView) => void; }) { const formatted = formatKoreanDate(match.scheduledAt); const [expandedGameNumber, setExpandedGameNumber] = useState( @@ -409,6 +432,11 @@ function TeamGameCardsSection({
+ {replaceError && ( +
+ {replaceError} +
+ )} {isPreTeamBuilt ? (
팀 빌딩이 끝나면 일정이 표시됩니다. @@ -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(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() { /> ))} + + {replaceCodeSlot && ( +
+
+
+ + + +
+

+ 토너먼트 코드 교체 +

+

+ 정상적인 경기 진행이 불가한 경우 우리팀과 상대팀에 + 상황을 알린 뒤 {replaceCodeSlot.gameNumber}경기 코드를 + 교체하세요. +

+
+
+ + + 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="예" + /> + +
+ + +
+
+
+ )} ); }