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
@@ -18,6 +18,7 @@ import {
|
||||
MetaDot,
|
||||
PageBody,
|
||||
PageHero,
|
||||
Panel,
|
||||
Pill,
|
||||
PlainPage,
|
||||
type PillTone,
|
||||
@@ -991,13 +992,80 @@ function AdminAddParticipantModal({
|
||||
);
|
||||
}
|
||||
|
||||
function MatchRegistration({
|
||||
match,
|
||||
canJoin,
|
||||
checkingAccount,
|
||||
initialPosition,
|
||||
joining,
|
||||
error,
|
||||
onJoin,
|
||||
}: {
|
||||
match: MatchDetailView;
|
||||
canJoin: boolean;
|
||||
checkingAccount: boolean;
|
||||
initialPosition: Position;
|
||||
joining: boolean;
|
||||
error: Error | null;
|
||||
onJoin: (position: Position) => void;
|
||||
}) {
|
||||
const [selectedPosition, setSelectedPosition] = useState<Position>();
|
||||
const position = selectedPosition ?? initialPosition;
|
||||
const count = match.participants.length;
|
||||
const remaining = Math.max(0, match.maxParticipants - count);
|
||||
const progress = match.maxParticipants > 0 ? Math.min(100, count / match.maxParticipants * 100) : 0;
|
||||
|
||||
return (
|
||||
<Panel className="mb-5 px-4 py-4 sm:px-5" aria-labelledby="match-registration-title">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h2 id="match-registration-title" className="text-base font-bold">참가 신청</h2>
|
||||
<Pill tone={match.joined ? "live" : remaining > 0 ? "neutral" : "gold"}>
|
||||
{count}/{match.maxParticipants}명
|
||||
</Pill>
|
||||
</div>
|
||||
<p className="mt-2 font-semibold" role="status">
|
||||
{match.joined ? "참가 신청 완료" : remaining > 0 ? `${remaining}자리 남음` : "정원이 찼습니다"}
|
||||
</p>
|
||||
<div className="mt-2 h-2 overflow-hidden rounded-full bg-sunken-strong" aria-hidden="true">
|
||||
<div className="h-full rounded-full bg-brand-coral" style={{ width: `${progress}%` }} />
|
||||
</div>
|
||||
{!match.joined && remaining > 0 && (
|
||||
checkingAccount ? (
|
||||
<p className="mt-4 text-sm text-content-muted">참가 권한을 확인하고 있습니다.</p>
|
||||
) : canJoin ? (
|
||||
<form className="mt-4 flex flex-wrap items-end justify-between gap-4" onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
if (!joining) onJoin(position);
|
||||
}}>
|
||||
<fieldset disabled={joining}>
|
||||
<legend className="mb-2 text-sm font-semibold">1순위 희망 포지션</legend>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{POSITION_ORDER.map((role) => (
|
||||
<label key={role} className="cursor-pointer">
|
||||
<input type="radio" name="preferred-position" value={role} checked={role === position} onChange={() => setSelectedPosition(role)} className="peer sr-only" />
|
||||
<span className="inline-flex min-h-9 items-center rounded-full border border-line-strong px-3 text-sm peer-checked:border-transparent peer-checked:bg-secondary peer-checked:text-secondary-content peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2">
|
||||
{positionLabel[role]}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
<Btn type="submit" variant="primary" size="lg" disabled={joining}>
|
||||
{joining ? "신청 중…" : "참가 신청"}
|
||||
</Btn>
|
||||
</form>
|
||||
) : (
|
||||
<div className="mt-4"><Btn to={`/login?next=${encodeURIComponent(`/match/${match.id}`)}`} variant="primary">로그인하고 참가하기</Btn></div>
|
||||
)
|
||||
)}
|
||||
{error && <ErrorNote className="mt-4" title="참가 신청을 완료하지 못했습니다" description={error.message} />}
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
|
||||
function ParticipantTable({
|
||||
participants,
|
||||
maxParticipants,
|
||||
joined,
|
||||
canJoin,
|
||||
onJoin,
|
||||
isJoining,
|
||||
canManage,
|
||||
onOpenAddParticipant,
|
||||
onRemoveParticipant,
|
||||
@@ -1007,10 +1075,6 @@ function ParticipantTable({
|
||||
}: {
|
||||
participants: ParticipantView[];
|
||||
maxParticipants: number;
|
||||
joined: boolean;
|
||||
canJoin: boolean;
|
||||
onJoin: () => void;
|
||||
isJoining: boolean;
|
||||
canManage: boolean;
|
||||
onOpenAddParticipant: () => void;
|
||||
onRemoveParticipant: (userId: string) => void;
|
||||
@@ -1078,13 +1142,6 @@ function ParticipantTable({
|
||||
참가자 ({participants.length}/{maxParticipants})
|
||||
</h3>
|
||||
<div className="flex flex-wrap items-center justify-end gap-2">
|
||||
<Btn
|
||||
onClick={onJoin}
|
||||
disabled={!canJoin || joined || isJoining}
|
||||
variant="primary" size="sm"
|
||||
>
|
||||
{joined ? "참가 완료" : isJoining ? "신청 중..." : "참가 신청"}
|
||||
</Btn>
|
||||
{canManage && (
|
||||
<Btn
|
||||
onClick={onOpenAddParticipant}
|
||||
@@ -1271,13 +1328,6 @@ function ParticipantTable({
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{participants.length < maxParticipants && (
|
||||
<div className="px-4 py-2.5 border-t border-base-content/5 text-center bg-base-200/20">
|
||||
<span className="text-xs text-base-content/25">
|
||||
{maxParticipants - participants.length}자리 남음
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1451,19 +1501,27 @@ export default function MatchDetailPage() {
|
||||
const collectResultByRiotMatchMutation =
|
||||
useCollectTournamentResultByRiotMatch(DEFAULT_COMMUNITY_ID);
|
||||
|
||||
const preferredPositions = currentUser?.preferredPositions.length
|
||||
? [...currentUser.preferredPositions].sort((left, right) => left.priority - right.priority)
|
||||
: buildDefaultPreferredPositions();
|
||||
const matchQueryKey = matchQuery.queryKey;
|
||||
|
||||
const joinMatchMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
apiFetch(
|
||||
mutationFn: (position: Position) => {
|
||||
const positions = [position, ...preferredPositions.map((entry) => entry.position)];
|
||||
return apiFetch<MatchDetailResponse>(
|
||||
`/communities/${DEFAULT_COMMUNITY_ID}/matches/${id}/participants`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
preferredPositions: currentUser?.preferredPositions.length
|
||||
? currentUser.preferredPositions.slice(0, 5)
|
||||
: buildDefaultPreferredPositions(),
|
||||
preferredPositions: [...new Set(positions)].slice(0, 5).map((entry, index) => ({
|
||||
position: entry,
|
||||
priority: index + 1,
|
||||
})),
|
||||
}),
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({
|
||||
@@ -1474,10 +1532,11 @@ export default function MatchDetailPage() {
|
||||
}),
|
||||
]);
|
||||
},
|
||||
onError: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: ["match", DEFAULT_COMMUNITY_ID, id ?? null] });
|
||||
},
|
||||
});
|
||||
|
||||
const matchQueryKey = matchQuery.queryKey;
|
||||
|
||||
const addParticipantMutation = useMutation({
|
||||
mutationFn: ({
|
||||
userId,
|
||||
@@ -1791,6 +1850,8 @@ export default function MatchDetailPage() {
|
||||
auctionQuery.error instanceof ApiError && auctionQuery.error.status === 404;
|
||||
const activeAuction = auctionNotStarted ? null : auctionQuery.data;
|
||||
const showAuctionLink = Boolean(activeAuction);
|
||||
const hasTeamProgress = Boolean(competitionQuery.data?.teams.length) &&
|
||||
(match.status === "in-progress" || match.status === "finished");
|
||||
const auctionParticipantPool = buildAuctionParticipantPool(
|
||||
matchQuery.data.participants,
|
||||
);
|
||||
@@ -1929,16 +1990,27 @@ export default function MatchDetailPage() {
|
||||
}
|
||||
description={match.description || undefined}
|
||||
actions={
|
||||
showAuctionLink ? (
|
||||
<Btn to={`/match/${match.id}/auction`} variant="primary" size="lg">
|
||||
경매 보기
|
||||
hasTeamProgress ? (
|
||||
<Btn to={`/match/${match.id}/team`} variant="primary" size="lg">
|
||||
팀 경기 현황
|
||||
</Btn>
|
||||
) : showAuctionLink && match.status !== "recruiting" ? (
|
||||
<Btn to={`/match/${match.id}/auction`} variant="primary" size="lg">경매 보기</Btn>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
<PageBody>
|
||||
{joinMatchMutation.error instanceof Error && (
|
||||
<ErrorNote className="mb-4" title="요청을 처리하지 못했습니다" description={joinMatchMutation.error.message} />
|
||||
<PageBody className={!usesTabbedLayout && match.status !== "recruiting" ? "pt-12" : undefined}>
|
||||
{match.status === "recruiting" && (
|
||||
<MatchRegistration
|
||||
key={match.id}
|
||||
match={match}
|
||||
canJoin={canUseMemberActions}
|
||||
checkingAccount={isCheckingPermissions && !canUseMemberActions}
|
||||
initialPosition={preferredPositions[0]?.position ?? "TOP"}
|
||||
joining={joinMatchMutation.isPending}
|
||||
error={joinMatchMutation.error}
|
||||
onJoin={joinMatchMutation.mutate}
|
||||
/>
|
||||
)}
|
||||
|
||||
{startAuctionMutation.error instanceof Error && (
|
||||
@@ -2044,6 +2116,7 @@ export default function MatchDetailPage() {
|
||||
{showCompetitionResults && (
|
||||
<CompetitionResults
|
||||
competition={competitionQuery.data}
|
||||
showTeamLink={!hasTeamProgress}
|
||||
view={
|
||||
usesTabbedLayout
|
||||
? activeMatchTab === "games"
|
||||
@@ -2097,10 +2170,6 @@ export default function MatchDetailPage() {
|
||||
<ParticipantTable
|
||||
participants={match.participants}
|
||||
maxParticipants={match.maxParticipants}
|
||||
joined={match.joined}
|
||||
canJoin={canUseMemberActions}
|
||||
onJoin={() => joinMatchMutation.mutate()}
|
||||
isJoining={joinMatchMutation.isPending}
|
||||
canManage={canManageAuction}
|
||||
onOpenAddParticipant={() => setAddParticipantOpen(true)}
|
||||
onRemoveParticipant={(userId) =>
|
||||
@@ -2480,13 +2549,13 @@ export default function MatchDetailPage() {
|
||||
{match.teams.map((team) => (
|
||||
<TeamCard key={team.teamIndex} team={team} />
|
||||
))}
|
||||
{showAuctionLink && (
|
||||
{showAuctionLink && hasTeamProgress && (
|
||||
<div className="flex justify-end">
|
||||
<Btn
|
||||
to={`/match/${match.id}/auction`}
|
||||
variant="primary"
|
||||
variant="secondary"
|
||||
>
|
||||
경매 페이지 열기
|
||||
경매 기록 보기
|
||||
</Btn>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user