feat(admin): manage match participants
This commit is contained in:
1 parent
994a9fcad0
commit
6a192276e8
4 files changed
+437
-1
No files matched your search
@@ -173,6 +173,14 @@ export class UpdateMatchDto {
|
|||||||
schedule?: MatchScheduleItemDto[];
|
schedule?: MatchScheduleItemDto[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class UpdateParticipantDto {
|
||||||
|
@IsEnum(POSITIONS)
|
||||||
|
mainPosition!: Position;
|
||||||
|
|
||||||
|
@IsEnum(POSITIONS)
|
||||||
|
subPosition!: Position;
|
||||||
|
}
|
||||||
|
|
||||||
export class JoinMatchDto {
|
export class JoinMatchDto {
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ArrayMinSize(1)
|
@ArrayMinSize(1)
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import {
|
|||||||
CreateMatchDto,
|
CreateMatchDto,
|
||||||
JoinMatchDto,
|
JoinMatchDto,
|
||||||
UpdateMatchDto,
|
UpdateMatchDto,
|
||||||
|
UpdateParticipantDto,
|
||||||
} from './dto/create-match.dto';
|
} from './dto/create-match.dto';
|
||||||
import { MatchService } from './match.service';
|
import { MatchService } from './match.service';
|
||||||
|
|
||||||
@@ -137,6 +138,49 @@ export class MatchController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 관리자 전용 — 참가자 주/부 포지션 변경.
|
||||||
|
@Patch(':matchId/participants/:userId')
|
||||||
|
@Roles('admin', 'owner')
|
||||||
|
@UseGuards(RolesGuard)
|
||||||
|
public async updateParticipant(
|
||||||
|
@CurrentUser() currentUser: UserDocument,
|
||||||
|
@Param('communityId', ParseObjectIdPipe)
|
||||||
|
communityId: mongoose.Types.ObjectId,
|
||||||
|
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||||
|
@Param('userId', ParseObjectIdPipe) userId: mongoose.Types.ObjectId,
|
||||||
|
@Body() body: UpdateParticipantDto,
|
||||||
|
) {
|
||||||
|
this.assertSameCommunity(currentUser, communityId);
|
||||||
|
const match = await this.matchService.updateParticipantPositions({
|
||||||
|
matchId,
|
||||||
|
communityId,
|
||||||
|
targetUserId: userId,
|
||||||
|
mainPosition: body.mainPosition,
|
||||||
|
subPosition: body.subPosition,
|
||||||
|
});
|
||||||
|
return this.matchService.serialize(match);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 관리자 전용 — 참가자 강제 제외.
|
||||||
|
@Delete(':matchId/participants/:userId')
|
||||||
|
@Roles('admin', 'owner')
|
||||||
|
@UseGuards(RolesGuard)
|
||||||
|
@HttpCode(HttpStatus.NO_CONTENT)
|
||||||
|
public async removeParticipant(
|
||||||
|
@CurrentUser() currentUser: UserDocument,
|
||||||
|
@Param('communityId', ParseObjectIdPipe)
|
||||||
|
communityId: mongoose.Types.ObjectId,
|
||||||
|
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||||
|
@Param('userId', ParseObjectIdPipe) userId: mongoose.Types.ObjectId,
|
||||||
|
) {
|
||||||
|
this.assertSameCommunity(currentUser, communityId);
|
||||||
|
await this.matchService.removeParticipant({
|
||||||
|
matchId,
|
||||||
|
communityId,
|
||||||
|
targetUserId: userId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private resolveJoinerUserId(
|
private resolveJoinerUserId(
|
||||||
currentUser: UserDocument | undefined,
|
currentUser: UserDocument | undefined,
|
||||||
bodyUserId?: string,
|
bodyUserId?: string,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
MatchDocument,
|
MatchDocument,
|
||||||
MatchSeriesResult,
|
MatchSeriesResult,
|
||||||
MatchStatus,
|
MatchStatus,
|
||||||
|
Position,
|
||||||
PositionPreference,
|
PositionPreference,
|
||||||
TierInfo,
|
TierInfo,
|
||||||
} from '../global/database/schema';
|
} from '../global/database/schema';
|
||||||
@@ -54,6 +55,20 @@ interface CancelMatchJoinParams {
|
|||||||
userId: mongoose.Types.ObjectId;
|
userId: mongoose.Types.ObjectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface RemoveParticipantParams {
|
||||||
|
matchId: mongoose.Types.ObjectId;
|
||||||
|
communityId: mongoose.Types.ObjectId;
|
||||||
|
targetUserId: mongoose.Types.ObjectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UpdateParticipantPositionsParams {
|
||||||
|
matchId: mongoose.Types.ObjectId;
|
||||||
|
communityId: mongoose.Types.ObjectId;
|
||||||
|
targetUserId: mongoose.Types.ObjectId;
|
||||||
|
mainPosition: Position;
|
||||||
|
subPosition: Position;
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MatchService {
|
export class MatchService {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -276,6 +291,86 @@ export class MatchService {
|
|||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 관리자 전용 — 특정 참가자를 강제로 제외한다.
|
||||||
|
public async removeParticipant(
|
||||||
|
params: RemoveParticipantParams,
|
||||||
|
): Promise<MatchDocument> {
|
||||||
|
const match = await this.loadRecruitingMatch(
|
||||||
|
params.matchId,
|
||||||
|
params.communityId,
|
||||||
|
);
|
||||||
|
const participantIndex = match.participants.findIndex((participant) =>
|
||||||
|
participant.userId.equals(params.targetUserId),
|
||||||
|
);
|
||||||
|
if (participantIndex === -1) {
|
||||||
|
throw new NotFoundException('Participant not found.');
|
||||||
|
}
|
||||||
|
match.participants.splice(participantIndex, 1);
|
||||||
|
await match.save();
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 관리자 전용 — 참가자의 주/부 포지션(선호 우선순위 1·2)을 교체한다.
|
||||||
|
public async updateParticipantPositions(
|
||||||
|
params: UpdateParticipantPositionsParams,
|
||||||
|
): Promise<MatchDocument> {
|
||||||
|
const match = await this.loadRecruitingMatch(
|
||||||
|
params.matchId,
|
||||||
|
params.communityId,
|
||||||
|
);
|
||||||
|
const participant = match.participants.find((entry) =>
|
||||||
|
entry.userId.equals(params.targetUserId),
|
||||||
|
);
|
||||||
|
if (!participant) {
|
||||||
|
throw new NotFoundException('Participant not found.');
|
||||||
|
}
|
||||||
|
participant.preferredPositions = this.reorderPreferredPositions(
|
||||||
|
params.mainPosition,
|
||||||
|
params.subPosition,
|
||||||
|
participant.preferredPositions,
|
||||||
|
);
|
||||||
|
match.markModified('participants');
|
||||||
|
await match.save();
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async loadRecruitingMatch(
|
||||||
|
matchId: mongoose.Types.ObjectId,
|
||||||
|
communityId: mongoose.Types.ObjectId,
|
||||||
|
): Promise<MatchDocument> {
|
||||||
|
const MatchModel = await this.connectionService.getModel('match');
|
||||||
|
const match = await MatchModel.findById(matchId);
|
||||||
|
if (!match) throw new NotFoundException('Match not found.');
|
||||||
|
if (!match.communityId.equals(communityId)) {
|
||||||
|
throw new BadRequestException('Different community.');
|
||||||
|
}
|
||||||
|
if (match.status !== 'recruiting') {
|
||||||
|
throw new BadRequestException('Match is not recruiting.');
|
||||||
|
}
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 주/부 포지션을 priority 1·2로 올리고 기존 나머지 선호는 뒤로 보존한다.
|
||||||
|
private reorderPreferredPositions(
|
||||||
|
mainPosition: Position,
|
||||||
|
subPosition: Position,
|
||||||
|
current: PositionPreference[],
|
||||||
|
): PositionPreference[] {
|
||||||
|
const ordered: Position[] = [mainPosition];
|
||||||
|
if (subPosition !== mainPosition) ordered.push(subPosition);
|
||||||
|
for (const preference of [...current].sort(
|
||||||
|
(left, right) => left.priority - right.priority,
|
||||||
|
)) {
|
||||||
|
if (!ordered.includes(preference.position)) {
|
||||||
|
ordered.push(preference.position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ordered.map((position, index) => ({
|
||||||
|
position,
|
||||||
|
priority: index + 1,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
private selectParticipantTier(tiers: TierInfo[]): TierInfo | undefined {
|
private selectParticipantTier(tiers: TierInfo[]): TierInfo | undefined {
|
||||||
const tier =
|
const tier =
|
||||||
tiers.find((entry) => entry.queueType === 'RANKED_SOLO_5x5') ?? tiers[0];
|
tiers.find((entry) => entry.queueType === 'RANKED_SOLO_5x5') ?? tiers[0];
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ import {
|
|||||||
} from "../lib/league";
|
} from "../lib/league";
|
||||||
import type {
|
import type {
|
||||||
AuctionTopTierThreshold,
|
AuctionTopTierThreshold,
|
||||||
|
ApiMatch,
|
||||||
ApiMatchParticipant,
|
ApiMatchParticipant,
|
||||||
|
ApiPositionPreference,
|
||||||
ApiTierInfo,
|
ApiTierInfo,
|
||||||
ManualTournamentResultCollectResponse,
|
ManualTournamentResultCollectResponse,
|
||||||
Position,
|
Position,
|
||||||
@@ -90,6 +92,25 @@ function captainSlotKey(slot: CaptainSelectionSlot) {
|
|||||||
return String(slot.teamIndex);
|
return String(slot.teamIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 백엔드 reorderPreferredPositions와 동일 규칙. 낙관적 업데이트에서
|
||||||
|
// 캐시된 preferredPositions를 즉시 갱신하는 데 사용한다.
|
||||||
|
function reorderPreferredPositions(
|
||||||
|
mainPosition: Position,
|
||||||
|
subPosition: Position,
|
||||||
|
current: ApiPositionPreference[],
|
||||||
|
): ApiPositionPreference[] {
|
||||||
|
const ordered: Position[] = [mainPosition];
|
||||||
|
if (subPosition !== mainPosition) ordered.push(subPosition);
|
||||||
|
for (const preference of [...current].sort(
|
||||||
|
(left, right) => left.priority - right.priority,
|
||||||
|
)) {
|
||||||
|
if (!ordered.includes(preference.position)) {
|
||||||
|
ordered.push(preference.position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ordered.map((position, index) => ({ position, priority: index + 1 }));
|
||||||
|
}
|
||||||
|
|
||||||
function parseInitialPointsInput(value: string) {
|
function parseInitialPointsInput(value: string) {
|
||||||
if (!value.trim()) return null;
|
if (!value.trim()) return null;
|
||||||
const points = Number(value);
|
const points = Number(value);
|
||||||
@@ -316,18 +337,81 @@ function tierRank(tier: string) {
|
|||||||
return index === -1 ? PARTICIPANT_TIER_FILTERS.length : index;
|
return index === -1 ? PARTICIPANT_TIER_FILTERS.length : index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ParticipantRowAdmin = {
|
||||||
|
onRemove: (userId: string) => void;
|
||||||
|
onChangePositions: (
|
||||||
|
userId: string,
|
||||||
|
mainPosition: Position,
|
||||||
|
subPosition: Position,
|
||||||
|
) => void;
|
||||||
|
isRemoving: boolean;
|
||||||
|
isUpdating: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
function PositionSelect({
|
||||||
|
value,
|
||||||
|
sub,
|
||||||
|
disabled,
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
value: Position;
|
||||||
|
sub?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
|
onChange: (next: Position) => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<select
|
||||||
|
value={value}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(event) => onChange(event.target.value as Position)}
|
||||||
|
className={`h-7 border bg-base-100 pl-1.5 pr-1 text-[11px] font-medium focus:border-primary/30 focus:outline-none disabled:opacity-50 ${
|
||||||
|
sub
|
||||||
|
? "border-base-content/10 text-base-content/45"
|
||||||
|
: "border-primary/20 text-primary"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{POSITION_ORDER.map((position) => (
|
||||||
|
<option key={position} value={position}>
|
||||||
|
{positionLabel[position]}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function ParticipantRow({
|
function ParticipantRow({
|
||||||
participant,
|
participant,
|
||||||
index,
|
index,
|
||||||
assignedPos,
|
assignedPos,
|
||||||
|
admin,
|
||||||
}: {
|
}: {
|
||||||
participant: ParticipantView;
|
participant: ParticipantView;
|
||||||
index: number;
|
index: number;
|
||||||
assignedPos?: Position;
|
assignedPos?: Position;
|
||||||
|
admin?: ParticipantRowAdmin;
|
||||||
}) {
|
}) {
|
||||||
const { data: ddragon } = useDdragonManifest();
|
const { data: ddragon } = useDdragonManifest();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const historyBackTo = `${location.pathname}${location.search}${location.hash}`;
|
const historyBackTo = `${location.pathname}${location.search}${location.hash}`;
|
||||||
|
const [confirmingRemove, setConfirmingRemove] = useState(false);
|
||||||
|
|
||||||
|
// 주/부 포지션이 겹치면 두 값을 맞바꿔 항상 서로 다르게 유지한다.
|
||||||
|
const handleMainChange = (next: Position) => {
|
||||||
|
if (!admin) return;
|
||||||
|
const sub =
|
||||||
|
next === participant.subPosition
|
||||||
|
? participant.mainPosition
|
||||||
|
: participant.subPosition;
|
||||||
|
admin.onChangePositions(participant.userId, next, sub);
|
||||||
|
};
|
||||||
|
const handleSubChange = (next: Position) => {
|
||||||
|
if (!admin) return;
|
||||||
|
const main =
|
||||||
|
next === participant.mainPosition
|
||||||
|
? participant.subPosition
|
||||||
|
: participant.mainPosition;
|
||||||
|
admin.onChangePositions(participant.userId, main, next);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr className="border-b border-base-content/5 last:border-b-0 hover:bg-base-content/[0.02] transition-colors">
|
<tr className="border-b border-base-content/5 last:border-b-0 hover:bg-base-content/[0.02] transition-colors">
|
||||||
@@ -370,6 +454,68 @@ function ParticipantRow({
|
|||||||
<td className="py-2 px-3">
|
<td className="py-2 px-3">
|
||||||
<PosBadge pos={assignedPos} />
|
<PosBadge pos={assignedPos} />
|
||||||
</td>
|
</td>
|
||||||
|
) : admin ? (
|
||||||
|
<>
|
||||||
|
<td className="py-2 px-3">
|
||||||
|
<PositionSelect
|
||||||
|
value={participant.mainPosition}
|
||||||
|
disabled={admin.isUpdating}
|
||||||
|
onChange={handleMainChange}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
<td className="py-2 px-3">
|
||||||
|
<PositionSelect
|
||||||
|
value={participant.subPosition}
|
||||||
|
sub
|
||||||
|
disabled={admin.isUpdating}
|
||||||
|
onChange={handleSubChange}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
<td className="py-2 px-3 text-right">
|
||||||
|
{confirmingRemove ? (
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={admin.isRemoving}
|
||||||
|
onClick={() => admin.onRemove(participant.userId)}
|
||||||
|
className="text-[10px] font-bold text-red-400 hover:text-red-300 disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{admin.isRemoving ? "제외 중..." : "확인"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setConfirmingRemove(false)}
|
||||||
|
className="text-[10px] text-base-content/35 hover:text-base-content/60"
|
||||||
|
>
|
||||||
|
취소
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
title="참가자 제외"
|
||||||
|
aria-label="참가자 제외"
|
||||||
|
onClick={() => setConfirmingRemove(true)}
|
||||||
|
className="text-base-content/25 hover:text-red-400 transition-colors"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
className="h-3.5 w-3.5"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M6 18L18 6M6 6l12 12"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<td className="py-2 px-3">
|
<td className="py-2 px-3">
|
||||||
@@ -391,6 +537,11 @@ function ParticipantTable({
|
|||||||
canJoin,
|
canJoin,
|
||||||
onJoin,
|
onJoin,
|
||||||
isJoining,
|
isJoining,
|
||||||
|
canManage,
|
||||||
|
onRemoveParticipant,
|
||||||
|
onUpdatePositions,
|
||||||
|
removingUserId,
|
||||||
|
updatingUserId,
|
||||||
}: {
|
}: {
|
||||||
participants: ParticipantView[];
|
participants: ParticipantView[];
|
||||||
maxParticipants: number;
|
maxParticipants: number;
|
||||||
@@ -398,6 +549,15 @@ function ParticipantTable({
|
|||||||
canJoin: boolean;
|
canJoin: boolean;
|
||||||
onJoin: () => void;
|
onJoin: () => void;
|
||||||
isJoining: boolean;
|
isJoining: boolean;
|
||||||
|
canManage: boolean;
|
||||||
|
onRemoveParticipant: (userId: string) => void;
|
||||||
|
onUpdatePositions: (
|
||||||
|
userId: string,
|
||||||
|
mainPosition: Position,
|
||||||
|
subPosition: Position,
|
||||||
|
) => void;
|
||||||
|
removingUserId: string | null;
|
||||||
|
updatingUserId: string | null;
|
||||||
}) {
|
}) {
|
||||||
const [positionFilter, setPositionFilter] =
|
const [positionFilter, setPositionFilter] =
|
||||||
useState<ParticipantPositionFilter>(ALL_PARTICIPANT_FILTER);
|
useState<ParticipantPositionFilter>(ALL_PARTICIPANT_FILTER);
|
||||||
@@ -542,6 +702,9 @@ function ParticipantTable({
|
|||||||
<th className="py-2 px-3">현재 티어</th>
|
<th className="py-2 px-3">현재 티어</th>
|
||||||
<th className="py-2 px-3">주 포지션</th>
|
<th className="py-2 px-3">주 포지션</th>
|
||||||
<th className="py-2 px-3">부 포지션</th>
|
<th className="py-2 px-3">부 포지션</th>
|
||||||
|
{canManage && (
|
||||||
|
<th className="py-2 px-3 w-10 text-right">관리</th>
|
||||||
|
)}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -551,12 +714,22 @@ function ParticipantTable({
|
|||||||
key={participant.id}
|
key={participant.id}
|
||||||
participant={participant}
|
participant={participant}
|
||||||
index={index}
|
index={index}
|
||||||
|
admin={
|
||||||
|
canManage
|
||||||
|
? {
|
||||||
|
onRemove: onRemoveParticipant,
|
||||||
|
onChangePositions: onUpdatePositions,
|
||||||
|
isRemoving: removingUserId === participant.userId,
|
||||||
|
isUpdating: updatingUserId === participant.userId,
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<tr>
|
<tr>
|
||||||
<td
|
<td
|
||||||
colSpan={5}
|
colSpan={canManage ? 6 : 5}
|
||||||
className="px-3 py-8 text-center text-sm text-base-content/35"
|
className="px-3 py-8 text-center text-sm text-base-content/35"
|
||||||
>
|
>
|
||||||
조건에 맞는 참가자가 없습니다.
|
조건에 맞는 참가자가 없습니다.
|
||||||
@@ -1241,6 +1414,89 @@ export default function MatchDetailPage() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const matchQueryKey = ["match", DEFAULT_COMMUNITY_ID, id ?? null];
|
||||||
|
|
||||||
|
const removeParticipantMutation = useMutation({
|
||||||
|
mutationFn: (userId: string) =>
|
||||||
|
apiFetch(
|
||||||
|
`/communities/${DEFAULT_COMMUNITY_ID}/matches/${id}/participants/${userId}`,
|
||||||
|
{ method: "DELETE" },
|
||||||
|
),
|
||||||
|
onMutate: async (userId: string) => {
|
||||||
|
await queryClient.cancelQueries({ queryKey: matchQueryKey });
|
||||||
|
const previous = queryClient.getQueryData<ApiMatch>(matchQueryKey);
|
||||||
|
if (previous) {
|
||||||
|
queryClient.setQueryData<ApiMatch>(matchQueryKey, {
|
||||||
|
...previous,
|
||||||
|
participants: previous.participants.filter(
|
||||||
|
(participant) => participant.userId !== userId,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return { previous };
|
||||||
|
},
|
||||||
|
onError: (_error, _userId, context) => {
|
||||||
|
if (context?.previous) {
|
||||||
|
queryClient.setQueryData(matchQueryKey, context.previous);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSettled: () => {
|
||||||
|
void queryClient.invalidateQueries({ queryKey: matchQueryKey });
|
||||||
|
void queryClient.invalidateQueries({
|
||||||
|
queryKey: ["matches", DEFAULT_COMMUNITY_ID],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateParticipantMutation = useMutation({
|
||||||
|
mutationFn: ({
|
||||||
|
userId,
|
||||||
|
mainPosition,
|
||||||
|
subPosition,
|
||||||
|
}: {
|
||||||
|
userId: string;
|
||||||
|
mainPosition: Position;
|
||||||
|
subPosition: Position;
|
||||||
|
}) =>
|
||||||
|
apiFetch(
|
||||||
|
`/communities/${DEFAULT_COMMUNITY_ID}/matches/${id}/participants/${userId}`,
|
||||||
|
{
|
||||||
|
method: "PATCH",
|
||||||
|
body: JSON.stringify({ mainPosition, subPosition }),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
onMutate: async ({ userId, mainPosition, subPosition }) => {
|
||||||
|
await queryClient.cancelQueries({ queryKey: matchQueryKey });
|
||||||
|
const previous = queryClient.getQueryData<ApiMatch>(matchQueryKey);
|
||||||
|
if (previous) {
|
||||||
|
queryClient.setQueryData<ApiMatch>(matchQueryKey, {
|
||||||
|
...previous,
|
||||||
|
participants: previous.participants.map((participant) =>
|
||||||
|
participant.userId === userId
|
||||||
|
? {
|
||||||
|
...participant,
|
||||||
|
preferredPositions: reorderPreferredPositions(
|
||||||
|
mainPosition,
|
||||||
|
subPosition,
|
||||||
|
participant.preferredPositions,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: participant,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return { previous };
|
||||||
|
},
|
||||||
|
onError: (_error, _variables, context) => {
|
||||||
|
if (context?.previous) {
|
||||||
|
queryClient.setQueryData(matchQueryKey, context.previous);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSettled: () => {
|
||||||
|
void queryClient.invalidateQueries({ queryKey: matchQueryKey });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const startAuctionMutation = useMutation({
|
const startAuctionMutation = useMutation({
|
||||||
mutationFn: () =>
|
mutationFn: () =>
|
||||||
apiFetch(`/communities/${DEFAULT_COMMUNITY_ID}/matches/${id}/auction`, {
|
apiFetch(`/communities/${DEFAULT_COMMUNITY_ID}/matches/${id}/auction`, {
|
||||||
@@ -1511,6 +1767,18 @@ export default function MatchDetailPage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{removeParticipantMutation.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">
|
||||||
|
{removeParticipantMutation.error.message}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{updateParticipantMutation.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">
|
||||||
|
{updateParticipantMutation.error.message}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{pollTournamentResultMutation.error instanceof Error && (
|
{pollTournamentResultMutation.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">
|
<div className="mb-4 border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-500">
|
||||||
{pollTournamentResultMutation.error.message}
|
{pollTournamentResultMutation.error.message}
|
||||||
@@ -1542,6 +1810,27 @@ export default function MatchDetailPage() {
|
|||||||
canJoin={canUseMemberActions}
|
canJoin={canUseMemberActions}
|
||||||
onJoin={() => joinMatchMutation.mutate()}
|
onJoin={() => joinMatchMutation.mutate()}
|
||||||
isJoining={joinMatchMutation.isPending}
|
isJoining={joinMatchMutation.isPending}
|
||||||
|
canManage={canManageAuction}
|
||||||
|
onRemoveParticipant={(userId) =>
|
||||||
|
removeParticipantMutation.mutate(userId)
|
||||||
|
}
|
||||||
|
onUpdatePositions={(userId, mainPosition, subPosition) =>
|
||||||
|
updateParticipantMutation.mutate({
|
||||||
|
userId,
|
||||||
|
mainPosition,
|
||||||
|
subPosition,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
removingUserId={
|
||||||
|
removeParticipantMutation.isPending
|
||||||
|
? (removeParticipantMutation.variables ?? null)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
updatingUserId={
|
||||||
|
updateParticipantMutation.isPending
|
||||||
|
? (updateParticipantMutation.variables?.userId ?? null)
|
||||||
|
: null
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{isCheckingPermissions ? (
|
{isCheckingPermissions ? (
|
||||||
|
|||||||
Reference in new issue
Block a user