feat(auction): cancel active auction
This commit is contained in:
1 parent
8a9dd37755
commit
ef693fcf4a
5 files changed
+182
-2
No files matched your search
@@ -164,6 +164,7 @@ export class AuctionController {
|
|||||||
) {
|
) {
|
||||||
this.assertSameCommunity(currentUser, communityId);
|
this.assertSameCommunity(currentUser, communityId);
|
||||||
await this.auctionService.reset({ matchId, communityId });
|
await this.auctionService.reset({ matchId, communityId });
|
||||||
|
this.auctionGateway.broadcastReset(matchId.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private resolveBidder(
|
private resolveBidder(
|
||||||
|
|||||||
@@ -364,6 +364,11 @@ export class AuctionGateway
|
|||||||
this.syncRoomTimer(matchId, auction);
|
this.syncRoomTimer(matchId, auction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public broadcastReset(matchId: string) {
|
||||||
|
this.clearRoomTimer(matchId);
|
||||||
|
this.server.to(matchId).emit('reset', { matchId });
|
||||||
|
}
|
||||||
|
|
||||||
private emitChatHistory(socket: Socket, auction: AuctionDocument) {
|
private emitChatHistory(socket: Socket, auction: AuctionDocument) {
|
||||||
socket.emit('chat-history', {
|
socket.emit('chat-history', {
|
||||||
messages: (auction.chatMessages ?? []).map((message) =>
|
messages: (auction.chatMessages ?? []).map((message) =>
|
||||||
|
|||||||
@@ -171,6 +171,15 @@ export function useUndoAuction(communityId = DEFAULT_COMMUNITY_ID) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useResetAuction(communityId = DEFAULT_COMMUNITY_ID) {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ matchId }: { matchId: string }) =>
|
||||||
|
apiFetch<void>(`/communities/${communityId}/matches/${matchId}/auction`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function useCreateMatch(communityId = DEFAULT_COMMUNITY_ID) {
|
export function useCreateMatch(communityId = DEFAULT_COMMUNITY_ID) {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (body: MatchMutationRequest) =>
|
mutationFn: (body: MatchMutationRequest) =>
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ interface ChatHistoryPayload {
|
|||||||
messages?: ApiAuctionChatMessage[];
|
messages?: ApiAuctionChatMessage[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ResetPayload {
|
||||||
|
matchId?: string;
|
||||||
|
}
|
||||||
|
|
||||||
const MAX_CHAT_MESSAGES = 200;
|
const MAX_CHAT_MESSAGES = 200;
|
||||||
|
|
||||||
function mergeChatMessages(
|
function mergeChatMessages(
|
||||||
@@ -47,6 +51,7 @@ export function useAuctionSocket(matchId: string | undefined) {
|
|||||||
const socketRef = useRef<Socket | null>(null);
|
const socketRef = useRef<Socket | null>(null);
|
||||||
const [auction, setAuction] = useState<ApiAuction | null>(null);
|
const [auction, setAuction] = useState<ApiAuction | null>(null);
|
||||||
const [chatMessages, setChatMessages] = useState<ApiAuctionChatMessage[]>([]);
|
const [chatMessages, setChatMessages] = useState<ApiAuctionChatMessage[]>([]);
|
||||||
|
const [resetAt, setResetAt] = useState<number | null>(null);
|
||||||
const [connectionStatus, setConnectionStatus] =
|
const [connectionStatus, setConnectionStatus] =
|
||||||
useState<ConnectionStatus>('idle');
|
useState<ConnectionStatus>('idle');
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
@@ -103,6 +108,14 @@ export function useAuctionSocket(matchId: string | undefined) {
|
|||||||
setChatMessages((current) => mergeChatMessages(current, [message]));
|
setChatMessages((current) => mergeChatMessages(current, [message]));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('reset', (payload: ResetPayload) => {
|
||||||
|
if (payload.matchId && payload.matchId !== matchId) return;
|
||||||
|
setAuction(null);
|
||||||
|
setChatMessages([]);
|
||||||
|
setResetAt(Date.now());
|
||||||
|
setError('경매가 취소되었습니다.');
|
||||||
|
});
|
||||||
|
|
||||||
socket.on('error', (payload: { message?: string }) => {
|
socket.on('error', (payload: { message?: string }) => {
|
||||||
setConnectionStatus('error');
|
setConnectionStatus('error');
|
||||||
setError(payload.message ?? '실시간 경매 연결 중 오류가 발생했습니다.');
|
setError(payload.message ?? '실시간 경매 연결 중 오류가 발생했습니다.');
|
||||||
@@ -144,6 +157,7 @@ export function useAuctionSocket(matchId: string | undefined) {
|
|||||||
return {
|
return {
|
||||||
auction: visibleAuction,
|
auction: visibleAuction,
|
||||||
chatMessages: visibleAuction ? chatMessages : [],
|
chatMessages: visibleAuction ? chatMessages : [],
|
||||||
|
resetAt,
|
||||||
connectionStatus: visibleConnectionStatus,
|
connectionStatus: visibleConnectionStatus,
|
||||||
error,
|
error,
|
||||||
placeBid(payload: BidPayload) {
|
placeBid(payload: BidPayload) {
|
||||||
|
|||||||
@@ -7,14 +7,15 @@ import {
|
|||||||
type KeyboardEvent,
|
type KeyboardEvent,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import { SendHorizontal } from 'lucide-react';
|
import { AlertTriangle, SendHorizontal } from 'lucide-react';
|
||||||
import { Link, useLocation, useParams } from 'react-router';
|
import { Link, useLocation, useNavigate, useParams } from 'react-router';
|
||||||
import {
|
import {
|
||||||
useAuction,
|
useAuction,
|
||||||
useAuctionHistory,
|
useAuctionHistory,
|
||||||
useDdragonManifest,
|
useDdragonManifest,
|
||||||
useMatch,
|
useMatch,
|
||||||
useMe,
|
useMe,
|
||||||
|
useResetAuction,
|
||||||
useUndoAuction,
|
useUndoAuction,
|
||||||
} from '../api/hooks';
|
} from '../api/hooks';
|
||||||
import {
|
import {
|
||||||
@@ -728,6 +729,7 @@ function BidLog({ bids }: { bids: AuctionStateView['bids'] }) {
|
|||||||
export default function AuctionPage() {
|
export default function AuctionPage() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
const navigate = useNavigate();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const meQuery = useMe();
|
const meQuery = useMe();
|
||||||
const currentUser =
|
const currentUser =
|
||||||
@@ -747,17 +749,42 @@ export default function AuctionPage() {
|
|||||||
refetchInterval: 3000,
|
refetchInterval: 3000,
|
||||||
});
|
});
|
||||||
const undoMutation = useUndoAuction(DEFAULT_COMMUNITY_ID);
|
const undoMutation = useUndoAuction(DEFAULT_COMMUNITY_ID);
|
||||||
|
const resetAuctionMutation = useResetAuction(DEFAULT_COMMUNITY_ID);
|
||||||
const socket = useAuctionSocket(id);
|
const socket = useAuctionSocket(id);
|
||||||
const captainTeamIndex = useDevCaptainTeamIndex();
|
const captainTeamIndex = useDevCaptainTeamIndex();
|
||||||
const [now, setNow] = useState(() => Date.now());
|
const [now, setNow] = useState(() => Date.now());
|
||||||
const [assignedPosition, setAssignedPosition] = useState<Position>('MID');
|
const [assignedPosition, setAssignedPosition] = useState<Position>('MID');
|
||||||
|
const [showCancelModal, setShowCancelModal] = useState(false);
|
||||||
|
const [cancelConfirmText, setCancelConfirmText] = useState('');
|
||||||
|
const cancelConfirmInputRef = useRef<HTMLInputElement>(null);
|
||||||
const historyBackTo = `${location.pathname}${location.search}${location.hash}`;
|
const historyBackTo = `${location.pathname}${location.search}${location.hash}`;
|
||||||
|
const canConfirmAuctionCancel = cancelConfirmText.trim() === '예';
|
||||||
|
|
||||||
|
async function invalidateAuctionData() {
|
||||||
|
if (!id) return;
|
||||||
|
await Promise.all([
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ['auction', DEFAULT_COMMUNITY_ID, id],
|
||||||
|
}),
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ['auction-history', DEFAULT_COMMUNITY_ID, id],
|
||||||
|
}),
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ['match', DEFAULT_COMMUNITY_ID, id],
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = window.setInterval(() => setNow(Date.now()), 1000);
|
const timer = window.setInterval(() => setNow(Date.now()), 1000);
|
||||||
return () => window.clearInterval(timer);
|
return () => window.clearInterval(timer);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!showCancelModal) return;
|
||||||
|
cancelConfirmInputRef.current?.focus();
|
||||||
|
}, [showCancelModal]);
|
||||||
|
|
||||||
const liveAuction = pickLatestAuction(socket.auction, auctionQuery.data);
|
const liveAuction = pickLatestAuction(socket.auction, auctionQuery.data);
|
||||||
const auctionState =
|
const auctionState =
|
||||||
liveAuction && matchQuery.data
|
liveAuction && matchQuery.data
|
||||||
@@ -788,6 +815,13 @@ export default function AuctionPage() {
|
|||||||
}
|
}
|
||||||
}, [availableTeamIndexes, captainTeamIndex]);
|
}, [availableTeamIndexes, captainTeamIndex]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!socket.resetAt || !id) return;
|
||||||
|
void invalidateAuctionData().finally(() => {
|
||||||
|
navigate(`/match/${id}`, { replace: true });
|
||||||
|
});
|
||||||
|
}, [id, navigate, socket.resetAt]);
|
||||||
|
|
||||||
if (!DEFAULT_COMMUNITY_ID) {
|
if (!DEFAULT_COMMUNITY_ID) {
|
||||||
return (
|
return (
|
||||||
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
<main className="max-w-5xl mx-auto px-4 py-20 text-center">
|
||||||
@@ -862,6 +896,21 @@ export default function AuctionPage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleResetAuction() {
|
||||||
|
if (!id || !canConfirmAuctionCancel) return;
|
||||||
|
resetAuctionMutation.mutate(
|
||||||
|
{ matchId: id },
|
||||||
|
{
|
||||||
|
onSuccess: async () => {
|
||||||
|
setShowCancelModal(false);
|
||||||
|
setCancelConfirmText('');
|
||||||
|
await invalidateAuctionData();
|
||||||
|
navigate(`/match/${id}`, { replace: true });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const undoPanel = canManageAuction ? (
|
const undoPanel = canManageAuction ? (
|
||||||
<div className="border border-base-content/10 bg-base-100 p-4 space-y-3">
|
<div className="border border-base-content/10 bg-base-100 p-4 space-y-3">
|
||||||
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
|
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
|
||||||
@@ -930,6 +979,12 @@ export default function AuctionPage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{resetAuctionMutation.error instanceof Error && (
|
||||||
|
<div className="mb-4 border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-500">
|
||||||
|
{resetAuctionMutation.error.message}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="mb-5 flex items-start justify-between flex-wrap gap-3">
|
<div className="mb-5 flex items-start justify-between flex-wrap gap-3">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-xl font-bold text-base-content leading-tight">
|
<h1 className="text-xl font-bold text-base-content leading-tight">
|
||||||
@@ -1101,6 +1156,23 @@ export default function AuctionPage() {
|
|||||||
다음 선수
|
다음 선수
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
<div className="border-t border-base-content/10 pt-3">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-outline btn-error btn-sm inline-flex items-center gap-1.5 px-4 text-xs"
|
||||||
|
onClick={() => {
|
||||||
|
setCancelConfirmText('');
|
||||||
|
setShowCancelModal(true);
|
||||||
|
}}
|
||||||
|
disabled={resetAuctionMutation.isPending}
|
||||||
|
>
|
||||||
|
<AlertTriangle className="h-3.5 w-3.5" />
|
||||||
|
경매 진행 취소
|
||||||
|
</button>
|
||||||
|
<p className="mt-2 text-[11px] leading-relaxed text-base-content/35">
|
||||||
|
경매 데이터와 진행 기록을 삭제하고 내전을 모집 상태로 되돌립니다.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{undoPanel}
|
{undoPanel}
|
||||||
@@ -1138,6 +1210,85 @@ export default function AuctionPage() {
|
|||||||
className="h-[420px]"
|
className="h-[420px]"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{showCancelModal && (
|
||||||
|
<div
|
||||||
|
className="fixed inset-0 z-50 flex items-center justify-center bg-black/55 px-4"
|
||||||
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
aria-labelledby="auction-cancel-title"
|
||||||
|
>
|
||||||
|
<div className="w-full max-w-md border border-red-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-red-500/25 bg-red-500/10 text-red-400">
|
||||||
|
<AlertTriangle className="h-4 w-4" />
|
||||||
|
</span>
|
||||||
|
<div className="min-w-0">
|
||||||
|
<h2
|
||||||
|
id="auction-cancel-title"
|
||||||
|
className="text-base font-bold text-base-content"
|
||||||
|
>
|
||||||
|
경매 진행 취소
|
||||||
|
</h2>
|
||||||
|
<p className="mt-2 text-sm leading-6 text-base-content/60">
|
||||||
|
정말 경매를 취소하고 모집 상태로 되돌리시겠습니까?
|
||||||
|
경매 데이터, 입찰 기록, 팀 배정 정보가 삭제됩니다.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label
|
||||||
|
htmlFor="auction-cancel-confirm"
|
||||||
|
className="mt-5 block text-[11px] font-bold uppercase tracking-wider text-base-content/40"
|
||||||
|
>
|
||||||
|
계속하려면 예 입력
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="auction-cancel-confirm"
|
||||||
|
ref={cancelConfirmInputRef}
|
||||||
|
value={cancelConfirmText}
|
||||||
|
onChange={(event) => setCancelConfirmText(event.target.value)}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === 'Escape') {
|
||||||
|
setShowCancelModal(false);
|
||||||
|
setCancelConfirmText('');
|
||||||
|
}
|
||||||
|
if (event.key === 'Enter' && canConfirmAuctionCancel) {
|
||||||
|
handleResetAuction();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
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-red-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={() => {
|
||||||
|
setShowCancelModal(false);
|
||||||
|
setCancelConfirmText('');
|
||||||
|
}}
|
||||||
|
disabled={resetAuctionMutation.isPending}
|
||||||
|
>
|
||||||
|
닫기
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-error btn-sm px-4 text-xs"
|
||||||
|
onClick={handleResetAuction}
|
||||||
|
disabled={
|
||||||
|
!canConfirmAuctionCancel || resetAuctionMutation.isPending
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{resetAuctionMutation.isPending
|
||||||
|
? '취소 처리 중...'
|
||||||
|
: '경매 취소 진행'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user