mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-29 06:43:17 -05:00
Tournament admin action change team name Closes #1695
This commit is contained in:
@@ -335,6 +335,22 @@ export function checkOut({
|
||||
return query.execute();
|
||||
}
|
||||
|
||||
export function updateTeamName({
|
||||
tournamentTeamId,
|
||||
name,
|
||||
}: {
|
||||
tournamentTeamId: number;
|
||||
name: string;
|
||||
}) {
|
||||
return db
|
||||
.updateTable("TournamentTeam")
|
||||
.set({
|
||||
name,
|
||||
})
|
||||
.where("id", "=", tournamentTeamId)
|
||||
.execute();
|
||||
}
|
||||
|
||||
export function addStaff({
|
||||
tournamentId,
|
||||
userId,
|
||||
|
||||
@@ -101,6 +101,21 @@ export const action: ActionFunction = async ({ request, params }) => {
|
||||
|
||||
break;
|
||||
}
|
||||
case "CHANGE_TEAM_NAME": {
|
||||
validateIsTournamentOrganizer();
|
||||
validate(
|
||||
tournament.ctx.inProgressBrackets.length === 0,
|
||||
"Tournament started",
|
||||
);
|
||||
const team = tournament.teamById(data.teamId);
|
||||
validate(team, "Invalid team id");
|
||||
|
||||
await TournamentRepository.updateTeamName({
|
||||
tournamentTeamId: data.teamId,
|
||||
name: data.teamName,
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "CHECK_IN": {
|
||||
validateIsTournamentOrganizer();
|
||||
const team = tournament.teamById(data.teamId);
|
||||
@@ -331,6 +346,11 @@ const actions = [
|
||||
inputs: ["USER", "TEAM_NAME"] as Input[],
|
||||
when: ["TOURNAMENT_BEFORE_START"],
|
||||
},
|
||||
{
|
||||
type: "CHANGE_TEAM_NAME",
|
||||
inputs: ["REGISTERED_TEAM", "TEAM_NAME"] as Input[],
|
||||
when: ["TOURNAMENT_BEFORE_START"],
|
||||
},
|
||||
{
|
||||
type: "CHANGE_TEAM_OWNER",
|
||||
inputs: ["ROSTER_MEMBER", "REGISTERED_TEAM"] as Input[],
|
||||
@@ -445,7 +465,7 @@ function TeamActions() {
|
||||
) : null}
|
||||
{selectedAction.inputs.includes("TEAM_NAME") ? (
|
||||
<div>
|
||||
<label htmlFor="teamId">Team name</label>
|
||||
<label htmlFor="teamName">Team name</label>
|
||||
<input id="teamName" name="teamName" />
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -10,10 +10,12 @@ import {
|
||||
import { TOURNAMENT } from "./tournament-constants";
|
||||
import { bracketIdx } from "../tournament-bracket/tournament-bracket-schemas.server";
|
||||
|
||||
const teamName = z.string().trim().min(1).max(TOURNAMENT.TEAM_NAME_MAX_LENGTH);
|
||||
|
||||
export const registerSchema = z.union([
|
||||
z.object({
|
||||
_action: _action("UPSERT_TEAM"),
|
||||
teamName: z.string().min(1).max(TOURNAMENT.TEAM_NAME_MAX_LENGTH),
|
||||
teamName,
|
||||
prefersNotToHost: z.preprocess(checkboxValueToBoolean, z.boolean()),
|
||||
noScreen: z.preprocess(checkboxValueToBoolean, z.boolean()),
|
||||
}),
|
||||
@@ -54,6 +56,11 @@ export const adminActionSchema = z.union([
|
||||
teamId: id,
|
||||
memberId: id,
|
||||
}),
|
||||
z.object({
|
||||
_action: _action("CHANGE_TEAM_NAME"),
|
||||
teamId: id,
|
||||
teamName,
|
||||
}),
|
||||
z.object({
|
||||
_action: _action("CHECK_IN"),
|
||||
teamId: id,
|
||||
@@ -81,7 +88,7 @@ export const adminActionSchema = z.union([
|
||||
z.object({
|
||||
_action: _action("ADD_TEAM"),
|
||||
userId: id,
|
||||
teamName: z.string().min(1).max(TOURNAMENT.TEAM_NAME_MAX_LENGTH),
|
||||
teamName,
|
||||
}),
|
||||
z.object({
|
||||
_action: _action("ADD_STAFF"),
|
||||
|
||||
@@ -116,9 +116,22 @@ test.describe("Tournament", () => {
|
||||
await page.getByTestId("admin-tab").click();
|
||||
|
||||
const actionSelect = page.getByLabel("Action");
|
||||
const teamSelect = page.getByLabel("Team");
|
||||
const teamSelect = page.getByLabel("Team", { exact: true });
|
||||
const memberSelect = page.getByLabel("Member");
|
||||
|
||||
// Change team name
|
||||
{
|
||||
await actionSelect.selectOption("CHANGE_TEAM_NAME");
|
||||
await teamSelect.selectOption("1");
|
||||
await page.getByLabel("Team name").fill("NSTC");
|
||||
await submit(page);
|
||||
|
||||
const data = await fetchTournamentLoaderData();
|
||||
const firstTeam = data.tournament.ctx.teams.find((t) => t.id === 1);
|
||||
invariant(firstTeam, "First team not found");
|
||||
expect(firstTeam.name).toBe("NSTC");
|
||||
}
|
||||
|
||||
// Change team owner
|
||||
let data = await fetchTournamentLoaderData();
|
||||
expect(getIsOwnerOfUser({ data, userId: ADMIN_ID, teamId: 1 })).toBe(1);
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
|
||||
"admin.download": "Download participants",
|
||||
"admin.actions.CHANGE_TEAM_OWNER": "Change captain",
|
||||
"admin.actions.CHANGE_TEAM_NAME": "Change team name",
|
||||
"admin.actions.CHECK_IN": "Check in",
|
||||
"admin.actions.CHECK_OUT": "Check out",
|
||||
"admin.actions.ADD_MEMBER": "Add member",
|
||||
|
||||
Reference in New Issue
Block a user